Add handler for m.room.topic events
This commit is contained in:
parent
70dfaff080
commit
d4ce1cb06c
1
.gitignore
vendored
1
.gitignore
vendored
@ -59,3 +59,4 @@ Makefile.in
|
|||||||
/src/matrix-event-state-base.c
|
/src/matrix-event-state-base.c
|
||||||
/src/matrix-event-room-message.c
|
/src/matrix-event-room-message.c
|
||||||
/src/namespace-info.c
|
/src/namespace-info.c
|
||||||
|
/src/matrix-event-room-topic.c
|
||||||
|
@ -29,6 +29,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
|||||||
matrix-event-presence.vala \
|
matrix-event-presence.vala \
|
||||||
matrix-event-room-member.vala \
|
matrix-event-room-member.vala \
|
||||||
matrix-event-room-message.vala \
|
matrix-event-room-message.vala \
|
||||||
|
matrix-event-room-topic.vala \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
|
63
src/matrix-event-room-topic.vala
Normal file
63
src/matrix-event-room-topic.vala
Normal file
@ -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
|
||||||
|
* <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
}
|
||||||
|
}
|
@ -161,6 +161,9 @@ matrix_event_types_ctor(void)
|
|||||||
matrix_event_register_type("m.room.message",
|
matrix_event_register_type("m.room.message",
|
||||||
MATRIX_EVENT_TYPE_ROOM_MESSAGE,
|
MATRIX_EVENT_TYPE_ROOM_MESSAGE,
|
||||||
NULL);
|
NULL);
|
||||||
|
matrix_event_register_type("m.room.topic",
|
||||||
|
MATRIX_EVENT_TYPE_ROOM_TOPIC,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user