Bug 55668 - use the self-contact to handle Aliasing and Avatars
Summary: use the self-contact to handle Aliasing and Avatars
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: mission-control (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Simon McVittie
QA Contact: Telepathy bugs list
URL: http://cgit.freedesktop.org/~smcv/tel...
Whiteboard:
Keywords: patch
Depends on: 55391
Blocks: 54879
  Show dependency treegraph
 
Reported: 2012-10-05 15:24 UTC by Simon McVittie
Modified: 2012-10-11 09:29 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
McdAccount: store the self-contact (2.76 KB, patch)
2012-10-05 15:25 UTC, Simon McVittie
Details | Splinter Review
McdAccount: take responsibility for setting the nickname (14.89 KB, patch)
2012-10-05 15:25 UTC, Simon McVittie
Details | Splinter Review
Don't set the nickname to the normalized name on connect (1.79 KB, patch)
2012-10-05 15:26 UTC, Simon McVittie
Details | Splinter Review
enable_fakecm_account: copy parameters and alter the copy (1.52 KB, patch)
2012-10-05 15:27 UTC, Simon McVittie
Details | Splinter Review
nickname test: verify that a trivial nickname is not set on connect (6.39 KB, patch)
2012-10-05 15:27 UTC, Simon McVittie
Details | Splinter Review
McdAccount: cope with self-contact changes; follow the self-contact (3.42 KB, patch)
2012-10-05 15:29 UTC, Simon McVittie
Details | Splinter Review
Add a regression test for an IRC-like protocol (7.14 KB, patch)
2012-10-05 15:29 UTC, Simon McVittie
Details | Splinter Review
Knock out most of the IRC test until fd.o #55666 is fixed (1.01 KB, patch)
2012-10-05 15:29 UTC, Simon McVittie
Details | Splinter Review
Emulate the Aliasing interface a little more realistically (7.30 KB, patch)
2012-10-05 16:58 UTC, Simon McVittie
Details | Splinter Review
Track Avatars using McdAccount, and use the self-contact for it (19.72 KB, patch)
2012-10-05 17:02 UTC, Simon McVittie
Details | Splinter Review
Downgrade failure to set alias/avatar from WARNING to DEBUG (1.19 KB, patch)
2012-10-09 14:32 UTC, Simon McVittie
Details | Splinter Review
Downgrade failure to prepare self-contact from WARNING to DEBUG (759 bytes, patch)
2012-10-09 14:32 UTC, Simon McVittie
Details | Splinter Review
nickname test: test what happens when we set an empty nickname (5.52 KB, patch)
2012-10-09 14:34 UTC, Simon McVittie
Details | Splinter Review
Implement Set("Nickname", "") by using the normalized name instead (4.26 KB, patch)
2012-10-09 14:34 UTC, Simon McVittie
Details | Splinter Review
Ignore changes to the avatar of former self-contacts (1.21 KB, patch)
2012-10-09 14:35 UTC, Simon McVittie
Details | Splinter Review
mcd_account_process_initial_avatar_token: don't take self_contact argument (2.04 KB, patch)
2012-10-09 14:35 UTC, Simon McVittie
Details | Splinter Review
mcd_account_self_contact_changed_cb: ignore no-op changes (1.04 KB, patch)
2012-10-09 14:35 UTC, Simon McVittie
Details | Splinter Review

Description Simon McVittie 2012-10-05 15:24:31 UTC
+++ This bug was initially created as a clone of Bug #55391 +++

On that bug, I wrote:

> Other things to do include:
> 
> McdConnection has quite a lot of tp_connection_get_self_handle(). The
> simple fix would be to copy that function's implementation every time
> we call it - but it would be better if we used a TpContact for the
> self-contact, attached it to the McdAccount instead of the McdConnection,
> and used high-level APIs instead. This should be done separately for
> aliasing, presence, avatars, and any other offending interfaces.

Let's do Aliasing first. It turns out to be a small net code-deletion:

 src/mcd-account.c         |  183 ++++++++++++++++++++++++++++++++++++++-------
 src/mcd-connection-priv.h |    3 -
 src/mcd-connection.c      |  147 ------------------------------------
 3 files changed, 157 insertions(+), 176 deletions(-)

(when tests are ignored)
Comment 1 Simon McVittie 2012-10-05 15:25:35 UTC
Created attachment 68126 [details] [review]
McdAccount: store the self-contact
Comment 2 Simon McVittie 2012-10-05 15:25:57 UTC
Created attachment 68127 [details] [review]
McdAccount: take responsibility for setting the nickname

As well as being implemented in a more streamlined way (using the
self-contact instead of calling D-Bus methods directly), this reduces
the circular dependencies between McdConnection and McdAccount.
Comment 3 Simon McVittie 2012-10-05 15:26:49 UTC
Created attachment 68128 [details] [review]
Don't set the nickname to the normalized name on connect

We still allow the nickname to be set to the normalized name by
user action later, because in that case, the intention is unambiguous:
the user really does want their nickname to take that value.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39381

---

The observant will notice that this change is much, much smaller than the one on Bug #39381 :-)
Comment 4 Simon McVittie 2012-10-05 15:27:13 UTC
Created attachment 68129 [details] [review]
enable_fakecm_account: copy parameters and alter the  copy

Mutable defaults for arguments are dangerous. If we call
enable_fakecm_account twice with default arguments, when we alter
expect_before_connect/expect_after_connect, we are actually altering
the default! Python doesn't construct a new empty list for us every
time. The C equivalent would be a static GPtrArray * or something.
Comment 5 Simon McVittie 2012-10-05 15:27:48 UTC
Created attachment 68130 [details] [review]
nickname test: verify that a trivial nickname is not set  on connect

---

This is Bug #39381 really.
Comment 6 Simon McVittie 2012-10-05 15:29:00 UTC
Created attachment 68131 [details] [review]
McdAccount: cope with self-contact changes; follow the  self-contact

---

This doesn't actually gain us any correctness (but is harmless) until we fix Bug #55666 in telepathy-glib. Software is hard.
Comment 7 Simon McVittie 2012-10-05 15:29:22 UTC
Created attachment 68132 [details] [review]
Add a regression test for an IRC-like protocol

IRC has plenty of oddities, but the one we're interested in here
is that your nickname and your unique identifier are inextricably linked.
Comment 8 Simon McVittie 2012-10-05 15:29:43 UTC
Created attachment 68133 [details] [review]
Knock out most of the IRC test until fd.o #55666 is  fixed
Comment 9 Simon McVittie 2012-10-05 16:58:39 UTC
Created attachment 68136 [details] [review]
Emulate the Aliasing interface a little more  realistically
Comment 10 Simon McVittie 2012-10-05 17:02:20 UTC
Created attachment 68137 [details] [review]
Track Avatars using McdAccount, and use the self-contact  for it

---

This removes what appears to be a completely redundant call to GetKnownAvatarTokens() whenever we receive AvatarUpdated. That's pointless - we just got the avatar token! - so we don't need to do it. Unfortunately, one of the tests asserted that we did.

The previous commit is needed because without it, the TpContact for the self-contact in account-manager/auto-connect.py will fail to prepare in a reasonable time (TpContact calls GetAliases() but the test never replies to it), and we'll never actually upload the new avatar. The test would work if it took longer than 25 seconds to give up, but that would be ridiculous.
Comment 11 Xavier Claessens 2012-10-08 08:10:27 UTC
Did not read all the patches in details, just noticed that you upgrade the self contact manually. I don't know how far we got with introducing factory into MC, but we could define those contact features on the factory so they become part of TpConnection's CORE feature.

otoh, we need to be careful here. With tp-glib master no other contacts than connection's self will get prepared (TpChannel's contacts are prepared only if TP_CHANNEL_FEATURE_CONTACTS). But in next, TpChannel's target/initiator are part of CORE and group contacts are prepared as part of GROUP (which is not CORE anymore). I've also seen that MC prepares GROUP to leave channels so that will be an issue if we put contact features on the factory.
Comment 12 Simon McVittie 2012-10-08 09:48:36 UTC
(In reply to comment #11)
> Did not read all the patches in details, just noticed that you upgrade the
> self contact manually.

Yeah, that was deliberate, to not upgrade any other contacts that might exist. I think it's right for the self-contact to be a bit of a special case.

Unless we add a separate set of self-handle-features to the factory, I think what I'm doing here is more appropriate than using the factory.

> But in next, TpChannel's target/initiator
> are part of CORE and group contacts are prepared as part of GROUP (which is
> not CORE anymore).

Right, that's a waste of time for MC.
Comment 13 Xavier Claessens 2012-10-09 08:41:50 UTC
Comment on attachment 68127 [details] [review]
McdAccount: take responsibility for setting the nickname

Review of attachment 68127 [details] [review]:
-----------------------------------------------------------------

::: src/mcd-account.c
@@ +1318,5 @@
> +    gpointer user_data,
> +    GObject *weak_object)
> +{
> +  if (error)
> +    WARNING ("%s", error->message);

Do we want a warning here? We usually uses DEBUG() for failing dbus calls

@@ +4546,5 @@
> +      if (self_contact == self->priv->self_contact)
> +        {
> +          tp_g_signal_connect_object (self_contact, "notify::alias",
> +              G_CALLBACK (mcd_account_self_contact_notify_alias_cb),
> +              self, G_CONNECT_SWAPPED);

swapped is nice to avoid the GParamSpec useless arg, but in this case you use both self and self_contact, so swapped is not needed.

@@ +4560,5 @@
> +      g_ptr_array_unref (contacts);
> +    }
> +  else
> +    {
> +      WARNING ("failed to prepare self-contact: %s", error->message);

Same here, should we downgrade to DEBUG?
Comment 14 Xavier Claessens 2012-10-09 08:45:11 UTC
Comment on attachment 68128 [details] [review]
Don't set the nickname to the normalized name on connect

Review of attachment 68128 [details] [review]:
-----------------------------------------------------------------

Wondering what happens if I set my nickname to empty string. Won't "notify::alias" be emitted to normalized id, and then mcd_account_self_contact_notify_alias_cb() will set normalized id as account nickname?
Comment 15 Xavier Claessens 2012-10-09 08:50:16 UTC
Comment on attachment 68131 [details] [review]
McdAccount: cope with self-contact changes; follow the  self-contact

Review of attachment 68131 [details] [review]:
-----------------------------------------------------------------

::: src/mcd-account.c
@@ +4590,5 @@
> +  if (self_contact != self->priv->self_contact)
> +    {
> +      g_clear_object (&self->priv->self_contact);
> +      self->priv->self_contact = g_object_ref (self_contact);
> +    }

I would early return if self->priv->self_contact == self_contact, this would avoid useless extra work.

@@ +4631,5 @@
>                                          tp_connection, dbus_error, details);
>  
> +    tp_g_signal_connect_object (tp_connection, "notify::self-contact",
> +        G_CALLBACK (mcd_account_self_contact_changed_cb), account,
> +        G_CONNECT_SWAPPED);

swapped is not useful here.
Comment 16 Xavier Claessens 2012-10-09 08:51:40 UTC
Comment on attachment 68133 [details] [review]
Knock out most of the IRC test until fd.o #55666 is  fixed

Review of attachment 68133 [details] [review]:
-----------------------------------------------------------------

::: tests/twisted/account-manager/irc.py
@@ +68,5 @@
>      q.dbus_return(set_aliases.message, signature='')
>  
> +    # FIXME: fd.o #55666 in telepathy-glib breaks the rest of this test.
> +    # Reinstate it when we depend on a version that has that fixed.
> +    return

It is fixed now
Comment 17 Xavier Claessens 2012-10-09 09:09:11 UTC
Comment on attachment 68137 [details] [review]
Track Avatars using McdAccount, and use the self-contact  for it

Review of attachment 68137 [details] [review]:
-----------------------------------------------------------------

::: src/mcd-account.c
@@ +1382,5 @@
> +static void
> +mcd_account_self_contact_notify_avatar_file_cb (McdAccount *self,
> +    GParamSpec *unused_param_spec G_GNUC_UNUSED,
> +    TpContact *self_contact)
> +{

Actually you don't need the unused_param_spec and self_contact args, which is the point of connect_swapped.

@@ +1429,5 @@
> +          g_free (uri);
> +          return;
> +        }
> +
> +      if (G_UNLIKELY (len > G_MAXUINT))

You're probably already OOM-killed at this point, but ok :)

@@ +4769,5 @@
> +
> +          tp_g_signal_connect_object (self_contact, "notify::avatar-file",
> +              G_CALLBACK (mcd_account_self_contact_notify_avatar_file_cb),
> +              self, G_CONNECT_SWAPPED);
> +          mcd_account_process_initial_avatar_token (self, self_contact);

You don't need that self_contact arg, it is self->priv->self_contact
Comment 18 Simon McVittie 2012-10-09 09:34:02 UTC
(In reply to comment #13)
> McdAccount: take responsibility for setting the nickname

> ::: src/mcd-account.c
> @@ +1318,5 @@
> > +    gpointer user_data,
> > +    GObject *weak_object)
> > +{
> > +  if (error)
> > +    WARNING ("%s", error->message);
> 
> Do we want a warning here? We usually uses DEBUG() for failing dbus calls

Yeah, perhaps. MC is pretty inconsistent about this; it uses WARNING() in at least some situations where it really shouldn't, like failed channel requests.

> @@ +4546,5 @@
> > +      if (self_contact == self->priv->self_contact)
> > +        {
> > +          tp_g_signal_connect_object (self_contact, "notify::alias",
> > +              G_CALLBACK (mcd_account_self_contact_notify_alias_cb),
> > +              self, G_CONNECT_SWAPPED);
> 
> swapped is nice to avoid the GParamSpec useless arg, but in this case you
> use both self and self_contact, so swapped is not needed.

I feel as though the swapped form is nicer in situations where you'll call the callback explicitly, like this:

+          tp_g_signal_connect_object (self_contact, "notify::alias",
+              G_CALLBACK (mcd_account_self_contact_notify_alias_cb),
+              self, G_CONNECT_SWAPPED);
+          mcd_account_self_contact_notify_alias_cb (self, NULL, self_contact);

but if you disagree, I can change this.

> @@ +4560,5 @@
> > +      g_ptr_array_unref (contacts);
> > +    }
> > +  else
> > +    {
> > +      WARNING ("failed to prepare self-contact: %s", error->message);
> 
> Same here, should we downgrade to DEBUG?

Yeah, probably.

(In reply to comment #14)
> Don't set the nickname to the normalized name on connect
...
> Wondering what happens if I set my nickname to empty string. Won't
> "notify::alias" be emitted to normalized id, and then
> mcd_account_self_contact_notify_alias_cb() will set normalized id as account
> nickname?

Yes. I think that's probably a feature - setting an empty nickname makes so little sense that I think we should quietly "correct" it.

I should maybe write a regression test for this, though.

(In reply to comment #15)
> McdAccount: cope with self-contact changes; follow the  self-contact

> I would early return if self->priv->self_contact == self_contact, this would
> avoid useless extra work.

Yeah, fair.

> swapped is not useful here.

As above.

(In reply to comment #16)
> Knock out most of the IRC test until fd.o #55666 is  fixed
...
> It is fixed now

As I said in the comment, it isn't really fixed until it's fixed in a telepathy-glib release, and we depend on that release.

(In reply to comment #17)
> Track Avatars using McdAccount, and use the self-contact  for it

> Actually you don't need the unused_param_spec and self_contact args, which
> is the point of connect_swapped.

This callback does use self_contact, just as a way to not have to fish it out of self->priv again.

Strictly speaking we should be early-returning if self-contact != self->priv->self_contact too, to cope with our unique ID changing; in principle we might have to rename ourselves in telepathy-salut, which has avatars (although I doubt we implement it correctly in Salut anyway).

> > +          tp_g_signal_connect_object (self_contact, "notify::avatar-file",
> > +              G_CALLBACK (mcd_account_self_contact_notify_avatar_file_cb),
> > +              self, G_CONNECT_SWAPPED);
> > +          mcd_account_process_initial_avatar_token (self, self_contact);
> 
> You don't need that self_contact arg, it is self->priv->self_contact

If it isn't an argument, then mcd_account_process_initial_avatar_token() will need to assert that self->priv->self_contact is non-NULL. That seems reasonable, though.
Comment 19 Simon McVittie 2012-10-09 10:26:15 UTC
(In reply to comment #18)
> > Wondering what happens if I set my nickname to empty string. Won't
> > "notify::alias" be emitted to normalized id, and then
> > mcd_account_self_contact_notify_alias_cb() will set normalized id as account
> > nickname?
> 
> Yes. I think that's probably a feature - setting an empty nickname makes so
> little sense that I think we should quietly "correct" it.

mcd_account_set_string_val() "normalizes" an empty string to NULL anyway, so using tp_str_empty() here wasn't actually a behaviour change.

When we connect, if we have no nickname stored locally, I think it's correct to try to get it from the remote connection - this means we do the right thing when creating e.g. a Gabble account and not specifically setting a nickname (we'll get the one from the server).

I think it makes sense to standardize on "nickname of '' is bad, try to do something better". I'll append a patch to make Set("Nickname", "") use the normalized name too.
Comment 20 Simon McVittie 2012-10-09 14:32:20 UTC
Created attachment 68339 [details] [review]
Downgrade failure to set alias/avatar from WARNING to  DEBUG
Comment 21 Simon McVittie 2012-10-09 14:32:34 UTC
Created attachment 68340 [details] [review]
Downgrade failure to prepare self-contact from WARNING  to DEBUG
Comment 22 Simon McVittie 2012-10-09 14:34:28 UTC
Created attachment 68341 [details] [review]
nickname test: test what happens when we set an empty  nickname
Comment 23 Simon McVittie 2012-10-09 14:34:51 UTC
Created attachment 68342 [details] [review]
Implement Set("Nickname", "") by using the normalized  name instead

This is consistent with what we do when we first connect, and ensures
that we always have some sort of nickname.
Comment 24 Simon McVittie 2012-10-09 14:35:16 UTC
Created attachment 68343 [details] [review]
Ignore changes to the avatar of former self-contacts
Comment 25 Simon McVittie 2012-10-09 14:35:37 UTC
Created attachment 68344 [details] [review]
mcd_account_process_initial_avatar_token: don't take  self_contact argument

It can be retrieved from the McdAccount.
Comment 26 Simon McVittie 2012-10-09 14:35:53 UTC
Created attachment 68345 [details] [review]
mcd_account_self_contact_changed_cb: ignore no-op  changes
Comment 27 Simon McVittie 2012-10-09 14:37:20 UTC
Things I haven't changed from Xavier's review: use of swapped signal arguments; semi-reversion of IRC test until we depend on a good enough telepathy-glib.
Comment 28 Xavier Claessens 2012-10-09 14:47:54 UTC
Ship it :)
Comment 29 Simon McVittie 2012-10-11 09:29:25 UTC
Shipped it. It'll be in 5.15.0.


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.