diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index 2bf1d350f..767d10215 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -596,7 +596,7 @@ on_self_presence(Acc) -> -spec on_user_offline(ejabberd_c2s:state(), atom()) -> ejabberd_c2s:state(). on_user_offline(#{jid := JID} = C2SState, _Reason) -> - purge_offline(jid:tolower(JID)), + purge_offline(JID), C2SState; on_user_offline(C2SState, _Reason) -> C2SState. @@ -1897,14 +1897,14 @@ publish_item(Host, ServerHost, Node, Publisher, ItemId, Payload, PubOpts, Access Nidx = TNode#pubsub_node.id, Type = TNode#pubsub_node.type, Options = TNode#pubsub_node.options, - broadcast_retract_items(Host, Node, Nidx, Type, Options, Removed), + broadcast_retract_items(Host, Publisher, Node, Nidx, Type, Options, Removed), set_cached_item(Host, Nidx, ItemId, Publisher, Payload), {result, Reply}; {result, {TNode, {Result, Removed}}} -> Nidx = TNode#pubsub_node.id, Type = TNode#pubsub_node.type, Options = TNode#pubsub_node.options, - broadcast_retract_items(Host, Node, Nidx, Type, Options, Removed), + broadcast_retract_items(Host, Publisher, Node, Nidx, Type, Options, Removed), set_cached_item(Host, Nidx, ItemId, Publisher, Payload), {result, Result}; {result, {_, default}} -> @@ -1975,7 +1975,7 @@ delete_item(Host, Node, Publisher, ItemId, ForceNotify) -> ServerHost = serverhost(Host), ejabberd_hooks:run(pubsub_delete_item, ServerHost, [ServerHost, Node, Publisher, service_jid(Host), ItemId]), - broadcast_retract_items(Host, Node, Nidx, Type, Options, [ItemId], ForceNotify), + broadcast_retract_items(Host, Publisher, Node, Nidx, Type, Options, [ItemId], ForceNotify), case get_cached_item(Host, Nidx) of #pubsub_item{itemid = {ItemId, Nidx}} -> unset_cached_item(Host, Nidx); _ -> ok @@ -2834,16 +2834,16 @@ broadcast_publish_item(Host, Node, Nidx, Type, NodeOptions, ItemId, From, Payloa {result, false} end. --spec broadcast_retract_items(host(), binary(), nodeIdx(), binary(), +-spec broadcast_retract_items(host(), jid(), binary(), nodeIdx(), binary(), nodeOptions(), [itemId()]) -> {result, boolean()}. -broadcast_retract_items(Host, Node, Nidx, Type, NodeOptions, ItemIds) -> - broadcast_retract_items(Host, Node, Nidx, Type, NodeOptions, ItemIds, false). +broadcast_retract_items(Host, Publisher, Node, Nidx, Type, NodeOptions, ItemIds) -> + broadcast_retract_items(Host, Publisher, Node, Nidx, Type, NodeOptions, ItemIds, false). --spec broadcast_retract_items(host(), binary(), nodeIdx(), binary(), +-spec broadcast_retract_items(host(), jid(), binary(), nodeIdx(), binary(), nodeOptions(), [itemId()], boolean()) -> {result, boolean()}. -broadcast_retract_items(_Host, _Node, _Nidx, _Type, _NodeOptions, [], _ForceNotify) -> +broadcast_retract_items(_Host, _Publisher, _Node, _Nidx, _Type, _NodeOptions, [], _ForceNotify) -> {result, false}; -broadcast_retract_items(Host, Node, Nidx, Type, NodeOptions, ItemIds, ForceNotify) -> +broadcast_retract_items(Host, Publisher, Node, Nidx, Type, NodeOptions, ItemIds, ForceNotify) -> case (get_option(NodeOptions, notify_retract) or ForceNotify) of true -> case get_collection_subscriptions(Host, Node) of @@ -2854,7 +2854,7 @@ broadcast_retract_items(Host, Node, Nidx, Type, NodeOptions, ItemIds, ForceNotif items = #ps_items{ node = Node, retract = ItemIds}}]}, - broadcast_stanza(Host, Node, Nidx, Type, + broadcast_stanza(Host, Publisher, Node, Nidx, Type, NodeOptions, SubsByDepth, items, Stanza, true), {result, true}; _ -> @@ -4100,9 +4100,8 @@ subid_shim(SubIds) -> extended_headers(Jids) -> [#address{type = replyto, jid = Jid} || Jid <- Jids]. --spec purge_offline(ljid()) -> ok. -purge_offline(LJID) -> - Host = host(element(2, LJID)), +-spec purge_offline(jid()) -> ok. +purge_offline(#jid{lserver = Host} = JID) -> Plugins = plugins(Host), Result = lists:foldl( fun(Type, {Status, Acc}) -> @@ -4117,7 +4116,7 @@ purge_offline(LJID) -> andalso lists:member(<<"persistent-items">>, Features), if Items -> case node_action(Host, Type, - get_entity_affiliations, [Host, LJID]) of + get_entity_affiliations, [Host, JID]) of {result, Affs} -> {Status, [Affs | Acc]}; {error, _} = Err -> @@ -4138,7 +4137,7 @@ purge_offline(LJID) -> Purge = (get_option(Options, purge_offline) andalso get_option(Options, persist_items)), if (Publisher or Open) and Purge -> - purge_offline(Host, LJID, Node); + purge_offline(Host, JID, Node); true -> ok end @@ -4147,8 +4146,8 @@ purge_offline(LJID) -> ok end. --spec purge_offline(host(), ljid(), #pubsub_node{}) -> ok | {error, stanza_error()}. -purge_offline(Host, LJID, Node) -> +-spec purge_offline(host(), jid(), #pubsub_node{}) -> ok | {error, stanza_error()}. +purge_offline(Host, #jid{luser = User, lserver = Server, lresource = Resource} = JID, Node) -> Nidx = Node#pubsub_node.id, Type = Node#pubsub_node.type, Options = Node#pubsub_node.options, @@ -4156,7 +4155,6 @@ purge_offline(Host, LJID, Node) -> {result, {[], _}} -> ok; {result, {Items, _}} -> - {User, Server, Resource} = LJID, PublishModel = get_option(Options, publish_model), ForceNotify = get_option(Options, notify_retract), {_, NodeId} = Node#pubsub_node.nodeid, @@ -4165,7 +4163,7 @@ purge_offline(Host, LJID, Node) -> when (U == User) and (S == Server) and (R == Resource) -> case node_action(Host, Type, delete_item, [Nidx, {U, S, <<>>}, PublishModel, ItemId]) of {result, {_, broadcast}} -> - broadcast_retract_items(Host, NodeId, Nidx, Type, Options, [ItemId], ForceNotify), + broadcast_retract_items(Host, JID, NodeId, Nidx, Type, Options, [ItemId], ForceNotify), case get_cached_item(Host, Nidx) of #pubsub_item{itemid = {ItemId, Nidx}} -> unset_cached_item(Host, Nidx); _ -> ok