From b8026d8df7c3b43aaaacf9a4ee6ec7a661d4a6de Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 29 Apr 2011 20:28:35 +0200 Subject: [PATCH] Reorganize the push_item function, and handle version not_found (EJAB-1420) --- src/mod_roster.erl | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/mod_roster.erl b/src/mod_roster.erl index 6e6a0ca43..02a6bfc71 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -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()