Add handler for m.room.name

This commit is contained in:
Gergely Polonkai 2016-03-07 22:55:58 +00:00
parent 82536c650d
commit 5c121cef0e
4 changed files with 70 additions and 0 deletions

1
.gitignore vendored
View File

@ -65,3 +65,4 @@ Makefile.in
/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 /src/matrix-event-room-join-rules.c
/src/matrix-event-room-name.c

View File

@ -35,6 +35,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \
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 \ matrix-event-room-join-rules.vala \
matrix-event-room-name.vala \
$(NULL) $(NULL)
AM_CPPFLAGS += \ AM_CPPFLAGS += \

View File

@ -0,0 +1,65 @@
/*
* 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.name event.
*
* A room has an opaque room ID which is not human-friendly to read. A
* room alias is human-friendly, but not all rooms have room
* aliases. The room name is a human-friendly string designed to be
* displayed to the end-user. The room name is not unique, as multiple
* rooms can have the same room name set. The room name can also be
* set when creating a room using createRoom with the name key.
*/
public class Matrix.Event.RoomName : Matrix.Event.State {
public string? name { 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("name")) != null) {
_name = node.get_string();
} else {
warning("content.name is missing from a m.room.name 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 (_name == null) {
throw new Matrix.Error.INCOMPLETE(
"Won't send a m.room.name event without a name");
}
content_root.set_string_member("name", _name);
base.to_json(json_data);
}
}

View File

@ -179,6 +179,9 @@ matrix_event_types_ctor(void)
matrix_event_register_type("m.room.join_rules", matrix_event_register_type("m.room.join_rules",
MATRIX_EVENT_TYPE_ROOM_JOIN_RULES, MATRIX_EVENT_TYPE_ROOM_JOIN_RULES,
NULL); NULL);
matrix_event_register_type("m.room.name",
MATRIX_EVENT_TYPE_ROOM_NAME,
NULL);
} }
void void