aboutsummaryrefslogtreecommitdiff
path: root/xmpp-vala/src/module/xep/0054_vcard/module.vala
diff options
context:
space:
mode:
authorfiaxh <git@mx.ax.lt>2017-03-11 23:04:58 +0100
committerfiaxh <git@mx.ax.lt>2017-03-11 23:09:57 +0100
commitf40a34bdc1995e656b09cc1252a8dcce685e373f (patch)
treed56684122d0a2f0e13ee9d94e6e8675bae1b4c52 /xmpp-vala/src/module/xep/0054_vcard/module.vala
parent0ea4ac7e20674e3e6a8d1b3d4b53702dace72907 (diff)
downloaddino-f40a34bdc1995e656b09cc1252a8dcce685e373f.tar.gz
dino-f40a34bdc1995e656b09cc1252a8dcce685e373f.zip
Use delegates + object storage instead of listener objects
Diffstat (limited to 'xmpp-vala/src/module/xep/0054_vcard/module.vala')
-rw-r--r--xmpp-vala/src/module/xep/0054_vcard/module.vala36
1 files changed, 13 insertions, 23 deletions
diff --git a/xmpp-vala/src/module/xep/0054_vcard/module.vala b/xmpp-vala/src/module/xep/0054_vcard/module.vala
index 037f723b..622f2657 100644
--- a/xmpp-vala/src/module/xep/0054_vcard/module.vala
+++ b/xmpp-vala/src/module/xep/0054_vcard/module.vala
@@ -53,32 +53,22 @@ public class Module : XmppStreamModule {
} else {
iq.to = get_bare_jid(presence.from);
}
- stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, new IqResponseListenerImpl(this, storage, sha1));
+ stream.get_module(Iq.Module.IDENTITY).send_iq(stream, iq, on_received_vcard);
}
}
- private class IqResponseListenerImpl : Iq.ResponseListener, Object {
- Module outer;
- PixbufStorage storage;
- string id;
- public IqResponseListenerImpl(Module outer, PixbufStorage storage, string id) {
- this.outer = outer;
- this.id = id;
- this.storage = storage;
- }
- public void on_result(XmppStream stream, Iq.Stanza iq) {
- if (iq.is_error()) return;
- StanzaNode? vcard_node = iq.stanza.get_subnode("vCard", NS_URI);
- if (vcard_node == null) return;
- StanzaNode? photo_node = vcard_node.get_subnode("PHOTO", NS_URI);
- if (photo_node == null) return;
- StanzaNode? binary_node = photo_node.get_subnode("BINVAL", NS_URI);
- if (binary_node == null) return;
- string? content = binary_node.get_string_content();
- if (content == null) return;
- storage.store(id, Base64.decode(content));
- outer.received_avatar(stream, iq.from, id);
- }
+ private static void on_received_vcard(XmppStream stream, Iq.Stanza iq) {
+ if (iq.is_error()) return;
+ StanzaNode? vcard_node = iq.stanza.get_subnode("vCard", NS_URI);
+ if (vcard_node == null) return;
+ StanzaNode? photo_node = vcard_node.get_subnode("PHOTO", NS_URI);
+ if (photo_node == null) return;
+ StanzaNode? binary_node = photo_node.get_subnode("BINVAL", NS_URI);
+ if (binary_node == null) return;
+ string? content = binary_node.get_string_content();
+ if (content == null) return;
+ string sha1 = Checksum.compute_for_data(ChecksumType.SHA1, content.data);
+ stream.get_module(IDENTITY).received_avatar(stream, iq.from, sha1);
}
}
}