aboutsummaryrefslogtreecommitdiff
path: root/src/node_flat.erl
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2021-10-30 13:19:30 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2021-10-30 13:19:30 +0200
commit29dcc9b94ccfd514cf388979e7210d01cb97d5f4 (patch)
tree5ac228d1326501d0d43d4f126710bbd15d58cd54 /src/node_flat.erl
parentUpdate 'xmpp' dependency (diff)
PubSub: Add delete_expired_pubsub_items command
Support XEP-0060's pubsub#item_expire feature by adding a command for deleting expired PubSub items. Thanks to Ammonit Measurement GmbH for sponsoring this work.
Diffstat (limited to 'src/node_flat.erl')
-rw-r--r--src/node_flat.erl18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/node_flat.erl b/src/node_flat.erl
index c597b9ce9..55dea0d8d 100644
--- a/src/node_flat.erl
+++ b/src/node_flat.erl
@@ -40,7 +40,7 @@
create_node_permission/6, create_node/2, delete_node/1,
purge_node/2, subscribe_node/8, unsubscribe_node/4,
publish_item/7, delete_item/4,
- remove_extra_items/2, remove_extra_items/3,
+ remove_extra_items/2, remove_extra_items/3, remove_expired_items/2,
get_entity_affiliations/2, get_node_affiliations/1,
get_affiliation/2, set_affiliation/3,
get_entity_subscriptions/2, get_node_subscriptions/1,
@@ -432,6 +432,22 @@ remove_extra_items(Nidx, MaxItems, ItemIds) ->
del_items(Nidx, OldItems),
{result, {NewItems, OldItems}}.
+remove_expired_items(_Nidx, infinity) ->
+ {result, []};
+remove_expired_items(Nidx, Seconds) ->
+ Items = mnesia:index_read(pubsub_item, Nidx, #pubsub_item.nodeidx),
+ ExpT = misc:usec_to_now(
+ erlang:system_time(microsecond) - (Seconds * 1000000)),
+ ExpItems = lists:filtermap(
+ fun(#pubsub_item{itemid = {ItemId, _},
+ modification = {ModT, _}}) when ModT < ExpT ->
+ {true, ItemId};
+ (#pubsub_item{}) ->
+ false
+ end, Items),
+ del_items(Nidx, ExpItems),
+ {result, ExpItems}.
+
%% @doc <p>Triggers item deletion.</p>
%% <p>Default plugin: The user performing the deletion must be the node owner
%% or a publisher, or PublishModel being open.</p>