mirror of
https://github.com/matrix-construct/construct
synced 2024-12-01 19:22:53 +01:00
modules/client/rooms/messages: Chunk direct to socket.
This commit is contained in:
parent
87f792b8eb
commit
fb96f017b7
1 changed files with 50 additions and 45 deletions
|
@ -47,69 +47,74 @@ get__messages(client &client,
|
|||
room, page.from
|
||||
};
|
||||
|
||||
//TODO: chunk directly to socket
|
||||
const unique_buffer<mutable_buffer> buf
|
||||
{
|
||||
(1 + page.limit) * m::event::MAX_SIZE //TODO: XXX
|
||||
96_KiB
|
||||
};
|
||||
|
||||
json::stack out{buf};
|
||||
resource::response::chunked response
|
||||
{
|
||||
json::stack::object ret{out};
|
||||
client, http::OK
|
||||
};
|
||||
|
||||
// Spec sez the 'from' token is exclusive
|
||||
if(it && page.dir == 'b')
|
||||
--it;
|
||||
else if(it)
|
||||
++it;
|
||||
json::stack out{buf, [&response]
|
||||
(const const_buffer &buf)
|
||||
{
|
||||
response.write(buf);
|
||||
return buf;
|
||||
}};
|
||||
|
||||
size_t count{0};
|
||||
m::event::id::buf start, end;
|
||||
json::stack::object ret
|
||||
{
|
||||
out
|
||||
};
|
||||
|
||||
// Spec sez the 'from' token is exclusive
|
||||
if(it && page.dir == 'b')
|
||||
--it;
|
||||
else if(it)
|
||||
++it;
|
||||
|
||||
size_t count{0};
|
||||
m::event::id::buf start, end;
|
||||
{
|
||||
json::stack::member chunk{ret, "chunk"};
|
||||
json::stack::array messages{chunk};
|
||||
for(; it; page.dir == 'b'? --it : ++it)
|
||||
{
|
||||
json::stack::member chunk{ret, "chunk"};
|
||||
json::stack::array messages{chunk};
|
||||
for(; it; page.dir == 'b'? --it : ++it)
|
||||
const m::event &event{*it};
|
||||
if(page.to && at<"event_id"_>(event) == page.to)
|
||||
{
|
||||
const m::event &event{*it};
|
||||
if(page.to && at<"event_id"_>(event) == page.to)
|
||||
{
|
||||
if(page.dir != 'b')
|
||||
start = at<"event_id"_>(event);
|
||||
if(page.dir != 'b')
|
||||
start = at<"event_id"_>(event);
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
messages.append(event);
|
||||
if(++count >= page.limit)
|
||||
{
|
||||
if(page.dir == 'b')
|
||||
end = at<"event_id"_>(event);
|
||||
else
|
||||
start = at<"event_id"_>(event);
|
||||
messages.append(event);
|
||||
if(++count >= page.limit)
|
||||
{
|
||||
if(page.dir == 'b')
|
||||
end = at<"event_id"_>(event);
|
||||
else
|
||||
start = at<"event_id"_>(event);
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
ret, "start", json::value{start}
|
||||
};
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
ret, "end", json::value{end}
|
||||
};
|
||||
}
|
||||
|
||||
return resource::response
|
||||
json::stack::member
|
||||
{
|
||||
client, json::object
|
||||
{
|
||||
out.completed()
|
||||
}
|
||||
ret, "start", json::value{start}
|
||||
};
|
||||
|
||||
json::stack::member
|
||||
{
|
||||
ret, "end", json::value{end}
|
||||
};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
// Client-Server 6.3.6 query parameters
|
||||
|
|
Loading…
Reference in a new issue