Skip to content

Commit bf0176a

Browse files
committed
pep-avatar: select png from the list of available avatars
1 parent 2f08ad3 commit bf0176a

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/conn-avatars.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct {
4444
} pep_request_ctx;
4545

4646
static pep_request_ctx *
47-
pep_avatar_request_data (GabbleConnection *conn, TpHandle handle);
47+
pep_avatar_request_data (GabbleConnection *conn, TpHandle handle, gchar *id);
4848

4949
/* If the SHA1 has changed, this function will copy it to self_presence,
5050
* emit a signal and push it to the server. */
@@ -719,10 +719,10 @@ gabble_connection_request_avatars (TpSvcConnectionInterfaceAvatars *iface,
719719
if (NULL == g_hash_table_lookup (self->avatar_requests,
720720
GUINT_TO_POINTER (contact)))
721721
{
722-
if (g_hash_table_lookup (self->pep_avatar_hashes, GINT_TO_POINTER(contact)))
722+
gchar *id;
723+
if (id = g_hash_table_lookup (self->pep_avatar_hashes, GINT_TO_POINTER(contact)))
723724
{
724-
pep_request_ctx *ctx = pep_avatar_request_data (self, contact);
725-
725+
pep_request_ctx *ctx = pep_avatar_request_data (self, contact, id);
726726
g_hash_table_insert (self->avatar_requests,
727727
GUINT_TO_POINTER (contact), ctx);
728728
}
@@ -930,11 +930,12 @@ conn_avatars_fill_contact_attributes (GObject *obj,
930930
if (NULL != presence)
931931
{
932932
GValue *val = tp_g_value_slice_new (G_TYPE_STRING);
933+
gchar *id;
933934

934935
if (NULL != presence->avatar_sha1)
935936
g_value_set_string (val, presence->avatar_sha1);
936-
else if (g_hash_table_lookup (self->pep_avatar_hashes, GINT_TO_POINTER(handle)))
937-
g_value_set_string (val, g_hash_table_lookup (self->pep_avatar_hashes, GINT_TO_POINTER(handle)));
937+
else if (id = g_hash_table_lookup (self->pep_avatar_hashes, GINT_TO_POINTER(handle)))
938+
g_value_set_string (val, id);
938939
else
939940
g_value_set_string (val, "");
940941

@@ -958,8 +959,8 @@ pep_avatar_request_data_cb (
958959

959960
const gchar *binval_value;
960961
gchar *sha1;
961-
/* todo: get mime type from metadata pep, if any */
962-
const gchar *mime_type = "";
962+
// we only request avatars of type png, so this is fixed for now
963+
const gchar *mime_type = "image/png";
963964
gchar *bindata;
964965
gsize outlen;
965966
GArray *arr;
@@ -1071,6 +1072,7 @@ pep_avatar_metadata_node_changed (WockyPepService *pep,
10711072
(TpBaseConnection *) conn, TP_HANDLE_TYPE_CONTACT);
10721073
TpHandle handle;
10731074
WockyNode *metadata, *info;
1075+
WockyNodeIter iter;
10741076
const gchar *jid;
10751077
const gchar *sha1;
10761078

@@ -1096,11 +1098,23 @@ pep_avatar_metadata_node_changed (WockyPepService *pep,
10961098
return;
10971099
}
10981100

1099-
// FIXME: there may exist multiple child nodes
1100-
info = wocky_node_get_child (metadata, "info");
1101-
if (NULL == info)
1101+
gchar *type;
1102+
info = NULL;
1103+
wocky_node_iter_init (&iter, metadata, "info", NULL);
1104+
while (wocky_node_iter_next (&iter, &info))
1105+
{
1106+
gchar *url = wocky_node_get_attribute (info, "url");
1107+
type = wocky_node_get_attribute (info, "type");
1108+
//Found one of type png which is not an url node
1109+
if ((type) && (g_strcmp0(type, "image/png") == 0) && (!url))
1110+
{
1111+
break;
1112+
}
1113+
}
1114+
1115+
if (!info)
11021116
{
1103-
STANZA_DEBUG (stanza, "PEP metadata without info nodes, ignoring");
1117+
STANZA_DEBUG (stanza, "avatar metadata without compatible type, ignoring");
11041118
return;
11051119
}
11061120

@@ -1117,7 +1131,7 @@ pep_avatar_metadata_node_changed (WockyPepService *pep,
11171131
}
11181132

11191133
static pep_request_ctx *
1120-
pep_avatar_request_data (GabbleConnection *conn, TpHandle handle)
1134+
pep_avatar_request_data (GabbleConnection *conn, TpHandle handle, gchar *id)
11211135
{
11221136
TpBaseConnection *base = (TpBaseConnection *) conn;
11231137
pep_request_ctx *ctx;
@@ -1139,6 +1153,9 @@ pep_avatar_request_data (GabbleConnection *conn, TpHandle handle)
11391153
':', NS_PUBSUB,
11401154
'(', "items",
11411155
'@', "node", NS_AVATAR_DATA,
1156+
'(', "item",
1157+
'@', "id", id,
1158+
')',
11421159
')',
11431160
')',
11441161
NULL);

0 commit comments

Comments
 (0)