0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-03 20:22:56 +01:00

modules/client/rooms/messages: Simplify the messages iteration.

This commit is contained in:
Jason Volk 2019-03-04 15:46:44 -08:00
parent 1dcf36adc8
commit d8a9f484a4

View file

@ -110,70 +110,72 @@ get__messages(client &client,
response.buf, response.flusher() response.buf, response.flusher()
}; };
json::stack::object ret json::stack::object top
{ {
out out
}; };
// Spec sez the 'from' token is exclusive // Spec sez the 'from' token is exclusive
if(it && page.dir == 'b') if(page.from && it)
--it; {
else if(it) if(page.dir == 'b')
++it; --it;
else
++it;
}
m::event::id::buf start m::event::id::buf start
{ {
page.dir == 'b'? page.dir == 'b'? page.from : m::event::id::buf{}
page.from:
m::event::id::buf{}
}; };
m::event::id::buf end; m::event::id::buf end
{ {
json::stack::member member{ret, "chunk"}; page.dir == 'b'? page.to : m::event::id::buf{}
json::stack::array chunk{member}; };
size_t hit{0}, miss{0};
for(; it; page.dir == 'b'? --it : ++it) json::stack::array chunk
{
top, "chunk"
};
size_t hit{0}, miss{0};
for(; it; page.dir == 'b'? --it : ++it)
{
const m::event &event{*it};
if(page.dir != 'b')
start = at<"event_id"_>(event);
else
end = at<"event_id"_>(event);
if(hit >= page.limit || miss >= size_t(max_filter_miss))
break;
if(!visible(event, request.user_id))
{ {
const m::event &event{*it}; ++miss;
if(!visible(event, request.user_id)) continue;
break;
if(page.to && at<"event_id"_>(event) == page.to)
{
if(page.dir != 'b')
start = at<"event_id"_>(event);
break;
}
if(empty(filter_json) || match(filter, event))
{
_append(chunk, event, it.event_idx());
++hit;
}
else ++miss;
if(hit >= page.limit || miss >= size_t(max_filter_miss))
{
if(page.dir == 'b')
end = at<"event_id"_>(event);
else
start = at<"event_id"_>(event);
break;
}
} }
if(!empty(filter_json) && !match(filter, event))
{
++miss;
continue;
}
_append(chunk, event, it.event_idx());
++hit;
} }
chunk.~array();
json::stack::member json::stack::member
{ {
ret, "start", json::value{start} top, "start", json::value{start}
}; };
json::stack::member json::stack::member
{ {
ret, "end", json::value{end} top, "end", json::value{end}
}; };
return {}; return {};