From b6fbd4c26798fb376c8f00c12ac7d4ca3d21a11f Mon Sep 17 00:00:00 2001 From: Seif Lotfy Date: Sat, 9 Jun 2012 00:27:37 +0200 Subject: [PATCH] Telepathy Observer: Fix bloated payloads, reduce redundant if/else --- src/telepathy-observer.vala | 69 ++++++++++--------------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/src/telepathy-observer.vala b/src/telepathy-observer.vala index 016bd77..885a33a 100644 --- a/src/telepathy-observer.vala +++ b/src/telepathy-observer.vala @@ -293,8 +293,6 @@ public class TelepathyObserver : DataProvider if (state == TelepathyGLib.CallState.INITIALISED) { event_template.set_interpretation (ZG_CREATE_EVENT); - if (channel.requested == false) - event_template.set_manifestation (ZG_WORLD_ACTIVITY); Timer t = new Timer (); t.stop (); call_timers.insert (channel.get_object_path (), (owned) t); @@ -306,13 +304,6 @@ public class TelepathyObserver : DataProvider else if ((state == TelepathyGLib.CallState.ACTIVE || state == TelepathyGLib.CallState.ENDED) && call_timers.contains (channel.get_object_path ())) { - event_template.set_interpretation (ZG_CREATE_EVENT); - /* - * Set manifestation based on if the call was initiated or received - */ - if (channel.requested == false) - event_template.set_manifestation (ZG_WORLD_ACTIVITY); - if (state == TelepathyGLib.CallState.ACTIVE) { event_template.set_interpretation (ZG_ACCESS_EVENT); @@ -322,10 +313,22 @@ public class TelepathyObserver : DataProvider else if (state == TelepathyGLib.CallState.ENDED) { event_template.set_interpretation (ZG_LEAVE_EVENT); - if (reason.reason == TelepathyGLib.CallStateChangeReason.REJECTED) - event_template.set_interpretation (ZG_DENY_EVENT); - else if (reason.reason == TelepathyGLib.CallStateChangeReason.NO_ANSWER) - event_template.set_interpretation (ZG_EXPIRE_EVENT); + + /* Call was created by user but was rejected or not answered */ + if (reason.reason == TelepathyGLib.CallStateChangeReason.REJECTED + || reason.reason == TelepathyGLib.CallStateChangeReason.NO_ANSWER) + { + if (channel.requested) + event_template.set_manifestation (ZG_WORLD_ACTIVITY); + else + event_template.set_interpretation (ZG_USER_ACTIVITY); + + if (reason.reason == TelepathyGLib.CallStateChangeReason.NO_ANSWER) + event_template.set_interpretation (ZG_EXPIRE_EVENT); + else + event_template.set_interpretation (ZG_DENY_EVENT); + } + var duration = call_timers.lookup (channel.get_object_path ()).elapsed (); call_timers.lookup (channel.get_object_path ()).stop; call_timers.remove (channel.get_object_path ()); @@ -344,33 +347,6 @@ public class TelepathyObserver : DataProvider details_obj.set_int_member ("state", state); details_obj.set_int_member ("reason", reason.reason); details_obj.set_boolean_member ("requested", channel.requested); - - var obj_path = account.get_object_path (); - obj_path = this.tp_account_path.printf("%s", - obj_path [TelepathyGLib.ACCOUNT_OBJECT_PATH_BASE.length: - obj_path.length]); - - var targets = ""; - var i = 0; - foreach (var target in channel.get_members ().get_keys()) - { - if (i == 0) - targets = "%s".printf (this.tp_identifier.printf (target.get_identifier ())); - else - targets = "%s; %s".printf (targets, - this.tp_identifier.printf (target.get_identifier ())); - i++; - } - if (channel.requested == true) - { - details_obj.set_string_member ("host", obj_path); - details_obj.set_string_member ("recipient", targets); - } - else - { - details_obj.set_string_member ("host", this.tp_identifier.printf(targets)); - details_obj.set_string_member ("recipient", obj_path); - } details_obj.set_double_member ("duration", duration); size_t length; object.set_object_member (call_json_domain, details_obj); @@ -460,22 +436,9 @@ public class TelepathyObserver : DataProvider details_obj.set_int_member ("state", state); details_obj.set_int_member ("reason", reason); details_obj.set_boolean_member ("requested", channel.requested); - if (channel.requested == true) - { - details_obj.set_string_member ("sender", obj_path); - details_obj.set_string_member ("recipient", this.tp_identifier.printf(target.get_identifier ())); - } - else - { - details_obj.set_string_member ("sender", this.tp_identifier.printf(target.get_identifier ())); - details_obj.set_string_member ("recipient", obj_path); - } - details_obj.set_string_member ("mimetype", info.get_content_type ()); - details_obj.set_int_member ("date", channel.get_date ().to_unix ()); details_obj.set_string_member ("description", channel.get_description ()); details_obj.set_double_member ("size", (int64)channel.get_size ()); details_obj.set_string_member ("service", channel.get_service_name ()); - details_obj.set_string_member ("uri", channel.file.get_uri()); size_t length; object.set_object_member (ft_json_domain, details_obj); string payload_string = gen.to_data(out length); -- 1.7.9.5