Compare commits

...

2 Commits

Author SHA1 Message Date
dd6fd39ae3 First attempt to implement JsonSerializable 2018-05-10 14:17:09 +02:00
42d9ab7716 tmp 2018-05-10 14:17:09 +02:00
2 changed files with 75 additions and 3 deletions

View File

@ -19,7 +19,9 @@
/** /**
* Base class for Matrix events. * Base class for Matrix events.
*/ */
public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable { public abstract class Matrix.Event.Base : GLib.Object,
GLib.Initable,
Json.Serializable {
private Error? _construct_error = null; private Error? _construct_error = null;
private bool _inited = false; private bool _inited = false;
private Json.Node? _json; private Json.Node? _json;
@ -77,6 +79,8 @@ public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable {
} }
} }
// Implementation of GLib.Initable
public bool public bool
init(GLib.Cancellable? cancellable = null) init(GLib.Cancellable? cancellable = null)
throws Error, Matrix.Error throws Error, Matrix.Error
@ -95,6 +99,39 @@ public abstract class Matrix.Event.Base : GLib.Object, GLib.Initable {
return true; return true;
} }
// Implementation of Json.Serializable
public unowned ParamSpec
find_property(string name)
{
return get_class().find_property(name);
}
public Json.Node
serialize_property(string property_name,
Value value,
ParamSpec pspec)
{
return default_serialize_property(property_name, value, pspec);
}
public bool
deserialize_property(string property_name,
out Value value,
ParamSpec pspec,
Json.Node property_node)
{
value = Value(pspec.value_type);
return default_deserialize_property(property_name,
value,
pspec,
property_node);
}
// Own methods
private void private void
initialize_from_json(Json.Node json_data) initialize_from_json(Json.Node json_data)
throws Matrix.Error throws Matrix.Error

View File

@ -25,8 +25,12 @@
public class Matrix.Room : GLib.Object { public class Matrix.Room : GLib.Object {
/** /**
* The ID of the room this object belongs to. * The ID of the room this object belongs to.
*
* If this property is null, then this object is acting as a
* temporary stash for another room object, which is used when
* calculating state events to be sent by apply_changes().
*/ */
public string room_id { get; construct; } public string? room_id { get; construct; }
/** /**
* All the known room aliases. * All the known room aliases.
@ -155,13 +159,22 @@ public class Matrix.Room : GLib.Object {
private HashTable<string, MemberData?> _members = private HashTable<string, MemberData?> _members =
new HashTable<string, MemberData?>(str_hash, str_equal); new HashTable<string, MemberData?>(str_hash, str_equal);
private Room _stash = null;
/** /**
* Create a new Room object. * Create a new Room object.
*
* @param room_id the ID of the room this object belongs to. For
* null values, see remark at the room_id property.
*/ */
public public
Room(string room_id) Room(string? room_id)
{ {
Object(room_id : room_id); Object(room_id : room_id);
if (room_id != null) {
_stash = new Room(null);
}
} }
/** /**
@ -344,4 +357,26 @@ public class Matrix.Room : GLib.Object {
{ {
return _event_levels[event_type]; return _event_levels[event_type];
} }
/**
* Generate a set of events that can change the room state on the
* home server similar to what this object shows.
*/
public void
apply_changes()
{
Matrix.Event.Base[] ret = {};
foreach (var to_add in _aliases) {
if (!(to_add in _stash._aliases)) {
// add alias
}
}
foreach (var to_remove in _stash._aliases) {
if (!(to_remove in _aliases)) {
// remove alias
}
}
}
} }