Add MatrixRoomMemberEvent
This commit is contained in:
parent
80d4791658
commit
3e6a021a0f
1
.gitignore
vendored
1
.gitignore
vendored
@ -68,3 +68,4 @@ Makefile.in
|
|||||||
/src/matrix-compacts.c
|
/src/matrix-compacts.c
|
||||||
/src/matrix-event.c
|
/src/matrix-event.c
|
||||||
/src/matrix-room-event.c
|
/src/matrix-room-event.c
|
||||||
|
/src/matrix-room-member-event.c
|
||||||
|
@ -18,8 +18,13 @@
|
|||||||
|
|
||||||
<chapter>
|
<chapter>
|
||||||
<title>Matrix Client</title>
|
<title>Matrix Client</title>
|
||||||
<xi:include href="xml/matrix-types.xml"/>
|
<section>
|
||||||
<xi:include href="xml/matrix-event.xml"/>
|
<title>Types</title>
|
||||||
|
<xi:include href="xml/matrix-types.xml"/>
|
||||||
|
<xi:include href="xml/matrix-event.xml"/>
|
||||||
|
<xi:include href="xml/matrix-room-member-event.xml"/>
|
||||||
|
</section>
|
||||||
|
|
||||||
<xi:include href="xml/matrix-client.xml"/>
|
<xi:include href="xml/matrix-client.xml"/>
|
||||||
<xi:include href="xml/matrix-http-client.xml"/>
|
<xi:include href="xml/matrix-http-client.xml"/>
|
||||||
<xi:include href="xml/matrix-api.xml"/>
|
<xi:include href="xml/matrix-api.xml"/>
|
||||||
|
@ -1,3 +1,29 @@
|
|||||||
|
<SECTION>
|
||||||
|
<FILE>matrix-room-member-event</FILE>
|
||||||
|
<TITLE>MatrixRoomMemberEvent</TITLE>
|
||||||
|
matrix_room_member_event_set_membership
|
||||||
|
matrix_room_member_event_get_membership
|
||||||
|
matrix_room_member_event_set_state_key
|
||||||
|
matrix_room_member_event_get_state_key
|
||||||
|
matrix_room_member_event_set_avatar_url
|
||||||
|
matrix_room_member_event_get_avatar_url
|
||||||
|
matrix_room_member_event_set_display_name
|
||||||
|
matrix_room_member_event_get_display_name
|
||||||
|
|
||||||
|
<SUBSECTION Standard>
|
||||||
|
MATRIX_IS_ROOM_MEMBER_EVENT
|
||||||
|
MATRIX_IS_ROOM_MEMBER_EVENT_CLASS
|
||||||
|
MATRIX_ROOM_MEMBER_EVENT
|
||||||
|
MATRIX_ROOM_MEMBER_EVENT_CLASS
|
||||||
|
MATRIX_ROOM_MEMBER_EVENT_GET_CLASS
|
||||||
|
MATRIX_TYPE_ROOM_MEMBER_EVENT
|
||||||
|
MatrixRoomMemberEvent
|
||||||
|
MatrixRoomMemberEventPrivate
|
||||||
|
MatrixRoomMemberEventClass
|
||||||
|
matrix_room_member_event_get_type
|
||||||
|
matrix_room_member_event_construct
|
||||||
|
</SECTION>
|
||||||
|
|
||||||
<SECTION>
|
<SECTION>
|
||||||
<FILE>matrix-event</FILE>
|
<FILE>matrix-event</FILE>
|
||||||
<TITLE>MatrixEvent</TITLE>
|
<TITLE>MatrixEvent</TITLE>
|
||||||
|
@ -24,6 +24,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
|||||||
matrix-compacts.vala \
|
matrix-compacts.vala \
|
||||||
matrix-event.vala \
|
matrix-event.vala \
|
||||||
matrix-room-event.vala \
|
matrix-room-event.vala \
|
||||||
|
matrix-room-member-event.vala \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
|
@ -152,6 +152,9 @@ G_DEFINE_CONSTRUCTOR(matrix_event_types_ctor);
|
|||||||
static void
|
static void
|
||||||
matrix_event_types_ctor(void)
|
matrix_event_types_ctor(void)
|
||||||
{
|
{
|
||||||
|
matrix_event_register_type("m.room.member",
|
||||||
|
MATRIX_TYPE_ROOM_MEMBER_EVENT,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
119
src/matrix-room-member-event.vala
Normal file
119
src/matrix-room-member-event.vala
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for representing a room membership events
|
||||||
|
*
|
||||||
|
* The room membership event class.
|
||||||
|
*/
|
||||||
|
public class Matrix.RoomMemberEvent : Matrix.RoomEvent {
|
||||||
|
public string? state_key { get; set; }
|
||||||
|
public RoomMembership membership {
|
||||||
|
get; set;
|
||||||
|
default = RoomMembership.UNKNOWN;
|
||||||
|
}
|
||||||
|
public string? avatar_url { get; set; }
|
||||||
|
public string? display_name { get; set; }
|
||||||
|
|
||||||
|
protected override void
|
||||||
|
from_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
Json.Object root = json_data.get_object();
|
||||||
|
Json.Object content_root = root.get_member("content").get_object();
|
||||||
|
Json.Node? node;
|
||||||
|
|
||||||
|
if ((node = root.get_member("state_key")) != null) {
|
||||||
|
_state_key = node.get_string();
|
||||||
|
} else {
|
||||||
|
GLib.warning("state_key is missing from the m.room.member event");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node = root.get_member("room_id")) != null) {
|
||||||
|
_room_id = node.get_string();
|
||||||
|
} else {
|
||||||
|
GLib.warning("room_id is missing from the m.room.member event");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node = content_root.get_member("membership")) != null) {
|
||||||
|
Matrix.RoomMembership? mship = (Matrix.RoomMembership?)_g_enum_nick_to_value(
|
||||||
|
typeof(Matrix.RoomMembership),
|
||||||
|
node.get_string());
|
||||||
|
|
||||||
|
if (mship != null) {
|
||||||
|
_membership = mship;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
GLib.warning("membership key is missing from the m.room.member event");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node = content_root.get_member("avatar_url")) != null) {
|
||||||
|
_avatar_url = node.get_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((node = content_root.get_member("displayname")) != null) {
|
||||||
|
_display_name = node.get_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain up
|
||||||
|
base.from_json(json_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void
|
||||||
|
to_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
Json.Object root, content_root;
|
||||||
|
string? mship;
|
||||||
|
|
||||||
|
if (membership == RoomMembership.UNKNOWN) {
|
||||||
|
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||||
|
"Unknown membership value cannot be added to a room member event");
|
||||||
|
}
|
||||||
|
|
||||||
|
root = json_data.get_object();
|
||||||
|
|
||||||
|
content_root = _json_object_node_ensure_field(json_data,
|
||||||
|
"content",
|
||||||
|
Json.NodeType.OBJECT)
|
||||||
|
.get_object();
|
||||||
|
|
||||||
|
root.set_string_member("state_key", state_key);
|
||||||
|
|
||||||
|
if (room_id != null) {
|
||||||
|
root.set_string_member("room_id", room_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
mship = _g_enum_value_to_nick(typeof(Matrix.RoomMembership),
|
||||||
|
membership);
|
||||||
|
|
||||||
|
if (mship != null) {
|
||||||
|
content_root.set_string_member("membership", mship);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (avatar_url != null) {
|
||||||
|
content_root.set_string_member("avatar_url", avatar_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (display_name != null) {
|
||||||
|
content_root.set_string_member("displayname", display_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
base.to_json(json_data);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user