]> granicus.if.org Git - ejabberd/commitdiff
subscribing to a node sends only last items (EJAB-700), send_last_items bugfix
authorChristophe Romain <christophe.romain@process-one.net>
Wed, 23 Jul 2008 01:14:02 +0000 (01:14 +0000)
committerChristophe Romain <christophe.romain@process-one.net>
Wed, 23 Jul 2008 01:14:02 +0000 (01:14 +0000)
SVN Revision: 1474

ChangeLog
src/mod_pubsub/mod_pubsub.erl

index 5c9c0762b0c0ceccc8743655c5c088681898c3a2..9028a308d74dddb915d5da87c079948c94fecbf6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,7 +2,8 @@
 
        * src/mod_pubsub/mod_pubsub.erl: remove_user hook removes
        subscriptions (EJAB-684), send the last published and not the
-       first published item (EJAB-675), remove the pubsub/nodes tree.
+       first published item (EJAB-675), remove the pubsub/nodes tree,
+       subscribing to a node sends only last items (EJAB-700)
        * src/mod_pubsub/node_pep.erl: added acl and jid match on node
        creation permission (EJAB-663)
        * src/mod_pubsub/node_default.erl: fix node creation permission 
index a993af71b33c868160e10d49811f0aef3185e239..82a2c483f7334c2b6221cf891fe5d85d5220a040 100644 (file)
@@ -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)}],