aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>2016-07-07 14:53:15 +0300
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>2016-07-08 15:07:10 +0300
commit368b2021446c6a069a2f1e772c43160eac2026c9 (patch)
treeb25161b9c66301f048e914b0cb072e040d7d24ad
parentAdvertise MUC/Sub support in MUC service disco#info (diff)
Handle MUC/Sub subscriptions list request
-rw-r--r--src/mod_muc.erl25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mod_muc.erl b/src/mod_muc.erl
index 8e9096337..8571fcab6 100644
--- a/src/mod_muc.erl
+++ b/src/mod_muc.erl
@@ -429,6 +429,18 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
iq_get_vcard(Lang)}]},
ejabberd_router:route(To, From,
jlib:iq_to_xml(Res));
+ #iq{type = get, xmlns = ?NS_MUCSUB,
+ sub_el = #xmlel{name = <<"subscriptions">>} = SubEl} = IQ ->
+ RoomJIDs = get_subscribed_rooms(ServerHost, Host, From),
+ Subs = lists:map(
+ fun(J) ->
+ #xmlel{name = <<"subscription">>,
+ attrs = [{<<"jid">>,
+ jid:to_string(J)}]}
+ end, RoomJIDs),
+ Res = IQ#iq{type = result,
+ sub_el = [SubEl#xmlel{children = Subs}]},
+ ejabberd_router:route(To, From, jlib:iq_to_xml(Res));
#iq{type = get, xmlns = ?NS_MUC_UNIQUE} = IQ ->
Res = IQ#iq{type = result,
sub_el =
@@ -698,6 +710,19 @@ get_vh_rooms(Host, #rsm_in{max=M, direction=Direction, id=I, index=Index})->
index = NewIndex}}
end.
+get_subscribed_rooms(ServerHost, Host, From) ->
+ Rooms = get_rooms(ServerHost, Host),
+ lists:flatmap(
+ fun(#muc_room{name_host = {Name, _}, opts = Opts}) ->
+ Subscribers = proplists:get_value(subscribers, Opts, []),
+ case lists:keymember(From, 1, Subscribers) of
+ true -> [jid:make(Name, Host, <<>>)];
+ false -> []
+ end;
+ (_) ->
+ []
+ end, Rooms).
+
%% @doc Return the position of desired room in the list of rooms.
%% The room must exist in the list. The count starts in 0.
%% @spec (Desired::muc_online_room(), Rooms::[muc_online_room()]) -> integer()