Add event handler for m.room.guest_access

This commit is contained in:
Gergely Polonkai 2016-03-08 18:17:57 +00:00
parent 3f7bf44989
commit 66ae5cff58
5 changed files with 92 additions and 0 deletions

1
.gitignore vendored
View File

@ -72,3 +72,4 @@ Makefile.in
/src/matrix-event-room-power-levels.c
/src/matrix-event-room-avatar.c
/src/matrix-event-room-message-feedback.c
/src/matrix-event-room-guest-access.c

View File

@ -42,6 +42,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
matrix-event-room-power-levels.vala \
matrix-event-room-avatar.vala \
matrix-event-room-message-feedback.vala \
matrix-event-room-guest-access.vala \
$(NULL)
AM_CPPFLAGS += \

View File

@ -0,0 +1,81 @@
/*
* 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 to hold a m.room.guest_access event
*
* This event controls whether guest users are allowed to join
* rooms. If this event is absent, servers should act as if it is
* present and has the guest_access value `forbidden`.
*/
/**
* Class to hold a m.room.guest_access event
*/
public class Matrix.Event.RoomGuestAccess : Matrix.Event.State {
/**
* Whether guests can join the room.
*/
public GuestAccess? guest_access { 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("guest_access")) != null) {
GuestAccess? rules = (GuestAccess?)_g_enum_nick_to_value(
typeof(GuestAccess), node.get_string());
if (rules != null) {
_guest_access = rules;
} else {
_guest_access = GuestAccess.UNKNOWN;
warning("Unknown value '%s' in a m.room.guest_access event",
node.get_string());
}
} else {
warning("content.guest_access is missing from a m.room.guest_access event");
}
base.from_json(json_data);
}
protected override void
to_json(Json.Node json_data)
throws Matrix.Error
{
if ((_guest_access == null) || (_guest_access == GuestAccess.UNKNOWN)) {
throw new Matrix.Error.INCOMPLETE(
"Won't generate a m.room.guest_access event with an unset content.guest_access key");
}
var content_root = json_data.get_object()
.get_member("content").get_object();
content_root.set_string_member(
"guest_access",
_g_enum_value_to_nick(typeof(GuestAccess), _guest_access));
base.to_json(json_data);
}
}

View File

@ -200,6 +200,9 @@ matrix_event_types_ctor(void)
matrix_event_register_type("m.room.message.feedback",
MATRIX_EVENT_TYPE_ROOM_MESSAGE_FEEDBACK,
NULL);
matrix_event_register_type("m.room.guest_access",
MATRIX_EVENT_TYPE_ROOM_GUEST_ACCESS,
NULL);
}
void

View File

@ -270,6 +270,12 @@ namespace Matrix {
WORLD_READABLE;
}
public enum GuestAccess {
UNKNOWN, /// represents a value unknown to this library
CAN_JOIN, /// guest users are allowed to access the room
FORBIDDEN; /// guest users are not allowed to access the room
}
public struct ImageInfo {
int? size;
int? height;