25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Reorganize the push_item function, and handle version not_found (EJAB-1420)

This commit is contained in:
Badlop 2011-04-29 20:28:35 +02:00
parent c611361bbe
commit b8026d8df7

View File

@ -657,10 +657,18 @@ push_item(User, Server, From, Item)
%% Item = rosteritem()
% TODO: don't push to those who didn't load roster
push_item(User, Server, Resource, From, Item)
push_item(User, Server, Resource, From, Item) ->
push_item(User, Server, Resource, From, Item, not_found).
push_item(User, Server, Resource, From, Item, RosterVersion)
when is_binary(User), is_binary(Server), is_binary(Resource),
?IS_JID(From) ->
ExtraAttrs = case RosterVersion of
not_found -> [];
_ -> [?XMLATTR(<<"ver">>, RosterVersion)]
end,
Request = #xmlel{ns = ?NS_ROSTER, name = 'query',
attrs = ExtraAttrs,
children = [item_to_xml(Item)]},
ResIQ = exmpp_iq:set(?NS_JABBER_CLIENT, Request,
"push" ++ randoms:get_string()),
@ -673,19 +681,9 @@ push_item(User, Server, Resource, From, Item)
%% TODO: don't push to those who didn't load roster
push_item_version(Server, User, From, Item, RosterVersion) ->
lists:foreach(fun(Resource) ->
push_item_version(User, Server, Resource, From, Item, RosterVersion)
push_item(User, Server, Resource, From, Item, RosterVersion)
end, ejabberd_sm:get_user_resources(User, Server)).
push_item_version(User, Server, Resource, From, Item, RosterVersion) ->
Request = #xmlel{ns = ?NS_ROSTER, name = 'query', attrs = [?XMLATTR(<<"ver">>, RosterVersion)],
children = [mod_roster:item_to_xml(Item)]},
ResIQ = exmpp_iq:set(?NS_JABBER_CLIENT, Request,
"push" ++ randoms:get_string()),
ejabberd_router:route(
From,
exmpp_jid:make(User, Server, Resource),
ResIQ).
%% @spec (Ignored, User, Server) -> Subscription_Lists
%% Ignored = term()
%% User = binary()