mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Return proper index when using after of before in PubSub with RSM (#3618)
This fixes Index attribute in examples from: https://xmpp.org/extensions/xep-0059.html#forwards https://xmpp.org/extensions/xep-0059.html#backwards
This commit is contained in:
parent
41fd2afeb3
commit
bf8b4acf01
@ -761,18 +761,14 @@ get_items(Nidx, _From, #rsm_set{max = Max, index = IncIndex,
|
|||||||
{Count, lists:sublist(SubList, Limit)};
|
{Count, lists:sublist(SubList, Limit)};
|
||||||
{_, Stamp, undefined} ->
|
{_, Stamp, undefined} ->
|
||||||
BeforeNow = encode_stamp(Stamp),
|
BeforeNow = encode_stamp(Stamp),
|
||||||
SubList = lists:dropwhile(
|
{NewIndex, SubList} = extract_sublist(before_now, BeforeNow,
|
||||||
fun(#pubsub_item{creation = {Now, _}}) ->
|
0, lists:reverse(RItems)),
|
||||||
Now >= BeforeNow
|
{Count-NewIndex-1, lists:sublist(SubList, Limit)};
|
||||||
end, lists:reverse(RItems)),
|
|
||||||
{0, lists:sublist(SubList, Limit)};
|
|
||||||
{_, undefined, Stamp} ->
|
{_, undefined, Stamp} ->
|
||||||
AfterNow = encode_stamp(Stamp),
|
AfterNow = encode_stamp(Stamp),
|
||||||
SubList = lists:dropwhile(
|
{NewIndex, SubList} = extract_sublist(after_now, AfterNow,
|
||||||
fun(#pubsub_item{creation = {Now, _}}) ->
|
0, RItems),
|
||||||
Now =< AfterNow
|
{NewIndex, lists:sublist(SubList, Limit)}
|
||||||
end, RItems),
|
|
||||||
{0, lists:sublist(SubList, Limit)}
|
|
||||||
end,
|
end,
|
||||||
Rsm = rsm_page(Count, IncIndex, Offset, ItemsPage),
|
Rsm = rsm_page(Count, IncIndex, Offset, ItemsPage),
|
||||||
{result, {ItemsPage, Rsm}}
|
{result, {ItemsPage, Rsm}}
|
||||||
@ -814,6 +810,13 @@ get_items(Nidx, JID, AccessModel, PresenceSubscription, RosterGroup, _SubId, RSM
|
|||||||
get_items(Nidx, JID, RSM)
|
get_items(Nidx, JID, RSM)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
extract_sublist(A, Now, Index, [#pubsub_item{creation = {Creation, _}} | RItems])
|
||||||
|
when ((A == before_now) and (Creation >= Now))
|
||||||
|
or ((A == after_now) and (Creation =< Now)) ->
|
||||||
|
extract_sublist(A, Now, Index+1, RItems);
|
||||||
|
extract_sublist(_, _, Index, RItems) ->
|
||||||
|
{Index, RItems}.
|
||||||
|
|
||||||
get_only_item(Nidx, From) ->
|
get_only_item(Nidx, From) ->
|
||||||
get_last_items(Nidx, From, 1).
|
get_last_items(Nidx, From, 1).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user