From 3f7057c652406841da0787820d6e133d74854419 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Fri, 18 Mar 2016 16:58:23 +0100 Subject: [PATCH] Move Matrix.Event.RoomPowerLevels internals from HashTable to Gee.HashMap --- src/matrix-event-room-power-levels.vala | 53 ++++++++++++++++--------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/matrix-event-room-power-levels.vala b/src/matrix-event-room-power-levels.vala index 19ff0e4..d07b6b6 100644 --- a/src/matrix-event-room-power-levels.vala +++ b/src/matrix-event-room-power-levels.vala @@ -70,8 +70,29 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State { */ public int invite { get; set; default = 0; } - private HashTable _event_levels = null; - private HashTable _user_levels = null; + /** + * A hash map to store the required level to send specific events. + */ + public Gee.HashMap event_levels { + get { + return _event_levels; + } + } + + /** + * A hash map to store current level for individual users. + */ + public Gee.HashMap user_levels { + get { + return _user_levels; + } + } + + private Gee.HashMap _event_levels = + new Gee.HashMap(); + + private Gee.HashMap _user_levels = + new Gee.HashMap(); protected override void from_json(Json.Node json_data) @@ -126,22 +147,18 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State { } if ((node = content_root.get_member("events")) != null) { - node.get_object().foreach_member((obj, event_name, event_node) => { - if (_event_levels == null) { - _event_levels = new HashTable(str_hash, str_equal); - } + _event_levels.clear(); - _event_levels.replace(event_name, (int)event_node.get_int()); + node.get_object().foreach_member((obj, event_name, event_node) => { + _event_levels[event_name] = (int)event_node.get_int(); }); } if ((node = content_root.get_member("users")) != null) { - node.get_object().foreach_member((obj, user_id, user_node) => { - if (_user_levels == null) { - _user_levels = new HashTable(str_hash, str_equal); - } + _user_levels.clear(); - _user_levels.replace(user_id, (int)user_node.get_int()); + node.get_object().foreach_member((obj, user_id, user_node) => { + _user_levels[user_id] = (int)user_node.get_int(); }); } @@ -180,9 +197,9 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State { var user_node = new Json.Node(Json.NodeType.OBJECT); user_node.set_object(user_obj); - _user_levels.foreach((user_id, power_level) => { - user_obj.set_int_member(user_id, power_level); - }); + foreach (var entry in _user_levels.entries) { + user_obj.set_int_member(entry.key, entry.value); + } content_root.set_member("users", user_node); @@ -190,9 +207,9 @@ public class Matrix.Event.RoomPowerLevels : Matrix.Event.State { var events_node = new Json.Node(Json.NodeType.OBJECT); events_node.set_object(events_obj); - _event_levels.foreach((events_id, power_level) => { - events_obj.set_int_member(events_id, power_level); - }); + foreach (var entry in _event_levels.entries) { + events_obj.set_int_member(entry.key, entry.value); + } content_root.set_member("users", events_node);