From: Paweł Chmielowski Date: Mon, 6 May 2019 17:15:48 +0000 (+0200) Subject: Handle get_subscribed_rooms call from mod_muc_room pid X-Git-Tag: 19.05~29^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3d434cfcef3356319f3fdfe94cc34f848ade51c4;p=ejabberd Handle get_subscribed_rooms call from mod_muc_room pid 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. --- diff --git a/src/mod_muc.erl b/src/mod_muc.erl index 76fce1f8e..edc570eed 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -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} -> diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index f972a5feb..94c430197 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -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;