Add event handler for m.room.history_visibility
This commit is contained in:
parent
13abc13adc
commit
c581f9e2fb
1
.gitignore
vendored
1
.gitignore
vendored
@ -63,3 +63,4 @@ Makefile.in
|
|||||||
/src/matrix-event-typing.c
|
/src/matrix-event-typing.c
|
||||||
/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
|
||||||
|
@ -33,6 +33,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
|||||||
matrix-event-typing.vala \
|
matrix-event-typing.vala \
|
||||||
matrix-event-room-aliases.vala \
|
matrix-event-room-aliases.vala \
|
||||||
matrix-event-receipt.vala \
|
matrix-event-receipt.vala \
|
||||||
|
matrix-event-room-history-visibility.vala \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
AM_CPPFLAGS += \
|
AM_CPPFLAGS += \
|
||||||
|
@ -216,6 +216,14 @@ namespace Matrix {
|
|||||||
SENDER
|
SENDER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum HistoryVisibility {
|
||||||
|
UNKNOWN,
|
||||||
|
INVITED,
|
||||||
|
JOINED,
|
||||||
|
SHARE,
|
||||||
|
WORLD_READABLE;
|
||||||
|
}
|
||||||
|
|
||||||
private int?
|
private int?
|
||||||
_g_enum_nick_to_value(Type enum_type, string nick)
|
_g_enum_nick_to_value(Type enum_type, string nick)
|
||||||
{
|
{
|
||||||
|
77
src/matrix-event-room-history-visibility.vala
Normal file
77
src/matrix-event-room-history-visibility.vala
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.history_visibility event.
|
||||||
|
*
|
||||||
|
* This event controls whether a user can see the events that happened
|
||||||
|
* in a room from before they joined.
|
||||||
|
*/
|
||||||
|
public class Matrix.Event.RoomHistoryVisibility : Matrix.Event.State {
|
||||||
|
/**
|
||||||
|
* Who can see the room history.
|
||||||
|
*/
|
||||||
|
public Matrix.HistoryVisibility visibility {
|
||||||
|
get; set;
|
||||||
|
|
||||||
|
default = Matrix.HistoryVisibility.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
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("history_visibility")) != null) {
|
||||||
|
Matrix.HistoryVisibility? vis = (Matrix.HistoryVisibility?)_g_enum_nick_to_value(
|
||||||
|
typeof(Matrix.HistoryVisibility),
|
||||||
|
node.get_string());
|
||||||
|
|
||||||
|
if (vis != null) {
|
||||||
|
_visibility = vis;
|
||||||
|
} else {
|
||||||
|
_visibility = Matrix.HistoryVisibility.UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (visibility == Matrix.HistoryVisibility.UNKNOWN) {
|
||||||
|
throw new Matrix.Error.UNKNOWN_VALUE(
|
||||||
|
"Won't send m.room.history_visibility event with unknown visibility value");
|
||||||
|
}
|
||||||
|
|
||||||
|
content_root.set_string_member("history_visibility",
|
||||||
|
_g_enum_value_to_nick(
|
||||||
|
typeof(Matrix.HistoryVisibility),
|
||||||
|
visibility));
|
||||||
|
|
||||||
|
base.to_json(json_data);
|
||||||
|
}
|
||||||
|
}
|
@ -173,6 +173,9 @@ matrix_event_types_ctor(void)
|
|||||||
matrix_event_register_type("m.receipt",
|
matrix_event_register_type("m.receipt",
|
||||||
MATRIX_EVENT_TYPE_RECEIPT,
|
MATRIX_EVENT_TYPE_RECEIPT,
|
||||||
NULL);
|
NULL);
|
||||||
|
matrix_event_register_type("m.room.history_visibility",
|
||||||
|
MATRIX_EVENT_TYPE_ROOM_HISTORY_VISIBILITY,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user