mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
EJAB-491 fix
SVN Revision: 1145
This commit is contained in:
parent
04eb1c6641
commit
20c27ea9d9
@ -1403,11 +1403,8 @@ process_presence_probe(From, To, StateData) ->
|
||||
deny ->
|
||||
ok;
|
||||
allow ->
|
||||
Caps = case ?DICT:find(jlib:jid_tolower(To), StateData#state.pres_available) of
|
||||
{ok, Value} -> Value;
|
||||
_ -> mod_caps:read_caps(element(4, Packet)) % This is From=To case, so we can read Caps from Packet
|
||||
end,
|
||||
ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Caps]),
|
||||
Pid=element(2, StateData#state.sid),
|
||||
ejabberd_hooks:run(presence_probe_hook, StateData#state.server, [From, To, Pid]),
|
||||
ejabberd_router:route(To, From, Packet)
|
||||
end;
|
||||
Cond2 ->
|
||||
|
@ -396,9 +396,11 @@ disco_sm_items(Acc, _From, To, Node, _Lang) ->
|
||||
%% presence hooks handling functions
|
||||
%%
|
||||
|
||||
presence_probe(#jid{lserver = Host} = From, To, Caps) ->
|
||||
presence_probe(#jid{lserver = Host} = JID, JID, Pid) ->
|
||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
||||
gen_server:cast(Proc, {presence, From, To, Caps}).
|
||||
gen_server:cast(Proc, {presence, JID, Pid});
|
||||
presence_probe(_, _, _) ->
|
||||
ok.
|
||||
|
||||
%% -------
|
||||
%% user remove hook handling function
|
||||
@ -437,23 +439,22 @@ handle_call(stop, _From, State) ->
|
||||
%% Description: Handling cast messages
|
||||
%%--------------------------------------------------------------------
|
||||
%% @private
|
||||
handle_cast({presence, From, To, Caps}, State) ->
|
||||
handle_cast({presence, JID, Pid}, State) ->
|
||||
%% A new resource is available. send last published items
|
||||
LFrom = jlib:jid_tolower(From),
|
||||
LJID = jlib:jid_tolower(JID),
|
||||
Host = State#state.host,
|
||||
ServerHost = State#state.server_host,
|
||||
if From == To ->
|
||||
%% for each node From is subscribed to
|
||||
%% and if the node is so configured, send the last published item to From
|
||||
lists:foreach(fun(Type) ->
|
||||
{result, Subscriptions} = node_action(Type, get_entity_subscriptions, [Host, From]),
|
||||
{result, Subscriptions} = node_action(Type, get_entity_subscriptions, [Host, JID]),
|
||||
lists:foreach(
|
||||
fun({Node, subscribed}) ->
|
||||
case tree_action(Host, get_node, [Host, Node]) of
|
||||
#pubsub_node{options = Options} ->
|
||||
case get_option(Options, send_last_published_item) of
|
||||
on_sub_and_presence ->
|
||||
send_last_item(Host, Node, LFrom);
|
||||
send_last_item(Host, Node, LJID);
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
@ -463,13 +464,16 @@ handle_cast({presence, From, To, Caps}, State) ->
|
||||
(_) ->
|
||||
ok
|
||||
end, Subscriptions)
|
||||
end, State#state.plugins);
|
||||
true ->
|
||||
ok
|
||||
end,
|
||||
%% and send to From last PEP events published by To
|
||||
?DEBUG("got presence probe from ~s to ~s",[jlib:jid_to_string(From),jlib:jid_to_string(To)]),
|
||||
PepKey = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
||||
end, State#state.plugins),
|
||||
%% and send to From last PEP events published by its contacts
|
||||
case catch ejabberd_c2s:get_subscribed_and_online(Pid) of
|
||||
ContactsWithCaps when is_list(ContactsWithCaps) ->
|
||||
Caps = proplists:get_value(LJID, ContactsWithCaps),
|
||||
ContactsUsers = lists:usort(lists:map(
|
||||
fun({{User, Server, _}, _}) -> {User, Server} end, ContactsWithCaps)),
|
||||
lists:foreach(
|
||||
fun({User, Server}) ->
|
||||
PepKey = {User, Server, ""},
|
||||
lists:foreach(fun(#pubsub_node{nodeid = {_, Node}, options = Options}) ->
|
||||
case get_option(Options, send_last_published_item) of
|
||||
on_sub_and_presence ->
|
||||
@ -482,11 +486,11 @@ handle_cast({presence, From, To, Caps}, State) ->
|
||||
authorize -> false; % likewise
|
||||
roster ->
|
||||
Grps = get_option(Options, roster_groups_allowed),
|
||||
element(2, get_roster_info(To#jid.luser, To#jid.lserver, LFrom, Grps))
|
||||
element(2, get_roster_info(User, Server, LJID, Grps))
|
||||
end,
|
||||
if Subscribed ->
|
||||
?DEBUG("send ~s's ~s event to ~s",[jlib:jid_to_string(PepKey),Node,jlib:jid_to_string(From)]),
|
||||
send_last_item(PepKey, Node, LFrom);
|
||||
?DEBUG("send ~s's ~s event to ~s",[jlib:jid_to_string(PepKey),Node,jlib:jid_to_string(LJID)]),
|
||||
send_last_item(PepKey, Node, LJID);
|
||||
true ->
|
||||
ok
|
||||
end;
|
||||
@ -496,7 +500,11 @@ handle_cast({presence, From, To, Caps}, State) ->
|
||||
_ ->
|
||||
ok
|
||||
end
|
||||
end, tree_action(Host, get_nodes, [PepKey])),
|
||||
end, tree_action(Host, get_nodes, [PepKey]))
|
||||
end, ContactsUsers);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
{noreply, State};
|
||||
|
||||
handle_cast({remove, User, Server}, State) ->
|
||||
@ -641,9 +649,6 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
|
||||
_ ->
|
||||
ok
|
||||
end;
|
||||
"presence" ->
|
||||
presence_probe(From, To, Packet),
|
||||
ok;
|
||||
"message" ->
|
||||
case xml:get_attr_s("type", Attrs) of
|
||||
"error" ->
|
||||
|
Loading…
Reference in New Issue
Block a user