diff --git a/.gitignore b/.gitignore index 1c01bbc..da85e34 100644 --- a/.gitignore +++ b/.gitignore @@ -59,3 +59,4 @@ Makefile.in /src/matrix-event-state-base.c /src/matrix-event-room-message.c /src/namespace-info.c +/src/matrix-event-room-topic.c diff --git a/src/Makefile.am b/src/Makefile.am index 42289be..3a65cea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-presence.vala \ matrix-event-room-member.vala \ matrix-event-room-message.vala \ + matrix-event-room-topic.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-room-topic.vala b/src/matrix-event-room-topic.vala new file mode 100644 index 0000000..7e8f76f --- /dev/null +++ b/src/matrix-event-room-topic.vala @@ -0,0 +1,63 @@ +/* + * 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 + * . + */ + +/** + * Event type to hold the m.room.topic event. + * + * A topic is a short message detailing what is currently being + * discussed in the room. It can also be used as a way to display + * extra information about the room, which may not be suitable for the + * room name. + */ +public class Matrix.Event.RoomTopic : Matrix.Event.State { + /** + * The topic text. + */ + public string? topic { get; set; default = null; } + + protected override void + from_json(Json.Node json_data) + throws Matrix.Error + { + var root = json_data.get_object(); + var content_root = root.get_member("content").get_object(); + Json.Node? node; + + if ((node = content_root.get_member("topic")) != null) { + _topic = node.get_string(); + } else if (Config.DEBUG) { + warning("content.topic is missing from an m.room.topic event"); + } + + base.from_json(json_data); + } + + protected override void + to_json(Json.Node json_data) + throws Matrix.Error + { + var root = json_data.get_object(); + var content_root = root.get_member("content").get_object(); + + if (_topic != null) { + content_root.set_string_member("topic", _topic); + } + + base.to_json(json_data); + } +} diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index 4dfd4c0..038521a 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -161,6 +161,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.room.message", MATRIX_EVENT_TYPE_ROOM_MESSAGE, NULL); + matrix_event_register_type("m.room.topic", + MATRIX_EVENT_TYPE_ROOM_TOPIC, + NULL); } void