diff --git a/.gitignore b/.gitignore index 93526c6..cfd952c 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ Makefile.in /src/matrix-event-room-create.c /src/matrix-event-room-power-levels.c /src/matrix-event-room-avatar.c +/src/matrix-event-room-message-feedback.c diff --git a/src/Makefile.am b/src/Makefile.am index 6d79257..c88c232 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -41,6 +41,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-event-room-create.vala \ matrix-event-room-power-levels.vala \ matrix-event-room-avatar.vala \ + matrix-event-room-message-feedback.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-room-message-feedback.vala b/src/matrix-event-room-message-feedback.vala new file mode 100644 index 0000000..6c38713 --- /dev/null +++ b/src/matrix-event-room-message-feedback.vala @@ -0,0 +1,84 @@ +/* + * 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.message.feedback event. + * + * Usage of this event is discouraged in favour of the receipts + * module. Most clients will not recognise this event. + * + * Feedback events are events sent to acknowledge a message in some + * way. There are two supported acknowledgements: `delivered` (sent + * when the event has been received) and `read` (sent when the event + * has been observed by the end-user). The `target_event_id` should + * reference the `m.room.message` event being acknowledged. + */ +public class Matrix.Event.RoomMessageFeedback : Matrix.Event.Room { + /** + * The type of the feedback. As the use of this event type is + * discouraged, Matrix GLib SDK doesn’t implement this as an + * actual enum. + */ + public string? feedback_type { get; set; default = null; } + + /** + * The event that this feedback is related to. + */ + public string? target_event_id { 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("type")) != null) { + _feedback_type = node.get_string(); + } else { + warning("content.type is missing from a m.room.message.feedback event"); + } + + if ((node = content_root.get_member("target_event_id")) != null) { + _target_event_id = node.get_string(); + } else { + warning("content.target_event_id is missing from a m.room.message.feedback event"); + } + + base.from_json(json_data); + } + + protected override void + to_json(Json.Node json_data) + throws Matrix.Error + { + if ((_feedback_type == null) || (_target_event_id == null)) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.room.message.feedback without all fields set"); + } + + var content_root = json_data.get_object() + .get_member("content").get_object(); + + content_root.set_string_member("type", _feedback_type); + content_root.set_string_member("target_event_id", _target_event_id); + + base.to_json(json_data); + } +} diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index c3c5213..5bb259e 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -197,6 +197,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.room.avatar", MATRIX_EVENT_TYPE_ROOM_AVATAR, NULL); + matrix_event_register_type("m.room.message.feedback", + MATRIX_EVENT_TYPE_ROOM_MESSAGE_FEEDBACK, + NULL); } void