mirror of
https://github.com/matrix-construct/construct
synced 2024-06-07 12:38:56 +02:00
ircd:Ⓜ️:user::notifications: Add sorting for any-room queries here.
This commit is contained in:
parent
a398a1f5c0
commit
5665ae56cf
|
@ -39,6 +39,7 @@ struct ircd::m::user::notifications::opts
|
|||
event::idx to {0}; // lowest idx ending iteration
|
||||
string_view only; // spec "only" filter
|
||||
room::id room_id; // room_id filter (optional)
|
||||
bool sorted {true}; // sorted or optimal results
|
||||
};
|
||||
|
||||
inline
|
||||
|
|
|
@ -116,15 +116,38 @@ const
|
|||
user_room, type, {-1UL, -1L}, true
|
||||
};
|
||||
|
||||
return events.for_each([&opts, &closure]
|
||||
if(!opts.sorted || opts.room_id)
|
||||
return events.for_each([&opts, &closure]
|
||||
(const auto &type, const auto &depth, const auto &event_idx)
|
||||
{
|
||||
if(opts.from && event_idx > opts.from) //TODO: XXX
|
||||
return true;
|
||||
|
||||
if(opts.to && event_idx <= opts.to) //TODO: XXX
|
||||
return false;
|
||||
|
||||
return closure(type, event_idx);
|
||||
});
|
||||
|
||||
std::vector<event::idx> idxs;
|
||||
idxs.reserve(events.count());
|
||||
events.for_each([&opts, &idxs]
|
||||
(const auto &type, const auto &depth, const auto &event_idx)
|
||||
{
|
||||
if(opts.from && event_idx > opts.from) //TODO: XXX
|
||||
if(opts.from && event_idx > opts.from)
|
||||
return true;
|
||||
|
||||
if(opts.to && event_idx <= opts.to) //TODO: XXX
|
||||
if(opts.to && event_idx <= opts.to)
|
||||
return true;
|
||||
|
||||
idxs.emplace_back(event_idx);
|
||||
return true;
|
||||
});
|
||||
|
||||
std::sort(rbegin(idxs), rend(idxs));
|
||||
for(const auto &idx : idxs)
|
||||
if(!closure(string_view{}, idx)) //NOTE: no type string to closure
|
||||
return false;
|
||||
|
||||
return closure(type, event_idx);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue