25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-18 17:24:31 +01:00

mod_pubsub: Send notifications on PEP item retract

This commit is contained in:
Holger Weiss 2024-11-30 20:38:33 +01:00
parent 7d0c20e133
commit 344775aa8e

View File

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