From 368b2021446c6a069a2f1e772c43160eac2026c9 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Thu, 7 Jul 2016 14:53:15 +0300 Subject: [PATCH] Handle MUC/Sub subscriptions list request --- src/mod_muc.erl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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()