From be2220b0794decaba1d6e44ffa5291dac22823b4 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 9 Mar 2016 15:13:48 +0100 Subject: [PATCH] Patch up Matrix.Event.RoomCanonicalAlias * Require an empty state key --- src/matrix-event-room-canonical-alias.vala | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/matrix-event-room-canonical-alias.vala b/src/matrix-event-room-canonical-alias.vala index b48c3ac..9066a12 100644 --- a/src/matrix-event-room-canonical-alias.vala +++ b/src/matrix-event-room-canonical-alias.vala @@ -24,15 +24,24 @@ * as suggestion to users which alias to use to advertise the room. */ public class Matrix.Event.RoomCanonicalAlias : Matrix.Event.State { + /** + * The canonical alias. + */ public string? canonical_alias { get; set; default = null; } protected override void from_json(Json.Node json_data) throws Matrix.Error { - var content_root = json_data.get_object() - .get_member("content").get_object(); - Json.Node? node; + var root = json_data.get_object(); + var content_root = root.get_member("content").get_object(); + Json.Node? node = null; + + if (Config.DEBUG && ((node = root.get_member("state_key")) != null)) { + if (node.get_string() != "") { + warning("state_key of a m.room.canonical_alias event is non-empty"); + } + } if ((node = content_root.get_member("alias")) != null) { _canonical_alias = node.get_string(); @@ -48,6 +57,11 @@ public class Matrix.Event.RoomCanonicalAlias : Matrix.Event.State { var content_root = json_data.get_object() .get_member("content").get_object(); + if (_state_key != "") { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.room.canonical_alias event with a non-empty state_key"); + } + if (_canonical_alias != null) { content_root.set_string_member("alias", _canonical_alias); }