2016-02-26 16:29:18 +00:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
public abstract class Matrix.Event.State : Matrix.Event.Base {
|
2016-03-09 07:18:21 +00:00
|
|
|
protected string? _state_key;
|
|
|
|
|
|
|
|
public string? state_key {
|
|
|
|
get {
|
|
|
|
return _state_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
set {
|
|
|
|
_state_key = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
default = null;
|
|
|
|
}
|
2016-03-07 08:44:06 +00:00
|
|
|
public Json.Node? prev_content { get; set; default = null; }
|
2016-02-26 16:29:18 +00:00
|
|
|
|
|
|
|
protected override void
|
|
|
|
from_json(Json.Node json_data)
|
|
|
|
throws Matrix.Error
|
|
|
|
{
|
|
|
|
var root = json_data.get_object();
|
2016-03-07 08:44:06 +00:00
|
|
|
Json.Node? node;
|
2016-02-26 16:29:18 +00:00
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
if ((node = root.get_member("state_key")) != null) {
|
|
|
|
state_key = node.get_string();
|
2016-02-26 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
if ((node = root.get_member("prev_content")) != null) {
|
|
|
|
_prev_content = node;
|
2016-02-26 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
base.from_json(json_data);
|
|
|
|
}
|
2016-02-26 16:29:18 +00:00
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
protected override void
|
|
|
|
to_json(Json.Node json_node)
|
|
|
|
throws Matrix.Error
|
|
|
|
{
|
|
|
|
var root = json_node.get_object();
|
|
|
|
|
|
|
|
if (state_key != null) {
|
|
|
|
root.set_string_member("state_key", state_key);
|
2016-02-26 16:29:18 +00:00
|
|
|
}
|
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
if (prev_content != null) {
|
|
|
|
root.set_member("prev_content", prev_content);
|
|
|
|
}
|
2016-02-26 16:29:18 +00:00
|
|
|
|
2016-03-07 08:44:06 +00:00
|
|
|
base.to_json(json_node);
|
2016-02-26 16:29:18 +00:00
|
|
|
}
|
2016-03-07 14:02:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a stripped state event.
|
|
|
|
*
|
|
|
|
* @return `null` if the event is not allowed to be stripped, or
|
|
|
|
* the full JSON node otherwise
|
|
|
|
*/
|
|
|
|
public Json.Node?
|
|
|
|
get_stripped_node()
|
|
|
|
{
|
|
|
|
if ((_event_type != "m.room.join_rules")
|
|
|
|
&& (_event_type != "m.room.canonical_alias")
|
|
|
|
&& (_event_type != "m.room.avatar")
|
|
|
|
&& (_event_type != "m.room.name")) {
|
|
|
|
warning("Trying to strip down event that is not allowed to be stripped.");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return json;
|
|
|
|
}
|
2016-02-26 16:29:18 +00:00
|
|
|
}
|