summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2008-07-23 01:14:02 +0000
committerChristophe Romain <christophe.romain@process-one.net>2008-07-23 01:14:02 +0000
commitd8dc734d38062c6fea3a35a3d79622e59c01206a (patch)
tree313dfc9991a96c7ae93851f962688b5b242cdc40 /src
parentpubsub improvement, fixes EJAB-684 EJAB-675 EJAB-663 (diff)
subscribing to a node sends only last items (EJAB-700), send_last_items bugfix
SVN Revision: 1474
Diffstat (limited to 'src')
-rw-r--r--src/mod_pubsub/mod_pubsub.erl34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl
index a993af71..82a2c483 100644
--- a/src/mod_pubsub/mod_pubsub.erl
+++ b/src/mod_pubsub/mod_pubsub.erl
@@ -1385,7 +1385,7 @@ subscribe_node(Host, Node, From, JID) ->
{error, Error} ->
{error, Error};
{result, {Result, subscribed, send_last}} ->
- send_all_items(Host, Node, Subscriber),
+ send_last_item(Host, Node, Subscriber),
case Result of
default -> {result, Reply(subscribed)};
_ -> {result, Result}
@@ -1732,21 +1732,25 @@ send_last_item(Host, Node, LJID) ->
%% TODO use cache-last-item feature
send_items(Host, Node, LJID, Number) ->
- Items = get_items(Host, Node),
- ToSend = case Number of
- last -> hd(lists:reverse(Items));
- all -> Items;
- N when N > 0 -> lists:nthtail(length(Items)-N, Items);
- _ -> Items
- end,
+ ToSend = case get_items(Host, Node) of
+ [] ->
+ [];
+ Items ->
+ case Number of
+ last -> lists:sublist(lists:reverse(Items), 1);
+ all -> Items;
+ N when N > 0 -> lists:nthtail(length(Items)-N, Items);
+ _ -> Items
+ end
+ end,
ItemsEls = lists:map(
- fun(#pubsub_item{itemid = {ItemId, _}, payload = Payload}) ->
- ItemAttrs = case ItemId of
- "" -> [];
- _ -> [{"id", ItemId}]
- end,
- {xmlelement, "item", ItemAttrs, Payload}
- end, ToSend),
+ fun(#pubsub_item{itemid = {ItemId, _}, payload = Payload}) ->
+ ItemAttrs = case ItemId of
+ "" -> [];
+ _ -> [{"id", ItemId}]
+ end,
+ {xmlelement, "item", ItemAttrs, Payload}
+ end, ToSend),
Stanza = {xmlelement, "message", [],
[{xmlelement, "event", [{"xmlns", ?NS_PUBSUB_EVENT}],
[{xmlelement, "items", [{"node", node_to_string(Node)}],