From 5a0cfe7e2bab0d42771cf99ddae63b429c78a553 Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 29 Apr 2011 20:30:17 +0200 Subject: [PATCH] Reorganize the push_item function, and handle version not_found (EJAB-1420) --- src/mod_roster.erl | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/mod_roster.erl b/src/mod_roster.erl index f611136da..63162b4d0 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -411,10 +411,17 @@ push_item(User, Server, From, Item) -> % 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, not_found). + +push_item(User, Server, Resource, From, Item, RosterVersion) -> + ExtraAttrs = case RosterVersion of + not_found -> []; + _ -> [{"ver", RosterVersion}] + end, ResIQ = #iq{type = set, xmlns = ?NS_ROSTER, id = "push" ++ randoms:get_string(), sub_el = [{xmlelement, "query", - [{"xmlns", ?NS_ROSTER}], + [{"xmlns", ?NS_ROSTER}|ExtraAttrs], [item_to_xml(Item)]}]}, ejabberd_router:route( From, @@ -425,21 +432,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) -> - IQPush = #iq{type = 'set', xmlns = ?NS_ROSTER, - id = "push" ++ randoms:get_string(), - sub_el = [{xmlelement, "query", - [{"xmlns", ?NS_ROSTER}, - {"ver", RosterVersion}], - [item_to_xml(Item)]}]}, - ejabberd_router:route( - From, - jlib:make_jid(User, Server, Resource), - jlib:iq_to_xml(IQPush)). - get_subscription_lists(_, User, Server) -> LUser = jlib:nodeprep(User), LServer = jlib:nameprep(Server),