Create the MatrixRoomMessageEvent type
Currently it only handles msgtype and body; more complex types like documents or images are to be implemented soon.
This commit is contained in:
parent
2e8343f9bc
commit
444a93bddf
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||
|
@ -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 += \
|
||||
|
@ -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
|
||||
|
53
src/matrix-room-message-event.vala
Normal file
53
src/matrix-room-message-event.vala
Normal file
@ -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
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user