diff --git a/.gitignore b/.gitignore index 8e4e030..8aaa95a 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,4 @@ Makefile.in /src/namespace-info.c /src/matrix-event-room-topic.c /src/matrix-event-typing.c +/src/matrix-event-room-aliases.c diff --git a/src/Makefile.am b/src/Makefile.am index e0f93ab..96f1f24 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,6 +31,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-room-message.vala \ matrix-event-room-topic.vala \ matrix-event-typing.vala \ + matrix-event-room-aliases.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-room-aliases.vala b/src/matrix-event-room-aliases.vala new file mode 100644 index 0000000..e82fa0c --- /dev/null +++ b/src/matrix-event-room-aliases.vala @@ -0,0 +1,70 @@ +/* + * This file is part of matrix-glib-sdk + * + * matrix-glib-sdk is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * matrix-glib-sdk is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with matrix-glib-sdk. If not, see + * . + */ + +/** + * Class to hold a m.room.aliases event. + * + * This event is sent by a homeserver directly to inform of changes to + * the list of aliases it knows about for that room. + * + * The state_key for this event is set to the homeserver which owns + * the room alias. + * + * The entire set of known aliases for the room is the union of all + * the m.room.aliases events, one for each homeserver. Clients should + * check the validity of any room alias given in this list before + * presenting it to the user as trusted fact. The lists given by this + * event should be considered simply as advice on which aliases might + * exist, for which the client can perform the lookup to confirm + * whether it receives the correct room ID. + */ +public class Matrix.Event.RoomAliases : Matrix.Event.State { + private List? _aliases = null; + + /** + * A list of room aliases. + */ + public List? aliases { + get { + return _aliases; + } + + set { + _aliases = value.copy(); + } + + 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; + + if ((node = content_root.get_member("aliases")) != null) { + _aliases = null; + + node.get_array().foreach_element((ary, idx, member_node) => { + _aliases.prepend(member_node.get_string()); + }); + } + } +} diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index b017ff7..1ba7157 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -167,6 +167,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.typing", MATRIX_EVENT_TYPE_TYPING, NULL); + matrix_event_register_type("m.room.aliases", + MATRIX_EVENT_TYPE_ROOM_ALIASES, + NULL); } void