summaryrefslogtreecommitdiffstats
path: root/src/core/ephraim_roster.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ephraim_roster.erl')
-rw-r--r--src/core/ephraim_roster.erl52
1 files changed, 42 insertions, 10 deletions
diff --git a/src/core/ephraim_roster.erl b/src/core/ephraim_roster.erl
index bfc40b1..2426761 100644
--- a/src/core/ephraim_roster.erl
+++ b/src/core/ephraim_roster.erl
@@ -6,11 +6,16 @@
entries :: dict()
}).
+-record(avatar, {
+ data :: binary()
+ }).
+
-record(roster_entry, {
name :: binary() | undefined,
subscription :: atom() | undefined,
groups :: set(),
- resources :: dict()
+ resources :: dict(),
+ avatar :: #avatar{} | undefined
}).
-record(resource_entry, {
@@ -19,7 +24,6 @@
status :: binary()
}).
-
-spec init() -> ok.
init() ->
loop(#roster{entries=dict:new()}).
@@ -45,13 +49,11 @@ updateResource(Roster, JID, Priority, Type, Show, Status) ->
_ ->
RosterEntry#roster_entry.resources
end,
- Entries = dict:store(BareJID, RosterEntry#roster_entry{resources=Resources}, Roster#roster.entries),
- if RosterEntry#roster_entry.subscription =:= undefined ->
- ok;
- true ->
- ephraim ! {ui_update, {roster_update, BareJID, RosterEntry#roster_entry.name, RosterEntry#roster_entry.subscription,
- sets:to_list(RosterEntry#roster_entry.groups), dict:to_list(Resources)}}
- end,
+ NewEntry = RosterEntry#roster_entry{resources=Resources},
+
+ Entries = dict:store(BareJID, NewEntry, Roster#roster.entries),
+ uiUpdate(BareJID, NewEntry),
+
Roster#roster{entries=Entries}.
-spec updateRosterEntry(#roster{}, binary(), binary(), atom(), set()) -> #roster{}.
@@ -63,10 +65,36 @@ updateRosterEntry(Roster, JID, Name, Subscription, Groups) ->
dict:new()
end,
NewEntry = #roster_entry{subscription=Subscription,name=Name,resources=Resources,groups=Groups},
+
Entries = dict:store(JID, NewEntry, Roster#roster.entries),
- ephraim ! {ui_update, {roster_update, JID, Name, Subscription, sets:to_list(Groups), dict:to_list(Resources)}},
+ uiUpdate(JID, NewEntry),
+
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{resources=dict:new()}
+ 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.
+uiUpdate(JID, RosterEntry) ->
+ if RosterEntry#roster_entry.subscription =:= undefined ->
+ ok;
+ true ->
+ ephraim ! {ui_update, {roster_update, JID, RosterEntry#roster_entry.name, RosterEntry#roster_entry.subscription,
+ sets:to_list(RosterEntry#roster_entry.groups), dict:to_list(RosterEntry#roster_entry.resources),
+ RosterEntry#roster_entry.avatar}},
+ ok
+ end.
+
-spec getGroups([#xmlel{}]) -> set().
getGroups(Els) ->
getGroups(sets:new(), Els).
@@ -116,6 +144,10 @@ 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),
%io:format("ephraim_roster: IQ: ~p~n", [Payload]),