diff --git a/.gitignore b/.gitignore index 098704f..b38a40d 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,4 @@ Makefile.in /src/matrix-room-event.c /src/matrix-room-member-event.c /src/matrix-state-event.c +/src/matrix-room-message-event.c diff --git a/src/Makefile.am b/src/Makefile.am index 846987e..b560066 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,6 +27,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-state-event.vala \ matrix-room-event.vala \ matrix-room-member-event.vala \ + matrix-room-message-event.vala \ $(NULL) AM_CPPFLAGS += \ diff --git a/src/matrix-event-types.c b/src/matrix-event-types.c index 03a0c1a..1d96646 100644 --- a/src/matrix-event-types.c +++ b/src/matrix-event-types.c @@ -158,6 +158,9 @@ matrix_event_types_ctor(void) matrix_event_register_type("m.presence", MATRIX_TYPE_PRESENCE_EVENT, NULL); + matrix_event_register_type("m.room.message", + MATRIX_TYPE_ROOM_MESSAGE_EVENT, + NULL); } void diff --git a/src/matrix-room-message-event.vala b/src/matrix-room-message-event.vala new file mode 100644 index 0000000..1a54272 --- /dev/null +++ b/src/matrix-room-message-event.vala @@ -0,0 +1,53 @@ +/* + * 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 + * . + */ + +public class Matrix.RoomMessageEvent : Matrix.RoomEvent { + public string msg_type { get; set; } + public string body { get; set; } + + protected override void + from_json(Json.Node json_data) + throws Matrix.Error + { + var root = json_data.get_object(); + + if (root.get_member("content") == null) { + throw new Matrix.Error.INCOMPLETE( + "Message event without a content!"); + } + + var content_root = root.get_member("content").get_object(); + Json.Node? node; + + if ((node = content_root.get_member("msgtype")) == null) { + throw new Matrix.Error.INCOMPLETE( + "Message event without a message type!"); + } + + _msg_type = node.get_string(); + + if ((node = content_root.get_member("body")) == null) { + throw new Matrix.Error.INCOMPLETE( + "Message event without a body!"); + } + + _body = node.get_string(); + + base.from_json(json_data); + } +}