mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +01:00
make get_items able to sort items in publish order (EJAB-824)
SVN Revision: 2105
This commit is contained in:
parent
aa210166c4
commit
45a8a0fb53
@ -445,8 +445,6 @@ send_loop(State) ->
|
|||||||
send_loop(State);
|
send_loop(State);
|
||||||
{presence, User, Server, Resources, JID} ->
|
{presence, User, Server, Resources, JID} ->
|
||||||
%% get resources caps and check if processing is needed
|
%% 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() ->
|
spawn(fun() ->
|
||||||
{HasCaps, ResourcesCaps} = lists:foldl(fun(Resource, {R, L}) ->
|
{HasCaps, ResourcesCaps} = lists:foldl(fun(Resource, {R, L}) ->
|
||||||
case mod_caps:get_caps({User, Server, Resource}) of
|
case mod_caps:get_caps({User, Server, Resource}) of
|
||||||
@ -1985,29 +1983,16 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) ->
|
|||||||
%% Number = last | integer()
|
%% Number = last | integer()
|
||||||
%% @doc <p>Resend the items of a node to the user.</p>
|
%% @doc <p>Resend the items of a node to the user.</p>
|
||||||
%% @todo use cache-last-item feature
|
%% @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, {LU, LS, LR} = LJID, Number) ->
|
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
|
||||||
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
||||||
{result, []} ->
|
{result, []} ->
|
||||||
[];
|
[];
|
||||||
{result, Items} ->
|
{result, Items} ->
|
||||||
case Number of
|
case Number of
|
||||||
last ->
|
N when N > 0 -> lists:sublist(Items, N);
|
||||||
%%% [lists:last(Items)] does not work on clustered table
|
_ -> Items
|
||||||
[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
|
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
|
@ -699,9 +699,8 @@ del_state(NodeId, JID) ->
|
|||||||
%% ```get_items(NodeId, From) ->
|
%% ```get_items(NodeId, From) ->
|
||||||
%% node_default:get_items(NodeId, From).'''</p>
|
%% node_default:get_items(NodeId, From).'''</p>
|
||||||
get_items(NodeId, _From) ->
|
get_items(NodeId, _From) ->
|
||||||
Items = mnesia:match_object(
|
Items = mnesia:match_object(#pubsub_item{itemid = {'_', NodeId}, _ = '_'}),
|
||||||
#pubsub_item{itemid = {'_', NodeId}, _ = '_'}),
|
{result, lists:reverse(lists:keysort(#pubsub_item.modification, Items))}.
|
||||||
{result, Items}.
|
|
||||||
get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) ->
|
get_items(NodeId, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId) ->
|
||||||
GenKey = jlib:short_prepd_bare_jid(JID),
|
GenKey = jlib:short_prepd_bare_jid(JID),
|
||||||
GenState = get_state(NodeId, GenKey),
|
GenState = get_state(NodeId, GenKey),
|
||||||
|
Loading…
Reference in New Issue
Block a user