diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-08-03 11:39:36 +0100 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-08-19 10:29:49 +0100 |
commit | ecad75d4a995f14fb30dc4cc4c2e9abab7b5d94a (patch) | |
tree | 7152abd910cc08f9875c7289d090085933236f5b /src/search-channel.c | |
parent | 7021cd773e992e30a8b93d70026c14ed16c844c7 (diff) | |
download | telepathy-gabble-ecad75d4a995f14fb30dc4cc4c2e9abab7b5d94a.tar.gz |
emit_search_result: use the xmpp_to_tp hash table instead of hard coding fields
This had the side effect to to expose the "x-n-family" and "x-n-given"
info field in the search result which is probably what we want.
Diffstat (limited to 'src/search-channel.c')
-rw-r--r-- | src/search-channel.c | 69 |
1 files changed, 37 insertions, 32 deletions
diff --git a/src/search-channel.c b/src/search-channel.c index 26ac460b9..c4b995eb0 100644 --- a/src/search-channel.c +++ b/src/search-channel.c @@ -561,16 +561,13 @@ emit_search_result (GabbleSearchChannel *chan, GHashTable *info_map) { GPtrArray *info = g_ptr_array_new (); - gchar *jid, *first, *last, *nick, *email; + gchar *jid, *first = NULL, *last = NULL; TpHandle h = 0; GError *e = NULL; + gpointer key, value; + GHashTableIter iter; jid = ht_lookup_and_remove (info_map, "jid"); - last = ht_lookup_and_remove (info_map, "last"); - first = ht_lookup_and_remove (info_map, "first"); - nick = ht_lookup_and_remove (info_map, "nick"); - email = ht_lookup_and_remove (info_map, "email"); - if (jid == NULL) { DEBUG ("no jid; giving up"); @@ -593,6 +590,40 @@ emit_search_result (GabbleSearchChannel *chan, g_ptr_array_add (info, make_field ("x-telepathy-identifier", components)); } + g_hash_table_iter_init (&iter, info_map); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + const gchar *tp_name; + gchar *components[] = { value, NULL }; + + tp_name = g_hash_table_lookup (xmpp_to_tp, key); + if (tp_name == NULL) + { + DEBUG ("<item> contained field we don't understand (%s); ignoring it:" + , (const gchar *) key); + continue; + } + + if (value == NULL) + { + DEBUG ("field %s (%s) doesn't have a value; ignoring it", + (const gchar *) key, tp_name); + continue; + } + + DEBUG ("found field %s (%s): %s", (const gchar *) key, tp_name, + (const gchar *) value); + + g_ptr_array_add (info, make_field (tp_name, components)); + + if (!tp_strdiff (key, "last") || + !tp_strdiff (key, "family")) + last = value; + else if (!tp_strdiff (key, "first") || + !tp_strdiff (key, "given")) + first = value; + } + /* Build 'n' field: Family Name, Given Name, Additional Names, Honorific * Prefixes, and Honorific Suffixes. */ @@ -609,32 +640,6 @@ emit_search_result (GabbleSearchChannel *chan, g_ptr_array_add (info, make_field ("n", components)); } - /* Build 'nickname' field. */ - if (nick != NULL) - { - gchar *components[] = { nick, NULL }; - g_ptr_array_add (info, make_field ("nickname", components)); - } - - /* Build 'email' field */ - if (email != NULL) - { - gchar *components[] = { email, NULL }; - g_ptr_array_add (info, make_field ("email", components)); - } - - if (g_hash_table_size (info_map) > 0) - { - GHashTableIter iter; - gpointer key; - - DEBUG ("<item> contained fields we don't understand; ignoring them:"); - - g_hash_table_iter_init (&iter, info_map); - while (g_hash_table_iter_next (&iter, &key, NULL)) - DEBUG ("\t- %s has been ignored", (gchar *) key); - } - gabble_svc_channel_type_contact_search_emit_search_result_received (chan, h, info); out: |