diff --git a/.gitignore b/.gitignore index dba860c..098704f 100644 --- a/.gitignore +++ b/.gitignore @@ -70,3 +70,4 @@ Makefile.in /src/matrix-presence-event.c /src/matrix-room-event.c /src/matrix-room-member-event.c +/src/matrix-state-event.c diff --git a/src/Makefile.am b/src/Makefile.am index acd9cfd..846987e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,6 +24,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ matrix-compacts.vala \ matrix-event.vala \ matrix-presence-event.vala \ + matrix-state-event.vala \ matrix-room-event.vala \ matrix-room-member-event.vala \ $(NULL) diff --git a/src/matrix-http-api.vala b/src/matrix-http-api.vala index ad80a22..1a8f269 100644 --- a/src/matrix-http-api.vala +++ b/src/matrix-http-api.vala @@ -797,9 +797,7 @@ public class Matrix.HTTPAPI : GLib.Object, Matrix.API { builder.begin_array(); initial_state.foreach( (entry) => { - try { - builder.add_value(entry.get_json_node()); - } catch (Matrix.Error e) {} + builder.add_value(entry.json); }); builder.end_array(); } diff --git a/src/matrix-state-event.vala b/src/matrix-state-event.vala new file mode 100644 index 0000000..70132ee --- /dev/null +++ b/src/matrix-state-event.vala @@ -0,0 +1,58 @@ +/* + * 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 + * . + */ +namespace Matrix { + public class StateEvent : Matrix.Event { + public string? state_key { get; set; default = null; } + public Json.Node? content { get; set; default = null; } + + protected override void + from_json(Json.Node json_data) + throws Matrix.Error + { + var root = json_data.get_object(); + Json.Node? node; + + if ((node = root.get_member("state_key")) != null) { + state_key = node.get_string(); + } + + if ((node = root.get_member("content")) != null) { + content = node; + } + + base.from_json(json_data); + } + + 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); + } + + if (content != null) { + root.set_member("content", content); + } + + base.to_json(json_node); + } + } +}