]> granicus.if.org Git - ejabberd/commitdiff
Handle get_subscribed_rooms call from mod_muc_room pid
authorPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 6 May 2019 17:15:48 +0000 (19:15 +0200)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Mon, 6 May 2019 17:15:48 +0000 (19:15 +0200)
Previously sometimes we tried to post message to all online rooms, and
if that was called from muc room pid, we were not able to process that
message for that room and send response, and this did lead to timeout.

src/mod_muc.erl
src/mod_muc_room.erl

index 76fce1f8eea16addba0deaf4dfa424054b2cf6ee..edc570eedd563d76a3892f561a74948ebde4248b 100644 (file)
@@ -758,6 +758,10 @@ get_subscribed_rooms(Host, User) ->
     ServerHost = ejabberd_router:host_of_route(Host),
     get_subscribed_rooms(ServerHost, Host, User).
 
+-record(subscriber, {jid :: jid(),
+                    nick = <<>> :: binary(),
+                    nodes = [] :: [binary()]}).
+
 -spec get_subscribed_rooms(binary(), binary(), jid()) ->
                           {ok, [{jid(), [binary()]}]} | {error, any()}.
 get_subscribed_rooms(ServerHost, Host, From) ->
@@ -768,7 +772,15 @@ get_subscribed_rooms(ServerHost, Host, From) ->
        false ->
            Rooms = get_online_rooms(ServerHost, Host),
            {ok, lists:flatmap(
-                  fun({Name, _, Pid}) ->
+                  fun({Name, _, Pid}) when Pid == self() ->
+                      USR = jid:split(BareFrom),
+                      case erlang:get(muc_subscribers) of
+                          #{USR := #subscriber{nodes = Nodes}} ->
+                              [{jid:make(Name, Host), Nodes}];
+                          _ ->
+                              []
+                      end;
+                      ({Name, _, Pid}) ->
                           case p1_fsm:sync_send_all_state_event(
                                  Pid, {is_subscribed, BareFrom}) of
                               {true, Nodes} ->
index f972a5feb03a31c8c2568d2e64416f70c1919acf..94c4301972cf67ad2cab2a59232a0e53f0f3bba4 100644 (file)
@@ -538,6 +538,7 @@ handle_sync_event({change_config, Config}, _From,
     {reply, {ok, NSD#state.config}, StateName, NSD};
 handle_sync_event({change_state, NewStateData}, _From,
                  StateName, _StateData) ->
+    erlang:put(muc_subscribers, NewStateData#state.subscribers),
     {reply, {ok, NewStateData}, StateName, NewStateData};
 handle_sync_event({process_item_change, Item, UJID}, _From, StateName, StateData) ->
     case process_item_change(Item, StateData, UJID) of
@@ -4373,6 +4374,7 @@ store_room(StateData) ->
     store_room(StateData, []).
 store_room(StateData, ChangesHints) ->
     % Let store persistent rooms or on those backends that have get_subscribed_rooms
+    erlang:put(muc_subscribers, StateData#state.subscribers),
     ShouldStore = case (StateData#state.config)#config.persistent of
                      true ->
                          true;