From b9ded01e984afa59e58cc5f8cb1e4be7ca253c67 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Wed, 9 Mar 2016 11:33:44 +0100 Subject: [PATCH] Add to_json() to Matrix.Event.CallInvite --- src/matrix-event-call-invite.vala | 49 ++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/matrix-event-call-invite.vala b/src/matrix-event-call-invite.vala index 3d7fa3b..7e1dfc1 100644 --- a/src/matrix-event-call-invite.vala +++ b/src/matrix-event-call-invite.vala @@ -56,7 +56,8 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room { .get_member("content").get_object(); Json.Node? node; - if ((node = content_root.get_member("call_id")) != null) { _call_id = node.get_string(); + if ((node = content_root.get_member("call_id")) != null) { + _call_id = node.get_string(); } else { warning("content.call_id is missing from a m.call.invite event"); } @@ -100,4 +101,50 @@ public class Matrix.Event.CallInvite : Matrix.Event.Room { base.from_json(json_data); } + + protected override void + to_json(Json.Node json_data) + throws Matrix.Error + { + if (_offer_type == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.invite without offer.type"); + } + + if (_offer_sdp == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.invite without offer.sdp"); + } + + if (_version == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.invite without version"); + } + + if (_lifetime == null) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate a m.call.invite without lifetime"); + } + + var content_root = json_data.get_object() + .get_member("content").get_object(); + + content_root.set_string_member("call_id", _call_id); + content_root.set_int_member("version", _version); + content_root.set_int_member("lifetime", _lifetime); + + var offer_root = new Json.Object(); + var offer_node = new Json.Node(Json.NodeType.OBJECT); + offer_node.set_object(offer_root); + + offer_root.set_string_member( + "type", + _g_enum_value_to_nick(typeof(CallOfferType), + _offer_type)); + offer_root.set_string_member("sdp", _offer_sdp); + + content_root.set_member("offer", offer_node); + + base.to_json(json_data); + } }