mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Improve pubsub#itemreply implementation (#2325)
This commit is contained in:
parent
7627575856
commit
d28064518b
@ -1704,7 +1704,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
|
|||||||
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,
|
||||||
send_items(Host, Node, Nidx, Type, Options, Subscriber, 1),
|
send_items(Host, Node, Nidx, Type, Options, Subscriber, last),
|
||||||
ServerHost = serverhost(Host),
|
ServerHost = serverhost(Host),
|
||||||
ejabberd_hooks:run(pubsub_subscribe_node, ServerHost,
|
ejabberd_hooks:run(pubsub_subscribe_node, ServerHost,
|
||||||
[ServerHost, Host, Node, Subscriber, SubId]),
|
[ServerHost, Host, Node, Subscriber, SubId]),
|
||||||
@ -2018,7 +2018,7 @@ get_items(Host, Node, From, SubId, _MaxItems, ItemIds, RSM) ->
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
case transaction(Host, Node, Action, sync_dirty) of
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
{result, {_, {Items, RsmOut}}} ->
|
{result, {TNode, {Items, RsmOut}}} ->
|
||||||
SendItems = case ItemIds of
|
SendItems = case ItemIds of
|
||||||
[] ->
|
[] ->
|
||||||
Items;
|
Items;
|
||||||
@ -2028,14 +2028,12 @@ get_items(Host, Node, From, SubId, _MaxItems, ItemIds, RSM) ->
|
|||||||
lists:member(ItemId, ItemIds)
|
lists:member(ItemId, ItemIds)
|
||||||
end, Items)
|
end, Items)
|
||||||
end,
|
end,
|
||||||
{result,
|
Options = TNode#pubsub_node.options,
|
||||||
#pubsub{items = #ps_items{node = Node,
|
{result, #pubsub{items = items_els(Node, Options, SendItems),
|
||||||
items = itemsEls(SendItems)},
|
rsm = RsmOut}};
|
||||||
rsm = RsmOut}};
|
{result, {TNode, Item}} ->
|
||||||
{result, {_, Item}} ->
|
Options = TNode#pubsub_node.options,
|
||||||
{result,
|
{result, #pubsub{items = items_els(Node, Options, [Item])}};
|
||||||
#pubsub{items = #ps_items{node = Node,
|
|
||||||
items = itemsEls([Item])}}};
|
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
@ -2069,6 +2067,9 @@ get_allowed_items_call(Host, Nidx, From, Type, Options, Owners, RSM) ->
|
|||||||
{PS, RG} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
{PS, RG} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
node_call(Host, Type, get_items, [Nidx, From, AccessModel, PS, RG, undefined, RSM]).
|
node_call(Host, Type, get_items, [Nidx, From, AccessModel, PS, RG, undefined, RSM]).
|
||||||
|
|
||||||
|
get_last_items(Host, Type, Nidx, LJID, last) ->
|
||||||
|
% hack to handle section 6.1.7 of XEP-0060
|
||||||
|
get_last_items(Host, Type, Nidx, LJID, 1);
|
||||||
get_last_items(Host, Type, Nidx, LJID, 1) ->
|
get_last_items(Host, Type, Nidx, LJID, 1) ->
|
||||||
case get_cached_item(Host, Nidx) of
|
case get_cached_item(Host, Nidx) of
|
||||||
undefined ->
|
undefined ->
|
||||||
@ -2635,45 +2636,37 @@ payload_xmlelements([#xmlel{} | Tail], Count) ->
|
|||||||
payload_xmlelements([_ | Tail], Count) ->
|
payload_xmlelements([_ | Tail], Count) ->
|
||||||
payload_xmlelements(Tail, Count).
|
payload_xmlelements(Tail, Count).
|
||||||
|
|
||||||
items_event_stanza(Node, Options, Items) ->
|
items_els(Node, Options, Items) ->
|
||||||
MoreEls = case Items of
|
Els = case get_option(Options, itemreply) of
|
||||||
[LastItem] ->
|
publisher ->
|
||||||
{ModifNow, ModifUSR} = LastItem#pubsub_item.modification,
|
[#ps_item{id = ItemId, sub_els = Payload, publisher = jid:encode(USR)}
|
||||||
[#delay{stamp = ModifNow, from = jid:make(ModifUSR)}];
|
|| #pubsub_item{itemid = {ItemId, _}, payload = Payload, modification = {_, USR}}
|
||||||
|
<- Items];
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[#ps_item{id = ItemId, sub_els = Payload}
|
||||||
|
|| #pubsub_item{itemid = {ItemId, _}, payload = Payload}
|
||||||
|
<- Items]
|
||||||
end,
|
end,
|
||||||
BaseStanza = #message{
|
#ps_items{node = Node, items = Els}.
|
||||||
sub_els = [#ps_event{items = #ps_items{
|
|
||||||
node = Node,
|
|
||||||
items = itemsEls(Items)}}
|
|
||||||
| MoreEls]},
|
|
||||||
NotificationType = get_option(Options, notification_type, headline),
|
|
||||||
add_message_type(BaseStanza, NotificationType).
|
|
||||||
|
|
||||||
%%%%%% broadcast functions
|
%%%%%% broadcast functions
|
||||||
|
|
||||||
broadcast_publish_item(Host, Node, Nidx, Type, NodeOptions, ItemId, From, Payload, Removed) ->
|
broadcast_publish_item(Host, Node, Nidx, Type, NodeOptions, ItemId, From, Payload, Removed) ->
|
||||||
case get_collection_subscriptions(Host, Node) of
|
case get_collection_subscriptions(Host, Node) of
|
||||||
SubsByDepth when is_list(SubsByDepth) ->
|
SubsByDepth when is_list(SubsByDepth) ->
|
||||||
EventItem0 = case get_option(NodeOptions, deliver_payloads) of
|
ItemPublisher = case get_option(NodeOptions, itemreply) of
|
||||||
true -> #ps_item{sub_els = Payload, id = ItemId};
|
publisher -> jid:encode(From);
|
||||||
false -> #ps_item{id = ItemId}
|
_ -> undefined
|
||||||
end,
|
end,
|
||||||
EventItem = case get_option(NodeOptions, itemreply, none) of
|
ItemPayload = case get_option(NodeOptions, deliver_payloads) of
|
||||||
owner -> %% owner not supported
|
true -> Payload;
|
||||||
EventItem0;
|
false -> undefined
|
||||||
publisher ->
|
end,
|
||||||
EventItem0#ps_item{
|
ItemsEls = #ps_items{node = Node,
|
||||||
publisher = jid:encode(From)};
|
items = [#ps_item{id = ItemId,
|
||||||
none ->
|
publisher = ItemPublisher,
|
||||||
EventItem0
|
sub_els = ItemPayload}]},
|
||||||
end,
|
Stanza = #message{ sub_els = [#ps_event{items = ItemsEls}]},
|
||||||
Stanza = #message{
|
|
||||||
sub_els =
|
|
||||||
[#ps_event{items =
|
|
||||||
#ps_items{node = Node,
|
|
||||||
items = [EventItem]}}]},
|
|
||||||
broadcast_stanza(Host, From, Node, Nidx, Type,
|
broadcast_stanza(Host, From, Node, Nidx, Type,
|
||||||
NodeOptions, SubsByDepth, items, Stanza, true),
|
NodeOptions, SubsByDepth, items, Stanza, true),
|
||||||
case Removed of
|
case Removed of
|
||||||
@ -2900,8 +2893,20 @@ send_items(Host, Node, Nidx, Type, Options, Publisher, SubLJID, ToLJID, Number)
|
|||||||
[] ->
|
[] ->
|
||||||
ok;
|
ok;
|
||||||
Items ->
|
Items ->
|
||||||
Stanza = items_event_stanza(Node, Options, Items),
|
Delay = case Number of
|
||||||
send_stanza(Publisher, ToLJID, Node, Stanza)
|
last -> % handle section 6.1.7 of XEP-0060
|
||||||
|
[Last] = Items,
|
||||||
|
{Stamp, _USR} = Last#pubsub_item.modification,
|
||||||
|
[#delay{stamp = Stamp}];
|
||||||
|
_ ->
|
||||||
|
[]
|
||||||
|
end,
|
||||||
|
Stanza = #message{
|
||||||
|
sub_els = [#ps_event{items = items_els(Node, Options, Items)}
|
||||||
|
| Delay]},
|
||||||
|
NotificationType = get_option(Options, notification_type, headline),
|
||||||
|
send_stanza(Publisher, ToLJID, Node,
|
||||||
|
add_message_type(Stanza, NotificationType))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
send_stanza({LUser, LServer, _} = Publisher, USR, Node, BaseStanza) ->
|
send_stanza({LUser, LServer, _} = Publisher, USR, Node, BaseStanza) ->
|
||||||
@ -3733,11 +3738,6 @@ uniqid() ->
|
|||||||
{T1, T2, T3} = p1_time_compat:timestamp(),
|
{T1, T2, T3} = p1_time_compat:timestamp(),
|
||||||
(str:format("~.16B~.16B~.16B", [T1, T2, T3])).
|
(str:format("~.16B~.16B~.16B", [T1, T2, T3])).
|
||||||
|
|
||||||
-spec itemsEls([#pubsub_item{}]) -> [ps_item()].
|
|
||||||
itemsEls(Items) ->
|
|
||||||
[#ps_item{id = ItemId, sub_els = Payload}
|
|
||||||
|| #pubsub_item{itemid = {ItemId, _}, payload = Payload} <- Items].
|
|
||||||
|
|
||||||
-spec add_message_type(message(), message_type()) -> message().
|
-spec add_message_type(message(), message_type()) -> message().
|
||||||
add_message_type(#message{} = Message, Type) ->
|
add_message_type(#message{} = Message, Type) ->
|
||||||
Message#message{type = Type}.
|
Message#message{type = Type}.
|
||||||
|
Loading…
Reference in New Issue
Block a user