From 3d434cfcef3356319f3fdfe94cc34f848ade51c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pawe=C5=82=20Chmielowski?= Date: Mon, 6 May 2019 19:15:48 +0200 Subject: [PATCH] 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. --- src/mod_muc.erl | 14 +++++++++++++- src/mod_muc_room.erl | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) 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; -- 2.50.1