mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Avoid late arrival of get_disco_item response
This commit is contained in:
parent
4b6f1195c6
commit
3d8711f708
@ -740,17 +740,21 @@ iq_disco_items(_ServerHost, _Host, _From, Lang, _MaxRoomsDiscoItems, _Node, _RSM
|
|||||||
-spec get_room_disco_item({binary(), binary(), pid()},
|
-spec get_room_disco_item({binary(), binary(), pid()},
|
||||||
term()) -> {ok, disco_item()} |
|
term()) -> {ok, disco_item()} |
|
||||||
{error, timeout | notfound}.
|
{error, timeout | notfound}.
|
||||||
get_room_disco_item({Name, Host, Pid}, Query) ->
|
get_room_disco_item({Name, Host, Pid},
|
||||||
RoomJID = jid:make(Name, Host),
|
{get_disco_item, Filter, JID, Lang}) ->
|
||||||
try p1_fsm:sync_send_all_state_event(Pid, Query, 100) of
|
RoomJID = jid:make(Name, Host),
|
||||||
{item, Desc} ->
|
Timeout = 100,
|
||||||
{ok, #disco_item{jid = RoomJID, name = Desc}};
|
Time = erlang:monotonic_time(millisecond),
|
||||||
false ->
|
Query1 = {get_disco_item, Filter, JID, Lang, Time+Timeout},
|
||||||
{error, notfound}
|
try p1_fsm:sync_send_all_state_event(Pid, Query1, Timeout) of
|
||||||
catch _:{timeout, {p1_fsm, _, _}} ->
|
{item, Desc} ->
|
||||||
{error, timeout};
|
{ok, #disco_item{jid = RoomJID, name = Desc}};
|
||||||
_:{_, {p1_fsm, _, _}} ->
|
false ->
|
||||||
{error, notfound}
|
{error, notfound}
|
||||||
|
catch _:{timeout, {p1_fsm, _, _}} ->
|
||||||
|
{error, timeout};
|
||||||
|
_:{_, {p1_fsm, _, _}} ->
|
||||||
|
{error, notfound}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec get_subscribed_rooms(binary(), jid()) -> {ok, [{jid(), [binary()]}]} | {error, any()}.
|
-spec get_subscribed_rooms(binary(), jid()) -> {ok, [{jid(), [binary()]}]} | {error, any()}.
|
||||||
|
@ -512,7 +512,7 @@ handle_event({set_affiliations, Affiliations},
|
|||||||
handle_event(_Event, StateName, StateData) ->
|
handle_event(_Event, StateName, StateData) ->
|
||||||
{next_state, StateName, StateData}.
|
{next_state, StateName, StateData}.
|
||||||
|
|
||||||
handle_sync_event({get_disco_item, Filter, JID, Lang}, _From, StateName, StateData) ->
|
handle_sync_event({get_disco_item, Filter, JID, Lang, Time}, _From, StateName, StateData) ->
|
||||||
Len = maps:size(StateData#state.nicks),
|
Len = maps:size(StateData#state.nicks),
|
||||||
Reply = case (Filter == all) or (Filter == Len) or ((Filter /= 0) and (Len /= 0)) of
|
Reply = case (Filter == all) or (Filter == Len) or ((Filter /= 0) and (Len /= 0)) of
|
||||||
true ->
|
true ->
|
||||||
@ -521,10 +521,17 @@ handle_sync_event({get_disco_item, Filter, JID, Lang}, _From, StateName, StateDa
|
|||||||
false ->
|
false ->
|
||||||
false
|
false
|
||||||
end,
|
end,
|
||||||
{reply, Reply, StateName, StateData};
|
CurrentTime = erlang:monotonic_time(millisecond),
|
||||||
%% This clause is only for backwards compatibility
|
if CurrentTime < Time ->
|
||||||
|
{reply, Reply, StateName, StateData};
|
||||||
|
true ->
|
||||||
|
{next_state, StateName, StateData}
|
||||||
|
end;
|
||||||
|
%% These two clauses are only for backward compatibility with nodes running old code
|
||||||
handle_sync_event({get_disco_item, JID, Lang}, From, StateName, StateData) ->
|
handle_sync_event({get_disco_item, JID, Lang}, From, StateName, StateData) ->
|
||||||
handle_sync_event({get_disco_item, any, JID, Lang}, From, StateName, StateData);
|
handle_sync_event({get_disco_item, any, JID, Lang}, From, StateName, StateData);
|
||||||
|
handle_sync_event({get_disco_item, Filter, JID, Lang}, From, StateName, StateData) ->
|
||||||
|
handle_sync_event({get_disco_item, Filter, JID, Lang, infinity}, From, StateName, StateData);
|
||||||
handle_sync_event(get_config, _From, StateName,
|
handle_sync_event(get_config, _From, StateName,
|
||||||
StateData) ->
|
StateData) ->
|
||||||
{reply, {ok, StateData#state.config}, StateName,
|
{reply, {ok, StateData#state.config}, StateName,
|
||||||
|
Loading…
Reference in New Issue
Block a user