aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2009-05-26 22:50:11 +0000
committerChristophe Romain <christophe.romain@process-one.net>2009-05-26 22:50:11 +0000
commit7f5cce819668e712a5b5cc159b1de5eeb02e610f (patch)
tree1505b44a4f3402b78f63dfa93839d23cf4771c6c
parentimprove get_entity_* to work regardless of nodetree (EJAB-937) (diff)
make get_items able to sort items in publish order (EJAB-824)
SVN Revision: 2105
-rw-r--r--src/mod_pubsub/mod_pubsub.erl23
-rw-r--r--src/mod_pubsub/node_default.erl5
2 files changed, 6 insertions, 22 deletions
diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl
index e0acdd2a2..3f4306a91 100644
--- a/src/mod_pubsub/mod_pubsub.erl
+++ b/src/mod_pubsub/mod_pubsub.erl
@@ -443,8 +443,6 @@ send_loop(State) ->
send_loop(State);
{presence, User, Server, Resources, JID} ->
%% get resources caps and check if processing is needed
- %% get_caps may be blocked few seconds, get_caps as well
- %% so we spawn the whole process not to block other queries
spawn(fun() ->
{HasCaps, ResourcesCaps} = lists:foldl(fun(Resource, {R, L}) ->
case mod_caps:get_caps({User, Server, Resource}) of
@@ -1974,29 +1972,16 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) ->
%% Number = last | integer()
%% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature
+send_items(Host, Node, NodeId, Type, LJID, last) ->
+ send_items(Host, Node, NodeId, Type, LJID, 1);
send_items(Host, Node, NodeId, Type, LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
[];
{result, Items} ->
case Number of
- last ->
- %%% [lists:last(Items)] does not work on clustered table
- [First|Tail] = Items,
- [lists:foldl(
- fun(CurItem, LastItem) ->
- {LTimeStamp, _} = LastItem#pubsub_item.creation,
- {CTimeStamp, _} = CurItem#pubsub_item.creation,
- if
- CTimeStamp > LTimeStamp -> CurItem;
- true -> LastItem
- end
- end, First, Tail)];
- N when N > 0 ->
- %%% This case is buggy on clustered table due to lack of order
- lists:nthtail(length(Items)-N, Items);
- _ ->
- Items
+ N when N > 0 -> lists:sublist(Items, N);
+ _ -> Items
end;
_ ->
[]
diff --git a/src/mod_pubsub/node_default.erl b/src/mod_pubsub/node_default.erl
index 6e39b88e8..4cab47f3b 100644
--- a/src/mod_pubsub/node_default.erl
+++ b/src/mod_pubsub/node_default.erl
@@ -701,9 +701,8 @@ del_state(NodeId, JID) ->
%% ```get_items(NodeId, From) ->
%% node_default:get_items(NodeId, From).'''</p>
get_items(NodeId, _From) ->
- Items = mnesia:match_object(
- #pubsub_item{itemid = {'_', NodeId}, _ = '_'}),
- {result, Items}.
+ Items = mnesia:match_object(#pubsub_item{itemid = {'_', NodeId}, _ = '_'}),
+ {result, lists:reverse(lists:keysort(#pubsub_item.modification, Items))}.
get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) ->
SubKey = jlib:jid_tolower(JID),
GenKey = jlib:jid_remove_resource(SubKey),