prevent sending duplicated last items if several resources online (EJAB-1116)

SVN Revision: 2787
This commit is contained in:
Christophe Romain 2009-12-06 23:21:03 +00:00
parent 40e06b55c0
commit 913684e5a5
3 changed files with 50 additions and 42 deletions

View File

@ -734,6 +734,10 @@ presence_probe(JID, JID, Pid) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:cast(Proc, {presence, JID, Pid}),
gen_server:cast(Proc, {presence, User, Server, [Resource], JID});
presence_probe(#jid{luser = User, lserver = Server}, #jid{luser = User, lserver = Server}, _Pid) ->
%% ignore presence_probe from other ressources for the current user
%% this way, we do not send duplicated last items if user already connected with other clients
ok;
presence_probe(Peer, JID, _Pid) ->
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
Host = exmpp_jid:prep_domain_as_list(JID),

View File

@ -538,6 +538,10 @@ presence_probe(JID, JID, Pid) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:cast(Proc, {presence, JID, Pid}),
gen_server:cast(Proc, {presence, User, Server, [Resource], JID});
presence_probe(#jid{luser = User, lserver = Server}, #jid{luser = User, lserver = Server}, _Pid) ->
%% ignore presence_probe from other ressources for the current user
%% this way, we do not send duplicated last items if user already connected with other clients
ok;
presence_probe(Peer, JID, _Pid) ->
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
Host = exmpp_jid:prep_domain_as_list(JID),
@ -573,7 +577,7 @@ in_subscription(_, _, _, _, _, _) ->
remove_user(User, Server) ->
LUser = exmpp_stringprep:nodeprep(User),
LServer = exmpp_stringprep:nameprep(Server),
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
Proc = gen_mod:get_module_proc(binary_to_list(Server), ?PROCNAME),
gen_server:cast(Proc, {remove_user, LUser, LServer}).
%%--------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2009-11-06 15:30:53.000000000 +0100
+++ mod_pubsub_odbc.erl 2009-11-06 15:31:06.000000000 +0100
--- mod_pubsub.erl 2009-12-07 00:21:33.000000000 +0100
+++ mod_pubsub_odbc.erl 2009-12-07 00:21:40.000000000 +0100
@@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18.
@ -294,7 +294,7 @@
%% TODO, use iq_disco_items(Host, Node, From)
Host = exmpp_jid:prep_domain_as_list(To),
LJID = jlib:short_prepd_bare_jid(To),
@@ -841,10 +645,10 @@
@@ -845,10 +649,10 @@
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
lists:foreach(fun
({Node, subscribed, _, JID}) ->
@ -307,7 +307,7 @@
true ->
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
false ->
@@ -963,11 +767,12 @@
@@ -967,11 +771,12 @@
end,
ejabberd_router:route(To, From, Res);
#iq{type = get, ns = ?NS_DISCO_ITEMS,
@ -322,7 +322,7 @@
{result, IQRes} ->
Result = #xmlel{ns = ?NS_DISCO_ITEMS,
name = 'query', attrs = QAttrs,
@@ -1085,7 +890,7 @@
@@ -1089,7 +894,7 @@
[] ->
["leaf"]; %% No sub-nodes: it's a leaf node
_ ->
@ -331,7 +331,7 @@
{result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"];
_ -> []
@@ -1101,8 +906,9 @@
@@ -1105,8 +910,9 @@
[];
true ->
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
@ -343,7 +343,7 @@
end, features(Type))]
end,
%% TODO: add meta-data info (spec section 5.4)
@@ -1131,8 +937,9 @@
@@ -1135,8 +941,9 @@
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
@ -355,7 +355,7 @@
end, features(Host, Node))};
?NS_ADHOC_b ->
command_disco_info(Host, Node, From);
@@ -1142,7 +949,7 @@
@@ -1146,7 +953,7 @@
node_disco_info(Host, Node, From)
end.
@ -364,7 +364,7 @@
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
@@ -1155,7 +962,7 @@
@@ -1159,7 +966,7 @@
Other ->
Other
end;
@ -373,7 +373,7 @@
%% TODO: support localization of this string
CommandItems = [
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
@@ -1164,10 +971,10 @@
@@ -1168,10 +975,10 @@
?XMLATTR('name', "Get Pending")
]}],
{result, CommandItems};
@ -386,7 +386,7 @@
case string:tokens(Item, "!") of
[_SNode, _ItemID] ->
{result, []};
@@ -1175,10 +982,10 @@
@@ -1179,10 +986,10 @@
Node = string_to_node(SNode),
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -400,7 +400,7 @@
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
@@ -1189,9 +996,10 @@
@@ -1193,9 +1000,10 @@
Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
@ -413,7 +413,7 @@
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result};
@@ -1322,7 +1130,8 @@
@@ -1326,7 +1134,8 @@
(_, Acc) ->
Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -423,7 +423,7 @@
{get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} ->
@@ -1344,8 +1153,9 @@
@@ -1348,8 +1157,9 @@
end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
@ -435,7 +435,7 @@
case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
@@ -1479,7 +1289,8 @@
@@ -1483,7 +1293,8 @@
_ -> []
end
end,
@ -445,7 +445,7 @@
sync_dirty) of
{result, Res} -> Res;
Err -> Err
@@ -1523,7 +1334,7 @@
@@ -1527,7 +1338,7 @@
%%% authorization handling
@ -454,7 +454,7 @@
Lang = "en", %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
@@ -1553,7 +1364,7 @@
@@ -1557,7 +1368,7 @@
lists:foreach(fun(Owner) ->
{U, S, R} = Owner,
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
@ -463,7 +463,7 @@
find_authorization_response(Packet) ->
Els = Packet#xmlel.children,
@@ -1595,7 +1406,7 @@
@@ -1599,7 +1410,7 @@
end,
Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
@ -472,7 +472,7 @@
}]),
ejabberd_router:route(service_jid(Host), JID, Stanza).
@@ -1606,14 +1417,14 @@
@@ -1610,14 +1421,14 @@
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
{value, {_, [SAllow]}}} ->
Node = string_to_node(SNode),
@ -490,7 +490,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if
not IsApprover ->
@@ -1808,7 +1619,7 @@
@@ -1812,7 +1623,7 @@
end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
@ -499,7 +499,7 @@
{result, {Result, broadcast}} ->
%%Lang = "en", %% TODO: fix
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
@@ -1917,7 +1728,7 @@
@@ -1921,7 +1732,7 @@
%%<li>The node does not exist.</li>
%%</ul>
subscribe_node(Host, Node, From, JID, Configuration) ->
@ -508,7 +508,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -1928,7 +1739,7 @@
@@ -1932,7 +1743,7 @@
{undefined, undefined, undefined}
end,
SubId = uniqid(),
@ -517,7 +517,7 @@
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@@ -1947,9 +1758,13 @@
@@ -1951,9 +1762,13 @@
{"", "", ""} ->
{false, false};
_ ->
@ -534,7 +534,7 @@
end
end,
if
@@ -2282,7 +2097,7 @@
@@ -2286,7 +2101,7 @@
%% <p>The permission are not checked in this function.</p>
%% @todo We probably need to check that the user doing the query has the right
%% to read the items.
@ -543,7 +543,7 @@
MaxItems =
if
SMaxItems == "" -> get_max_items_node(Host);
@@ -2321,11 +2136,11 @@
@@ -2325,11 +2140,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
@ -557,7 +557,7 @@
SendItems = case ItemIDs of
[] ->
Items;
@@ -2338,7 +2153,7 @@
@@ -2342,7 +2157,7 @@
%% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -566,7 +566,7 @@
Error ->
Error
end
@@ -2370,17 +2185,29 @@
@@ -2374,17 +2189,29 @@
%% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -603,7 +603,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2509,29 +2336,12 @@
@@ -2513,29 +2340,12 @@
error ->
{error, 'bad-request'};
_ ->
@ -636,7 +636,7 @@
end, Entities),
{result, []};
_ ->
@@ -2586,11 +2396,11 @@
@@ -2590,11 +2400,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -650,7 +650,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('Subid', SubID) | nodeAttr(Node)],
@@ -2617,7 +2427,7 @@
@@ -2621,7 +2431,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -659,7 +659,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2647,7 +2457,7 @@
@@ -2651,7 +2461,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
@ -668,7 +668,7 @@
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@@ -2820,8 +2630,8 @@
@@ -2824,8 +2634,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router:route(service_jid(Host), JID, Stanza)
end,
@ -679,7 +679,7 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3110,7 +2920,7 @@
@@ -3114,7 +2924,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
@ -688,7 +688,7 @@
{result, CollSubs} -> CollSubs;
_ -> []
end.
@@ -3124,9 +2934,9 @@
@@ -3128,9 +2938,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -700,7 +700,7 @@
_ -> Acc
end;
(_, Acc) ->
@@ -3134,7 +2944,7 @@
@@ -3138,7 +2948,7 @@
end, [], Subs).
% TODO: merge broadcast code that way
@ -709,7 +709,7 @@
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
% case (get_option(NodeOptions, Feature) or Force) of
% true ->
@@ -3326,6 +3136,30 @@
@@ -3330,6 +3140,30 @@
Result
end.
@ -740,7 +740,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3715,7 +3549,13 @@
@@ -3719,7 +3553,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -755,7 +755,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3735,13 +3575,13 @@
@@ -3739,13 +3579,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -771,7 +771,7 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3754,8 +3594,15 @@
@@ -3758,8 +3598,15 @@
end
end, Trans).
@ -789,7 +789,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3763,6 +3610,15 @@
@@ -3767,6 +3614,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'};
@ -805,7 +805,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'};
@@ -3771,6 +3627,16 @@
@@ -3775,6 +3631,16 @@
{error, 'internal-server-error'}
end.