diff options
-rw-r--r-- | src/core/ephraim_event.erl | 42 | ||||
-rw-r--r-- | src/core/ephraim_roster.erl | 32 | ||||
-rw-r--r-- | src/gui/CellRendererContact.vala | 36 |
3 files changed, 53 insertions, 57 deletions
diff --git a/src/core/ephraim_event.erl b/src/core/ephraim_event.erl index d32914a..d8778e4 100644 --- a/src/core/ephraim_event.erl +++ b/src/core/ephraim_event.erl @@ -8,17 +8,17 @@ init() -> -spec handleEvent(binary(), #xmlel{}) -> ok. handleEvent(From, Item) -> - HasAvatarData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:data', data), - HasAvatarMetaData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:metadata', metadata), - if HasAvatarData -> - Element = exmpp_xml:get_element(Item, 'urn:xmpp:avatar:data', data), - Data = base64:decode(exmpp_xml:get_cdata_from_list(Element#xmlel.children)), - ephraim ! {roster, {avatar, From, Data}}, - ok; - HasAvatarMetaData -> - ok; + % HasAvatarData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:data', data), + % HasAvatarMetaData = exmpp_xml:has_element(Item, 'urn:xmpp:avatar:metadata', metadata), + if %HasAvatarData -> + % Element = exmpp_xml:get_element(Item, 'urn:xmpp:avatar:data', data), + % Data = base64:decode(exmpp_xml:get_cdata_from_list(Element#xmlel.children)), + % ephraim ! {roster, {avatar, From, Data}}, + % ok; + %HasAvatarMetaData -> + % ok; true -> - io:format("Received unhandled event from ~p:~n~p~n", [From, Item]) + io:format("Received unhandled event from ~p:~n~p~n", [From, Item]) end. -spec handleEvents(binary(), [#xmlel{}]) -> ok. @@ -32,15 +32,15 @@ handleEvents(From, [Item|Rest]) -> loop() -> receive stop -> - ok; - - {receive_event, From, Packet} -> - Event = exmpp_xml:get_element(Packet, 'http://jabber.org/protocol/pubsub#event', event), - Items = exmpp_xml:get_element(Event, 'http://jabber.org/protocol/pubsub#event', items), - handleEvents(From, Items#xmlel.children), - loop(); - - Msg -> - io:format("ephraim_event: ~p~n", [Msg]), - loop() + ok; + + {receive_event, From, Packet} -> + Event = exmpp_xml:get_element(Packet, 'http://jabber.org/protocol/pubsub#event', event), + Items = exmpp_xml:get_element(Event, 'http://jabber.org/protocol/pubsub#event', items), + handleEvents(From, Items#xmlel.children), + loop(); + + Msg -> + io:format("ephraim_event: ~p~n", [Msg]), + loop() end. 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); diff --git a/src/gui/CellRendererContact.vala b/src/gui/CellRendererContact.vala index bff0bba..924b601 100644 --- a/src/gui/CellRendererContact.vala +++ b/src/gui/CellRendererContact.vala @@ -46,25 +46,25 @@ public class CellRendererContact : Gtk.CellRenderer { Gee.Map.Entry<string, Contact.Resource>? r = contact.get_resource_with_highest_priority(); if(r == null) { presenceRenderer.pixbuf = offline; - return; } - - switch(r.value.show) { - case Contact.Show.ONLINE: - presenceRenderer.pixbuf = online; - break; - case Contact.Show.AWAY: - presenceRenderer.pixbuf = away; - break; - case Contact.Show.DND: - presenceRenderer.pixbuf = dnd; - break; - case Contact.Show.XA: - presenceRenderer.pixbuf = xa; - break; - case Contact.Show.UNDEFINED: - presenceRenderer.pixbuf = undefined; - break; + else { + switch(r.value.show) { + case Contact.Show.ONLINE: + presenceRenderer.pixbuf = online; + break; + case Contact.Show.AWAY: + presenceRenderer.pixbuf = away; + break; + case Contact.Show.DND: + presenceRenderer.pixbuf = dnd; + break; + case Contact.Show.XA: + presenceRenderer.pixbuf = xa; + break; + default: + presenceRenderer.pixbuf = undefined; + break; + } } avatarRenderer.pixbuf = contact.avatar; |