From f40a34bdc1995e656b09cc1252a8dcce685e373f Mon Sep 17 00:00:00 2001 From: fiaxh Date: Sat, 11 Mar 2017 23:04:58 +0100 Subject: Use delegates + object storage instead of listener objects --- xmpp-vala/src/module/xep/0054_vcard/module.vala | 36 +++++++++---------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'xmpp-vala/src/module/xep/0054_vcard/module.vala') 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); } } } -- cgit v1.2.3-54-g00ecf