diff --git a/.gitignore b/.gitignore index daf4231..ff4b028 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ Makefile.in /src/matrix-event-receipt.c /src/matrix-event-room-history-visibility.c /src/matrix-event-room-join-rules.c +/src/matrix-event-room-name.c diff --git a/src/Makefile.am b/src/Makefile.am index 91ba5cf..8f4d0f9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,6 +35,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-receipt.vala \ matrix-event-room-history-visibility.vala \ matrix-event-room-join-rules.vala \ + matrix-event-room-name.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-room-name.vala b/src/matrix-event-room-name.vala new file mode 100644 index 0000000..d31d676 --- /dev/null +++ b/src/matrix-event-room-name.vala @@ -0,0 +1,65 @@ +/* + * 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.name event. + * + * A room has an opaque room ID which is not human-friendly to read. A + * room alias is human-friendly, but not all rooms have room + * aliases. The room name is a human-friendly string designed to be + * displayed to the end-user. The room name is not unique, as multiple + * rooms can have the same room name set. The room name can also be + * set when creating a room using createRoom with the name key. + */ +public class Matrix.Event.RoomName : Matrix.Event.State { + public string? name { 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; + + if ((node = content_root.get_member("name")) != null) { + _name = node.get_string(); + } else { + warning("content.name is missing from a m.room.name event"); + } + + base.from_json(json_data); + } + + protected override void + to_json(Json.Node json_data) + throws Matrix.Error + { + var content_root = json_data.get_object() + .get_member("content").get_object(); + + if (_name == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't send a m.room.name event without a name"); + } + + content_root.set_string_member("name", _name); + + base.to_json(json_data); + } +} diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index 7e7b78a..e82c174 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -179,6 +179,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.room.join_rules", MATRIX_EVENT_TYPE_ROOM_JOIN_RULES, NULL); + matrix_event_register_type("m.room.name", + MATRIX_EVENT_TYPE_ROOM_NAME, + NULL); } void