Add event handler for m.room.join_rules
This commit is contained in:
parent
c581f9e2fb
commit
82536c650d
1
.gitignore
vendored
1
.gitignore
vendored
@ -64,3 +64,4 @@ Makefile.in
|
|||||||
/src/matrix-event-room-aliases.c
|
/src/matrix-event-room-aliases.c
|
||||||
/src/matrix-event-receipt.c
|
/src/matrix-event-receipt.c
|
||||||
/src/matrix-event-room-history-visibility.c
|
/src/matrix-event-room-history-visibility.c
|
||||||
|
/src/matrix-event-room-join-rules.c
|
||||||
|
@ -34,6 +34,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
|||||||
matrix-event-room-aliases.vala \
|
matrix-event-room-aliases.vala \
|
||||||
matrix-event-receipt.vala \
|
matrix-event-receipt.vala \
|
||||||
matrix-event-room-history-visibility.vala \
|
matrix-event-room-history-visibility.vala \
|
||||||
|
matrix-event-room-join-rules.vala \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
|
@ -200,6 +200,17 @@ namespace Matrix {
|
|||||||
PRIVATE; /// hide the room from the public room list
|
PRIVATE; /// hide the room from the public room list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Room join rules.
|
||||||
|
*/
|
||||||
|
public enum JoinRules {
|
||||||
|
UNKNOWN, /// A value unknown to this library
|
||||||
|
PUBLIC, /// Anyone can join
|
||||||
|
INVITE, /// Users may join upon invite
|
||||||
|
PRIVATE, /// Reserved word, not usable yet
|
||||||
|
KNOCK; /// Reserved word, not usable yet
|
||||||
|
}
|
||||||
|
|
||||||
public enum SearchOrder {
|
public enum SearchOrder {
|
||||||
RECENT,
|
RECENT,
|
||||||
RANK
|
RANK
|
||||||
|
83
src/matrix-event-room-join-rules.vala
Normal file
83
src/matrix-event-room-join-rules.vala
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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.join_rules event.
|
||||||
|
*
|
||||||
|
* A room may be public meaning anyone can join the room without any
|
||||||
|
* prior action. Alternatively, it can be invite meaning that a user
|
||||||
|
* who wishes to join the room must first receive an invite to the
|
||||||
|
* room from someone already inside of the room. Currently, knock and
|
||||||
|
* private are reserved keywords which are not implemented.
|
||||||
|
*/
|
||||||
|
public class Matrix.Event.RoomJoinRules : Matrix.Event.State {
|
||||||
|
public Matrix.JoinRules? join_rules { 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("join_rule")) != null) {
|
||||||
|
Matrix.JoinRules? rules = (Matrix.JoinRules)_g_enum_nick_to_value(
|
||||||
|
typeof(Matrix.JoinRules), node.get_string());
|
||||||
|
|
||||||
|
if (rules != null) {
|
||||||
|
_join_rules = rules;
|
||||||
|
} else {
|
||||||
|
_join_rules = Matrix.JoinRules.UNKNOWN;
|
||||||
|
|
||||||
|
warning("Unknown value %s in a m.room.join_rules event",
|
||||||
|
node.get_string());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_join_rules = Matrix.JoinRules.UNKNOWN;
|
||||||
|
|
||||||
|
warning("content.join_rules is missing from a m.room.join_rules event.");
|
||||||
|
}
|
||||||
|
|
||||||
|
base.from_json(json_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void
|
||||||
|
to_json(Json.Node json_data)
|
||||||
|
throws Matrix.Error
|
||||||
|
{
|
||||||
|
var content_root = json_data.get_object().
|
||||||
|
get_member("content").get_object();
|
||||||
|
|
||||||
|
if (_join_rules == null) {
|
||||||
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
|
"Won't send a m.room.join_rules event without content.join_rule");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_join_rules == Matrix.JoinRules.UNKNOWN) {
|
||||||
|
throw new Matrix.Error.INCOMPLETE(
|
||||||
|
"Won't send a m.room.join_rules event with an unknown rule");
|
||||||
|
}
|
||||||
|
|
||||||
|
content_root.set_string_member(
|
||||||
|
"join_rule",
|
||||||
|
_g_enum_value_to_nick(typeof(Matrix.JoinRules), _join_rules));
|
||||||
|
|
||||||
|
base.to_json(json_data);
|
||||||
|
}
|
||||||
|
}
|
@ -176,6 +176,9 @@ matrix_event_types_ctor(void)
|
|||||||
matrix_event_register_type("m.room.history_visibility",
|
matrix_event_register_type("m.room.history_visibility",
|
||||||
MATRIX_EVENT_TYPE_ROOM_HISTORY_VISIBILITY,
|
MATRIX_EVENT_TYPE_ROOM_HISTORY_VISIBILITY,
|
||||||
NULL);
|
NULL);
|
||||||
|
matrix_event_register_type("m.room.join_rules",
|
||||||
|
MATRIX_EVENT_TYPE_ROOM_JOIN_RULES,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user