0
0
Fork 0
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:
Jason Volk 2018-04-30 10:40:52 -07:00
parent 87f792b8eb
commit fb96f017b7

View file

@ -47,69 +47,74 @@ get__messages(client &client,
room, page.from room, page.from
}; };
//TODO: chunk directly to socket
const unique_buffer<mutable_buffer> buf 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 json::stack out{buf, [&response]
if(it && page.dir == 'b') (const const_buffer &buf)
--it; {
else if(it) response.write(buf);
++it; return buf;
}};
size_t count{0}; json::stack::object ret
m::event::id::buf start, end; {
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"}; const m::event &event{*it};
json::stack::array messages{chunk}; if(page.to && at<"event_id"_>(event) == page.to)
for(; it; page.dir == 'b'? --it : ++it)
{ {
const m::event &event{*it}; if(page.dir != 'b')
if(page.to && at<"event_id"_>(event) == page.to) start = at<"event_id"_>(event);
{
if(page.dir != 'b')
start = at<"event_id"_>(event);
break; break;
} }
messages.append(event); messages.append(event);
if(++count >= page.limit) if(++count >= page.limit)
{ {
if(page.dir == 'b') if(page.dir == 'b')
end = at<"event_id"_>(event); end = at<"event_id"_>(event);
else else
start = at<"event_id"_>(event); 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 ret, "start", json::value{start}
{
out.completed()
}
}; };
json::stack::member
{
ret, "end", json::value{end}
};
return {};
} }
// Client-Server 6.3.6 query parameters // Client-Server 6.3.6 query parameters