diff --git a/mod_pubsub_serverinfo/src/mod_pubsub_serverinfo.erl b/mod_pubsub_serverinfo/src/mod_pubsub_serverinfo.erl index 78a91697..2bc3d3e2 100644 --- a/mod_pubsub_serverinfo/src/mod_pubsub_serverinfo.erl +++ b/mod_pubsub_serverinfo/src/mod_pubsub_serverinfo.erl @@ -66,13 +66,13 @@ init([Host, _Opts]) -> handle_cast({register_in, Host, LServer, RServer, Pid}, #state{monitors = Mons} = State) -> Ref = monitor(process, Pid), - NewMons = maps:put(Ref, {incoming, {LServer, RServer, false}}, Mons), - check_if_remote_has_support(Host, LServer, RServer, incoming), + HasSupport = check_if_remote_has_support(Host, LServer, RServer, Mons), + NewMons = maps:put(Ref, {incoming, {LServer, RServer, HasSupport}}, Mons), {noreply, State#state{monitors = NewMons}}; handle_cast({register_out, Host, LServer, RServer, Pid}, #state{monitors = Mons} = State) -> Ref = monitor(process, Pid), - NewMons = maps:put(Ref, {outgoing, {LServer, RServer, false}}, Mons), - check_if_remote_has_support(Host, LServer, RServer, outgoing), + HasSupport = check_if_remote_has_support(Host, LServer, RServer, Mons), + NewMons = maps:put(Ref, {outgoing, {LServer, RServer, HasSupport}}, Mons), {noreply, State#state{monitors = NewMons}}; handle_cast(_, State) -> {noreply, State}. @@ -80,7 +80,7 @@ handle_cast(_, State) -> handle_call(_Request, _From, State) -> {noreply, State}. -handle_info({iq_reply, IQReply, {LServer, RServer, Dir, _Pid}}, +handle_info({iq_reply, IQReply, {LServer, RServer}}, #state{monitors = Mons} = State) -> case IQReply of #iq{type = result, sub_els = [El]} -> @@ -88,8 +88,8 @@ handle_info({iq_reply, IQReply, {LServer, RServer, Dir, _Pid}}, #disco_info{features = Features} -> case lists:member(?NS_URN_SERVERINFO, Features) of true -> - Mons2 = maps:fold(fun(Ref, {Dir0, {LServer0, RServer0, _}}, NewMons) - when Dir == Dir0, LServer == LServer0, RServer == RServer0 -> + Mons2 = maps:fold(fun(Ref, {Dir, {LServer0, RServer0, _}}, NewMons) + when LServer == LServer0, RServer == RServer0 -> maps:put(Ref, {Dir, {LServer, RServer, true}}, NewMons); (Ref, Other, NewMons) -> maps:put(Ref, Other, NewMons) @@ -153,12 +153,29 @@ out_auth_result(#{server_host := Host, server := LServer, remote_server := RServ out_auth_result(State, _) -> State. -check_if_remote_has_support(Host, LServer, RServer, Dir) -> - %% [FIXME] No need to do this per direction, either the remote host supports it or not. +check_if_remote_has_support(Host, LServer, RServer, Mons) -> + case has_support(LServer, RServer, Mons) of + true -> + true; + false -> + send_disco_info(Host, LServer, RServer), + false + end. + +has_support(LServer, RServer, Mons) -> + maps:size( + maps:filter( + fun(_Ref, {_Dir, LServer0, RServer0, HasSupport}) + when LServer0 == LServer, RServer0 == RServer -> HasSupport; + (_Ref, _Other) -> false + end, + Mons)) == 0. + +send_disco_info(Host, LServer, RServer) -> Proc = gen_mod:get_module_proc(Host, ?MODULE), IQ = #iq{type = get, from = jid:make(LServer), to = jid:make(RServer), sub_els = [#disco_info{}]}, - ejabberd_router:route_iq(IQ, {LServer, RServer, Dir, self()}, Proc). + ejabberd_router:route_iq(IQ, {LServer, RServer}, Proc). update_pubsub(#state{host = Host, pubsub_host = PubsubHost, node = Node, monitors = Mons}) -> Map = maps:fold(