diff options
author | Pouriya <pouriya.jahanbakhsh@gmail.com> | 2021-09-18 16:09:11 +0430 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-18 16:09:11 +0430 |
commit | 3eb795357ff2278fa641608f442c9800d74c9c0a (patch) | |
tree | 9592f786ad76e91b442fcf9a83cdd609ede3a9c2 /src/node_flat.erl | |
parent | ref: fix WS typos (diff) | |
parent | Fix previous commit: add forgotten endline blankspaces (diff) |
Merge branch 'processone:master' into master
Diffstat (limited to 'src/node_flat.erl')
-rw-r--r-- | src/node_flat.erl | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/node_flat.erl b/src/node_flat.erl index 4a2a60971..c597b9ce9 100644 --- a/src/node_flat.erl +++ b/src/node_flat.erl @@ -39,7 +39,8 @@ -export([init/3, terminate/2, options/0, features/0, 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/3, + publish_item/7, delete_item/4, + remove_extra_items/2, remove_extra_items/3, get_entity_affiliations/2, get_node_affiliations/1, get_affiliation/2, set_affiliation/3, get_entity_subscriptions/2, get_node_subscriptions/1, @@ -375,7 +376,8 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload, or (Subscribed == true)) -> {error, xmpp:err_forbidden()}; true -> - if MaxItems > 0 -> + if MaxItems > 0; + MaxItems == unlimited -> Now = erlang:timestamp(), case get_item(Nidx, ItemId) of {result, #pubsub_item{creation = {_, GenKey}} = OldItem} -> @@ -402,6 +404,16 @@ publish_item(Nidx, Publisher, PublishModel, MaxItems, ItemId, Payload, end end. +remove_extra_items(Nidx, MaxItems) -> + {result, States} = get_states(Nidx), + Records = States ++ mnesia:read({pubsub_orphan, Nidx}), + ItemIds = lists:flatmap(fun(#pubsub_state{items = Is}) -> + Is; + (#pubsub_orphan{items = Is}) -> + Is + end, Records), + remove_extra_items(Nidx, MaxItems, ItemIds). + %% @doc <p>This function is used to remove extra items, most notably when the %% maximum number of items has been reached.</p> %% <p>This function is used internally by the core PubSub module, as no @@ -945,15 +957,12 @@ rsm_page(Count, Index, Offset, Items) -> last = Last}. encode_stamp(Stamp) -> - case catch xmpp_util:decode_timestamp(Stamp) of - {MS,S,US} -> {MS,S,US}; - _ -> Stamp + try xmpp_util:decode_timestamp(Stamp) + catch _:{bad_timestamp, _} -> + Stamp % We should return a proper error to the client instead. end. decode_stamp(Stamp) -> - case catch xmpp_util:encode_timestamp(Stamp) of - TimeStamp when is_binary(TimeStamp) -> TimeStamp; - _ -> Stamp - end. + xmpp_util:encode_timestamp(Stamp). transform({pubsub_state, {Id, Nidx}, Is, A, Ss}) -> {pubsub_state, {Id, Nidx}, Nidx, Is, A, Ss}; |