diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-07-28 15:55:38 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2010-07-28 15:55:38 +0200 |
commit | eb4193538b99cf9d49ad0650b1bb816844361ab5 (patch) | |
tree | 1230f7cf90125217ac2d90f7fb91df3ab90ea437 /src/core/ephraim_roster.erl | |
parent | 7b06327c42968214730f0ad155565ebd760ad526 (diff) | |
download | ephraim-eb4193538b99cf9d49ad0650b1bb816844361ab5.tar ephraim-eb4193538b99cf9d49ad0650b1bb816844361ab5.zip |
Show vCard avatars
Diffstat (limited to 'src/core/ephraim_roster.erl')
-rw-r--r-- | src/core/ephraim_roster.erl | 32 |
1 files changed, 14 insertions, 18 deletions
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); |