]> granicus.if.org Git - ejabberd/commitdiff
In response with list of room subscriptions include also events (#2272)
authorBadlop <badlop@process-one.net>
Fri, 10 Aug 2018 15:46:47 +0000 (17:46 +0200)
committerBadlop <badlop@process-one.net>
Mon, 13 Aug 2018 10:52:33 +0000 (12:52 +0200)
rebar.config
src/mod_muc.erl
src/mod_muc_room.erl
src/mod_muc_sql.erl

index d45af48b1c874298423821f6ad5d231f2400db96..e764824662d7c5e6fc5ca982be66eb962ef5f0e8 100644 (file)
@@ -25,7 +25,7 @@
         {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.23"}}},
         {stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.12"}}},
         {fast_xml, ".*", {git, "https://github.com/processone/fast_xml", {tag, "1.1.32"}}},
-        {xmpp, ".*", {git, "https://github.com/processone/xmpp", "8bf26b9e208bd0059cd8fd4e6593d88548c136cf"}},
+        {xmpp, ".*", {git, "https://github.com/processone/xmpp", "305e9c3"}},
         {fast_yaml, ".*", {git, "https://github.com/processone/fast_yaml", {tag, "1.0.15"}}},
         {jiffy, ".*", {git, "https://github.com/davisp/jiffy", {tag, "0.14.8"}}},
         {p1_oauth2, ".*", {git, "https://github.com/processone/p1_oauth2", {tag, "0.6.3"}}},
index 6b53e38d962a68d5d8ad5a03d4bb6977d41d40b9..3024400ac1cd9e3dc00b4769cdc7d77446855239 100644 (file)
 -callback unregister_online_user(binary(), ljid(), binary(), binary()) -> any().
 -callback count_online_rooms_by_user(binary(), binary(), binary()) -> non_neg_integer().
 -callback get_online_rooms_by_user(binary(), binary(), binary()) -> [{binary(), binary()}].
--callback get_subscribed_rooms(binary(), binary(), jid()) -> [ljid()] | [].
+-callback get_subscribed_rooms(binary(), binary(), jid()) -> [{ljid(), [binary()]}] | [].
 
 %%====================================================================
 %% API
@@ -614,8 +614,8 @@ process_mucsub(#iq{type = get, from = From, to = To,
                   sub_els = [#muc_subscriptions{}]} = IQ) ->
     Host = To#jid.lserver,
     ServerHost = ejabberd_router:host_of_route(Host),
-    RoomJIDs = get_subscribed_rooms(ServerHost, Host, From),
-    xmpp:make_iq_result(IQ, #muc_subscriptions{list = RoomJIDs});
+    Subs = get_subscribed_rooms(ServerHost, Host, From),
+    xmpp:make_iq_result(IQ, #muc_subscriptions{list = Subs});
 process_mucsub(#iq{lang = Lang} = IQ) ->
     Txt = <<"No module is handling this query">>,
     xmpp:make_error(IQ, xmpp:err_service_unavailable(Txt, Lang)).
@@ -745,14 +745,15 @@ get_subscribed_rooms(ServerHost, Host, From) ->
            lists:flatmap(
              fun({Name, _, Pid}) ->
                      case p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of
-                         true -> [jid:make(Name, Host)];
+                         {true, Nodes} ->
+                               [#muc_subscription{jid = jid:make(Name, Host), events = Nodes}];
                          false -> []
                      end;
                 (_) ->
                      []
              end, Rooms);
        V ->
-           V
+           [#muc_subscription{jid = Jid, events = Nodes} || {Jid, Nodes} <- V]
     end.
 
 get_nick(ServerHost, Host, From) ->
index 33c58e416fda58cb43a50bda9816af5595d421d8..88bf4f099e692f6aea20010d5689024ef565169b 100644 (file)
@@ -586,7 +586,12 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName, StateData) ->
            {reply, {error, get_error_text(Err)}, StateName, StateData}
     end;
 handle_sync_event({is_subscribed, From}, _From, StateName, StateData) ->
-    IsSubs = ?DICT:is_key(jid:split(From), StateData#state.subscribers),
+    IsSubs = case (?DICT):find(jid:split(From), StateData#state.subscribers) of
+       {ok, #subscriber{nodes = Nodes}} ->
+           {true, Nodes};
+       error ->
+           false
+    end,
     {reply, IsSubs, StateName, StateData};
 handle_sync_event(_Event, _From, StateName,
                  StateData) ->
@@ -4090,11 +4095,11 @@ process_iq_mucsub(From, #iq{type = get, lang = Lang,
     FAffiliation = get_affiliation(From, StateData),
     FRole = get_role(From, StateData),
     if FRole == moderator; FAffiliation == owner; FAffiliation == admin ->
-           JIDs = dict:fold(
-                    fun(_, #subscriber{jid = J}, Acc) ->
-                            [J|Acc]
+           Subs = dict:fold(
+                    fun(_, #subscriber{jid = J, nodes = Nodes}, Acc) ->
+                            [#muc_subscription{jid = J, events = Nodes}|Acc]
                     end, [], StateData#state.subscribers),
-           {result, #muc_subscriptions{list = JIDs}, StateData};
+           {result, #muc_subscriptions{list = Subs}, StateData};
        true ->
            Txt = <<"Moderator privileges required">>,
            {error, xmpp:err_forbidden(Txt, Lang)}
index d078b64f152e0e4f97657ecc37974ca74d1249f2..e92b4bc5445269fe01725cc5c9ac35446aa377e9 100644 (file)
@@ -411,10 +411,10 @@ get_subscribed_rooms(LServer, Host, Jid) ->
     JidS = jid:encode(Jid),
     case catch ejabberd_sql:sql_query(
        LServer,
-       ?SQL("select @(room)s from muc_room_subscribers where jid=%(JidS)s"
+       ?SQL("select @(room)s, @(nodes)s from muc_room_subscribers where jid=%(JidS)s"
             " and host=%(Host)s")) of
        {selected, Subs} ->
-           [jid:make(Room, Host, <<>>) || {Room} <- Subs];
+           [{jid:make(Room, Host, <<>>), ejabberd_sql:decode_term(Nodes)} || {Room, Nodes} <- Subs];
        _Error ->
            []
     end.