Bug 41789 - Expose Facebook ids into Facebook Chat contacts’
Summary: Expose Facebook ids into Facebook Chat contacts’
Status: RESOLVED FIXED
Alias: None
Product: Telepathy
Classification: Unclassified
Component: gabble (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: Telepathy bugs list
QA Contact: Telepathy bugs list
URL: http://cgit.collabora.com/git/user/an...
Whiteboard:
Keywords: patch
Depends on: 30296 32690 32691 32692
Blocks:
  Show dependency treegraph
 
Reported: 2011-10-14 07:01 UTC by Andre Moreira Magalhaes
Modified: 2011-11-24 09:02 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Andre Moreira Magalhaes 2011-10-14 07:01:17 UTC
Currently applications have to rely on checking the user jid to extract the facebook user IDs when connecting to facebook. It would be good to expose this info directly to applications.
Comment 1 Andre Moreira Magalhaes 2011-10-14 07:02:32 UTC
Branch at URL attempts to fix this by adding a X-FACEBOOK-ID field in the ContactInfo for facebook contacts.
Comment 2 Will Thompson 2011-10-31 09:37:21 UTC
+    contact_info = [(u'x-facebook-id', [], [u'test']),]

+        {handle: {cs.CONN_IFACE_CONTACT_INFO + '/info': contact_info,
+                  'org.freedesktop.Telepathy.Connection/contact-id': 'test@chat.facebook.com'}},

Do you really intend to leave the leading '-' on the Facebook IDs? JIDs on Facebook look like -1407062450@chat.facebook.com; this will yield 'x-facebook-id': '-1407062450' in the contact info. The test case should definitely use something formatted like a real Facebook Chat JID.

The first patch is kind of a PITA to review because it's actually two patches: one preserving the context for the vCard callback, and the other inserting the Facebook stuff…

 } VCardField;
