Add event handler for m.room.redaction
This commit is contained in:
parent
66ae5cff58
commit
e958e0ecc7
1
.gitignore
vendored
1
.gitignore
vendored
@ -73,3 +73,4 @@ Makefile.in
|
||||
/src/matrix-event-room-avatar.c
|
||||
/src/matrix-event-room-message-feedback.c
|
||||
/src/matrix-event-room-guest-access.c
|
||||
/src/matrix-event-room-redaction.c
|
||||
|
@ -43,6 +43,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
|
||||
matrix-event-room-avatar.vala \
|
||||
matrix-event-room-message-feedback.vala \
|
||||
matrix-event-room-guest-access.vala \
|
||||
matrix-event-room-redaction.vala \
|
||||
$(NULL)
|
||||
|
||||
AM_CPPFLAGS += \
|
||||
|
85
src/matrix-event-room-redaction.vala
Normal file
85
src/matrix-event-room-redaction.vala
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.redaction event
|
||||
*
|
||||
* Events can be redacted by either room or server admins. Redacting
|
||||
* an event means that all keys not required by the protocol are
|
||||
* stripped off, allowing admins to remove offensive or illegal
|
||||
* content that may have been attached to any event. This cannot be
|
||||
* undone, allowing server owners to physically delete the offending
|
||||
* data. There is also a concept of a moderator hiding a message
|
||||
* event, which can be undone, but cannot be applied to state
|
||||
* events. The event that has been redacted is specified in the
|
||||
* redacts event level key.
|
||||
*/
|
||||
public class Matrix.Event.RoomRedaction : Matrix.Event.Room {
|
||||
/**
|
||||
* The reason for the redaction, if any.
|
||||
*/
|
||||
public string? reason { get; set; default = null; }
|
||||
|
||||
/**
|
||||
* The event ID that was redacted.
|
||||
*/
|
||||
public string? redacted_event_id { 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("reason")) != null) {
|
||||
_reason = node.get_string();
|
||||
}
|
||||
|
||||
if ((node = root.get_member("redacts")) != null) {
|
||||
_redacted_event_id = node.get_string();
|
||||
} else {
|
||||
warning("redacts is missing from a m.room.redaction event");
|
||||
}
|
||||
|
||||
base.from_json(json_data);
|
||||
}
|
||||
|
||||
protected override void
|
||||
to_json(Json.Node json_data)
|
||||
throws Matrix.Error
|
||||
{
|
||||
if (_redacted_event_id == null) {
|
||||
throw new Matrix.Error.INCOMPLETE(
|
||||
"Won't generate a m.room.redaction event without the redacts field");
|
||||
}
|
||||
|
||||
var root = json_data.get_object();
|
||||
|
||||
root.set_string_member("redacts", _redacted_event_id);
|
||||
|
||||
if (_reason != null) {
|
||||
var content_root = root.get_member("content").get_object();
|
||||
|
||||
content_root.set_string_member("reason", _reason);
|
||||
}
|
||||
|
||||
base.to_json(json_data);
|
||||
}
|
||||
}
|
@ -203,6 +203,9 @@ matrix_event_types_ctor(void)
|
||||
matrix_event_register_type("m.room.guest_access",
|
||||
MATRIX_EVENT_TYPE_ROOM_GUEST_ACCESS,
|
||||
NULL);
|
||||
matrix_event_register_type("m.room.redaction",
|
||||
MATRIX_EVENT_TYPE_ROOM_REDACTION,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
Reference in New Issue
Block a user