summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ephraim_roster.erl26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/core/ephraim_roster.erl b/src/core/ephraim_roster.erl
index 2998782..6360a34 100644
--- a/src/core/ephraim_roster.erl
+++ b/src/core/ephraim_roster.erl
@@ -51,33 +51,45 @@ updateResource(Roster, JID, Priority, Type, Show, Status) ->
end,
Roster#roster{entries=Entries}.
--spec updateRosterEntry(#roster{}, binary(), binary(), atom()) -> #roster{}.
-updateRosterEntry(Roster, JID, Name, Subscription) ->
+-spec updateRosterEntry(#roster{}, binary(), binary(), atom(), set()) -> #roster{}.
+updateRosterEntry(Roster, JID, Name, Subscription, Groups) ->
Resources = case dict:find(JID, Roster#roster.entries) of
{ok, Entry} ->
Entry#roster_entry.resources;
error ->
dict:new()
end,
- Groups = sets:new(),
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, dict:to_list(Resources)}},
+ ephraim ! {ui_update, {roster_update, JID, Name, Subscription, sets:to_list(Groups), dict:to_list(Resources)}},
Roster#roster{entries=Entries}.
+-spec getGroups([#xmlel{}]) -> set().
+getGroups(Els) ->
+ getGroups(sets:new(), Els).
+
+-spec getGroups(set(), [#xmlel{}]) -> set().
+getGroups(Groups, []) ->
+ Groups;
+getGroups(Groups, [#xmlel{ns='jabber:iq:roster',name=group,children=[#xmlcdata{cdata=Group}]}|Rest]) ->
+ getGroups(sets:add_element(Group, Groups), Rest);
+getGroups(Groups, [_|Rest]) ->
+ getGroups(Groups, Rest).
+
-spec handleRosterIQ(#roster{}, #xmlel{}) -> #roster{}.
handleRosterIQ(Roster, Item) ->
JID = exmpp_xml:get_attribute(Item, jid, undefined),
Name = exmpp_xml:get_attribute(Item, name, undefined),
+ Groups = getGroups(Item#xmlel.children),
Subscription = binary_to_atom(exmpp_xml:get_attribute(Item, subscription, undefined), utf8),
- updateRosterEntry(Roster, JID, Name, Subscription).
+ updateRosterEntry(Roster, JID, Name, Subscription, Groups).
-spec handleRosterIQs(#roster{}, [#xmlel{}]) -> #roster{}.
handleRosterIQs(Roster, []) ->
Roster;
-handleRosterIQs(Roster, [Item = #xmlel{name=item}|Rest]) ->
+handleRosterIQs(Roster, [Item = #xmlel{ns='jabber:iq:roster',name=item}|Rest]) ->
Roster2 = handleRosterIQ(Roster, Item),
handleRosterIQs(Roster2, Rest);
@@ -103,7 +115,7 @@ loop(Roster) ->
{roster_iq, Payload} ->
Roster2 = handleRosterIQs(Roster, Payload#xmlel.children),
- io:format("ephraim_roster: IQ: ~p~n", [Payload]),
+ %io:format("ephraim_roster: IQ: ~p~n", [Payload]),
loop(Roster2);
Msg ->