Bug 28312 - Make TpContact emit a presence-changed signal
Summary: Make TpContact emit a presence-changed signal
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: tp-glib (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Morten Mjelva
QA Contact: Telepathy bugs list
URL: http://cgit.freedesktop.org/~sjokkis/...
Whiteboard: review+
Keywords: patch
Depends on:
Blocks:
 
Reported: 2010-05-29 06:02 UTC by Morten Mjelva
Modified: 2010-06-14 04:02 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Adds TpContact::presence-changed signal (3.54 KB, patch)
2010-06-10 10:50 UTC, Morten Mjelva
Details | Splinter Review
Make TpContact emit a presence-changed signal (3.37 KB, patch)
2010-06-11 16:03 UTC, Morten Mjelva
Details | Splinter Review
Make TpContact emit a presence-changed signal (3.29 KB, patch)
2010-06-14 03:54 UTC, Morten Mjelva
Details | Splinter Review

Description Morten Mjelva 2010-05-29 06:02:28 UTC
Currently, property notify signals are emitted for presence-type, -message and -status whenever one of these properties change. It would be better to check if the new value is different from the old, and only emit the signal in this case.

Additionally, it would be beneficial to have a single signal to listen to, along  the lines of the PresencesChanged signal on Connection.Interface.SimplePresence.
Comment 1 Danielle Madeley 2010-05-29 06:13:01 UTC
Patch from sjokkis (not reviewed): http://cgit.freedesktop.org/~sjokkis/telepathy-glib/log/?h=presence-changed
Comment 2 Danielle Madeley 2010-05-29 06:21:42 UTC
Quick review:

Use tp_value_array_unpack() to unpack the value array. Don't look up offsets into the array (I know that's what the old code does, but it's nasty).

+ if (contact->priv->presence_type != type) {
+ contact->priv->presence_type = type;
+ g_object_notify ((GObject *) contact, "presence-type");
+ }

Not in Telepathy style. Telepathy style is documented in http://telepathy.freedesktop.org/wiki/Style -- also applies to the other if blocks.

+ gchar *status = g_value_dup_string (presence->values+1);
+ if (tp_strdiff(contact->priv->presence_status, status)) {
+ g_free (contact->priv->presence_status);
+ contact->priv->presence_status = status;
+ g_object_notify ((GObject *) contact, "presence-status");
+ }
+ g_free(status);

Memory management is incorrect here. If you use tp_value_array_unpack() you'll be given a const char * that you don't need to free, so you can just do:

+ g_free (contact->priv->presence_status);
+ contact->priv->presence_status = g_strdup (status);
Comment 3 Morten Mjelva 2010-06-10 10:50:04 UTC
Created attachment 36205 [details] [review]
Adds TpContact::presence-changed signal

Changed the criticisms above. Should be fine now. Let me know if it isn't, and I'll get on it ASAP.
Comment 4 Simon McVittie 2010-06-11 06:16:08 UTC
Review of attachment 36205 [details] [review]:

This mostly looks good; I'd like a few minor changes.

> From: mortenmj <morten.mjelva@gmail.com>

You might want to fix your git user.name setting and commit --amend this patch, before it becomes part of our revision history :-)

::: telepathy-glib/contact.c
@@ +873,3 @@
+   * TpContact::presence-changed:
+   * @contact: A #TpContact
+   * @presence: The contact's presence type 

"The new value of #TpContact:presence-type"

That way, the API user can follow the hyperlink to find out exactly how it works.

@@ +874,3 @@
+   * @contact: A #TpContact
+   * @presence: The contact's presence type 
+   * @status: Protocol-defined description of the presence type

The new value of #TpContact:presence-status

@@ +875,3 @@
+   * @presence: The contact's presence type 
+   * @status: Protocol-defined description of the presence type
+   * @status_message: User-defined status message

The new value of #TpContact:presence-message

@@ +877,3 @@
+   * @status_message: User-defined status message
+   *
+   * Emitted when PresenceChanged is received for this contact.

I'd prefer "Emitted when this contact's presence changes"; then it's meaningful even if you haven't read the Telepathy D-Bus API recently.

@@ +1662,2 @@
+// Presence properties might have changed. 
+// Set new values, and emit the TpContact::presence-changed signal.

/* */, please; we don't use C++ comments in Telepathy C code.

I don't think this comment actually adds much value, though, so I'd be inclined to just delete it.

@@ +1677,2 @@
+  tp_value_array_unpack (presence, presence->n_values, &type, &status,
+      &message);

Use a literal "3" for the second argument; it's used as a sanity check (to be able to warn/abort the number of arguments that follow it doesn't match presence->n_values), and using presence->n_values defeats that.
Comment 5 Morten Mjelva 2010-06-11 16:03:25 UTC
Created attachment 36227 [details] [review]
Make TpContact emit a presence-changed signal
Comment 6 Simon McVittie 2010-06-14 03:25:07 UTC
Review of attachment 36227 [details] [review]:

::: telepathy-glib/contact.c
@@ +1678,1 @@
   g_object_notify ((GObject *) contact, "presence-type");

I have one remaining concern here, which is that this changes the behaviour of notify::presence-* - previously, all three properties were updated before emitting any of the notification signals (which seems most useful to me), but now, they're updated one at a time.

If you have time to correct this before I do a telepathy-glib 0.19.7 release today, great; if not, I'll probably apply your patch, make the change myself, and get someone else to review it.

Thanks for your patience!
Comment 7 Morten Mjelva 2010-06-14 03:54:39 UTC
Created attachment 36261 [details] [review]
Make TpContact emit a presence-changed signal
Comment 8 Simon McVittie 2010-06-14 04:01:45 UTC
Reviewed and merged, thanks. Fixed in git, will be in 0.11.7 later today.
Comment 9 Simon McVittie 2010-06-14 04:02:00 UTC
Reviewed and merged, thanks. Fixed in git, will be in 0.11.7 later today.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.