From eb4193538b99cf9d49ad0650b1bb816844361ab5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 28 Jul 2010 15:55:38 +0200 Subject: Show vCard avatars --- src/core/ephraim_roster.erl | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/core/ephraim_roster.erl') diff --git a/src/core/ephraim_roster.erl b/src/core/ephraim_roster.erl index e0a1da6..aa31fd1 100644 --- a/src/core/ephraim_roster.erl +++ b/src/core/ephraim_roster.erl @@ -79,24 +79,19 @@ updateVCard(Roster, JID, VCard) -> error -> #roster_entry{} end, - NewEntry = OldEntry#roster_entry{vcard=VCard}, - Entries = dict:store(JID, NewEntry, Roster#roster.entries), - uiUpdate(JID, NewEntry), + Avatar = case dict:find('PHOTO', VCard) of + {ok, AvatarData} -> + #avatar{data=AvatarData}; + error -> + OldEntry#roster_entry.avatar + end, + + NewEntry = OldEntry#roster_entry{vcard=VCard,avatar=Avatar}, - Roster#roster{entries=Entries}. - --spec updateAvatar(#roster{}, binary(), binary()) -> #roster{}. -updateAvatar(Roster, JID, Avatar) -> - RosterEntry = case dict:find(JID, Roster#roster.entries) of - {ok, Entry} -> - Entry; - error -> - #roster_entry{} - end, - NewEntry = RosterEntry#roster_entry{avatar=#avatar{data=Avatar}}, Entries = dict:store(JID, NewEntry, Roster#roster.entries), uiUpdate(JID, NewEntry), + Roster#roster{entries=Entries}. -spec uiUpdate(binary(), #roster_entry{}) -> ok. @@ -147,6 +142,11 @@ handleRosterIQs(Roster, [_|Rest]) -> -spec handleVCardIQ(dict(), #xmlel{}|#xmlcdata{}) -> dict(). +handleVCardIQ(Dict, Item=#xmlel{name='PHOTO'}) -> + Element = exmpp_xml:get_element(Item, 'BINVAL'), + Data = base64:decode(exmpp_xml:get_cdata_from_list(Element#xmlel.children)), + dict:store('PHOTO', Data, Dict); + handleVCardIQ(Dict, Item=#xmlel{name=Key}) -> Value = exmpp_xml:get_cdata(Item), dict:store(Key, Value, Dict); @@ -201,10 +201,6 @@ loop(Roster) -> Roster2 = updateResource(Roster, From, Priority, Type, Show, Status), loop(Roster2); - {avatar, From, Avatar} -> - Roster2 = updateAvatar(Roster, From, Avatar), - loop(Roster2); - {roster_iq, Payload} -> Roster2 = handleRosterIQs(Roster, Payload#xmlel.children), loop(Roster2); -- cgit v1.2.3