+typedef struct {

There should be a space in between the two definitions.


+   if (username && tp_strdiff (server, "chat.facebook.com") == 0)

username != NULL; and tp_strdiff returns a gboolean, so you should use !tp_strdiff (server, "chat.facebook.com"). But in fact, I think I would be happier if there was a flag on the connection to say whether or not we're on Facebook (see http://cgit.collabora.com/git/user/wjt/telepathy-gabble-wjt.git/commit/?h=facebook-url for my WIP for the same feature); then _insert_server_specific_info() could just early-return if we're not on Facebook, rather than decomposing every single JID on every other connection.


+      VCardRequestInfo *request_info = g_new (VCardRequestInfo, 1);

Use g_slice_new(). I would be happier if there were new and free functions for VCardRequestInfo.
Comment 3 Andre Moreira Magalhaes 2011-11-13 17:44:07 UTC
Ok, we decided to implement this using Addressing instead of ContactInfo. URL is now updated to point to the correct repo.
Comment 4 Andre Moreira Magalhaes 2011-11-16 15:37:26 UTC
Branch updated with the latest changes in bug #30296 and dependencies.
Comment 5 Simon McVittie 2011-11-17 04:03:28 UTC
> @@ -223,6 +223,28 @@ gabble_parse_vcard_address (const gchar *vcard_field,

This seems to be taking a JID and converting it into a Facebook ID. I'm pretty sure that's wrong: it should be expecting an unsigned ASCII integer (e.g. 12345) and returning -12345@chat.facebook.com, or raising an error if the vCard field value isn't an unsigned ASCII integer.

Now that I look at that function again: is it meant to return a JID, or a normalized value for that vCard field? For x-jabber they're equivalent, but for x-facebook-id they're not! You'll need to split it into "normalize", "to_jid", "jid_to", as for URIs.

Here are some high-level things that we want to be true:

    NormalizeVCardAddress("x-facebook-id", "12345") -> "12345"
    NormalizeVCardAddress("x-facebook-id", "not a number") -> error
    NormalizeVCardAddress("x-facebook-id", "-12345") -> error
    NormalizeVCardAddress("x-facebook-id", "-12345@chat.facebook.com") -> error
    NormalizeVCardAddress("x-jabber", "-12345@CHAT.FaceBook.com")
        -> "-12345@chat.facebook.com")

    GetContactsByVCardField("x-facebook-id", ["12345"], [])
        -> details of the contact with JID "-12345@chat.facebook.com"
    GetContactsByVCardField("x-facebook-id", [x], [])
        -> no result for any x that produced an error above

    "/addresses" attr of "-12345@chat.facebook.com"
        -> { "x-jabber": "-12345@chat.facebook.com", "x-facebook-id": "12345" }
    "/addresses" attr of "dave@example.com"
        -> { "x-jabber": "dave@example.com" }
Comment 6 Simon McVittie 2011-11-17 04:06:54 UTC
Something we should have as a general principle is that for all values of field and old_value that don't cause this call to raise an error:

    new_value = NormalizeVCardAddress(field, old_value)

we should be able to normalize it again and get the same thing:

    NormalizeVCardAddress(field, new_value) == new_value

Otherwise we can't really call it "normalization". I don't think that's true in this branch.
Comment 7 Andre Moreira Magalhaes 2011-11-17 07:15:43 UTC
(In reply to comment #5)
> > @@ -223,6 +223,28 @@ gabble_parse_vcard_address (const gchar *vcard_field,
> 
> This seems to be taking a JID and converting it into a Facebook ID. I'm pretty
> sure that's wrong: it should be expecting an unsigned ASCII integer (e.g.
> 12345) and returning -12345@chat.facebook.com, or raising an error if the vCard
> field value isn't an unsigned ASCII integer.
> 
> Now that I look at that function again: is it meant to return a JID, or a
> normalized value for that vCard field? For x-jabber they're equivalent, but for
> x-facebook-id they're not! You'll need to split it into "normalize", "to_jid",
> "jid_to", as for URIs.
> 
> Here are some high-level things that we want to be true:
> 
>     NormalizeVCardAddress("x-facebook-id", "12345") -> "12345"
>     NormalizeVCardAddress("x-facebook-id", "not a number") -> error
>     NormalizeVCardAddress("x-facebook-id", "-12345") -> error
>     NormalizeVCardAddress("x-facebook-id", "-12345@chat.facebook.com") -> error
>     NormalizeVCardAddress("x-jabber", "-12345@CHAT.FaceBook.com")
>         -> "-12345@chat.facebook.com")
> 
>     GetContactsByVCardField("x-facebook-id", ["12345"], [])
>         -> details of the contact with JID "-12345@chat.facebook.com"
>     GetContactsByVCardField("x-facebook-id", [x], [])
>         -> no result for any x that produced an error above
> 
>     "/addresses" attr of "-12345@chat.facebook.com"
>         -> { "x-jabber": "-12345@chat.facebook.com", "x-facebook-id": "12345" }
>     "/addresses" attr of "dave@example.com"
>         -> { "x-jabber": "dave@example.com" }
Tnx for the review, I've updated the branch with the suggested changes and also rebased it on top of the changes in bug #30296.
Comment 8 Simon McVittie 2011-11-17 08:15:00 UTC
> addressing-util: Refactor gabble_parse_vcard_address in
> gabble_normalize_vcard_address, gabble_vcard_address_to_jid
> and gabble_jid_to_vcard_address.

Er, this isn't (just) refactoring... it's also "... and make x-facebook-id parsing expect a number, not a JID". Please be a bit more careful with your commit messages - they're all the context you'll have in n years' time when you're debugging this stuff and have forgotten how it worked :-)

> + while (*s && (g_ascii_isalnum (*s))) s++;

That's not "is numeric" :-)

(also, our coding style would have you use two lines for that)

The implementation looks OK now.
Comment 9 Andre Moreira Magalhaes 2011-11-17 08:45:24 UTC
(In reply to comment #8)
> > addressing-util: Refactor gabble_parse_vcard_address in
> > gabble_normalize_vcard_address, gabble_vcard_address_to_jid
> > and gabble_jid_to_vcard_address.
> 
> Er, this isn't (just) refactoring... it's also "... and make x-facebook-id
> parsing expect a number, not a JID". Please be a bit more careful with your
> commit messages - they're all the context you'll have in n years' time when
> you're debugging this stuff and have forgotten how it worked :-)
Amended the commit with a better msg :)

> > + while (*s && (g_ascii_isalnum (*s))) s++;
> 
> That's not "is numeric" :-)
Haha, I swear I misread isnum there, changed to isdigit now :P
 
> (also, our coding style would have you use two lines for that)
Done also.
Comment 10 Simon McVittie 2011-11-18 06:32:26 UTC
Looks OK, blocked by previous branches.
Comment 11 Will Thompson 2011-11-24 09:02:13 UTC
0.15.1


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.