mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
modules/client/rooms/initial_sync: Remove this trash and stub again.
This commit is contained in:
parent
e1b6ff3838
commit
58d9bd7ca1
1 changed files with 19 additions and 158 deletions
|
@ -22,91 +22,11 @@ get__initialsync_remote(client &client,
|
|||
const resource::request &request,
|
||||
const m::room::id &room_id)
|
||||
{
|
||||
// only used for headers
|
||||
const unique_buffer<mutable_buffer> state_buffer
|
||||
{
|
||||
8_KiB
|
||||
};
|
||||
|
||||
// only used for headers
|
||||
const unique_buffer<mutable_buffer> backfill_buffer
|
||||
{
|
||||
8_KiB
|
||||
};
|
||||
|
||||
m::v1::state state_request
|
||||
{
|
||||
room_id, state_buffer,
|
||||
};
|
||||
|
||||
m::v1::backfill::opts bf_opts;
|
||||
bf_opts.limit = size_t(initial_backfill);
|
||||
m::v1::backfill backfill_request
|
||||
{
|
||||
room_id, backfill_buffer, std::move(bf_opts)
|
||||
};
|
||||
|
||||
const auto when
|
||||
{
|
||||
ircd::now<steady_point>() + seconds(15) //TODO: conf
|
||||
};
|
||||
|
||||
std::vector<m::event> messages;
|
||||
messages.reserve(bf_opts.limit);
|
||||
if(backfill_request.wait_until(when) != ctx::future_status::timeout)
|
||||
{
|
||||
const auto &code{backfill_request.get()};
|
||||
const json::object &response{backfill_request};
|
||||
const json::array &pdus
|
||||
{
|
||||
response.get("pdus")
|
||||
};
|
||||
|
||||
for(const json::object &event : pdus)
|
||||
messages.emplace_back(event);
|
||||
|
||||
std::sort(std::begin(messages), std::end(messages), []
|
||||
(const auto &a, const auto &b)
|
||||
{
|
||||
return at<"depth"_>(a) < at<"depth"_>(b);
|
||||
});
|
||||
}
|
||||
else cancel(backfill_request);
|
||||
|
||||
std::vector<m::event> state;
|
||||
if(state_request.wait_until(when) != ctx::future_status::timeout)
|
||||
{
|
||||
const auto &code{state_request.get()};
|
||||
const json::object &response{state_request};
|
||||
const json::array &auth_chain
|
||||
{
|
||||
response.get("auth_chain")
|
||||
};
|
||||
|
||||
const json::array &pdus
|
||||
{
|
||||
response.get("pdus")
|
||||
};
|
||||
|
||||
state.reserve(auth_chain.size() + pdus.size());
|
||||
for(const json::object &event : auth_chain)
|
||||
state.emplace_back(event);
|
||||
|
||||
for(const json::object &event : pdus)
|
||||
state.emplace_back(event);
|
||||
|
||||
std::sort(std::begin(state), std::end(state), []
|
||||
(const auto &a, const auto &b)
|
||||
{
|
||||
return at<"depth"_>(a) < at<"depth"_>(b);
|
||||
});
|
||||
}
|
||||
else cancel(state_request);
|
||||
|
||||
const string_view membership{"join"};
|
||||
string_view membership{"join"};
|
||||
const string_view visibility{"public"};
|
||||
std::vector<m::event> messages;
|
||||
std::vector<m::event> state;
|
||||
std::vector<json::value> account_data;
|
||||
|
||||
const json::strung chunk
|
||||
{
|
||||
messages.data(), messages.data() + messages.size()
|
||||
|
@ -117,7 +37,7 @@ get__initialsync_remote(client &client,
|
|||
state.data(), state.data() + state.size()
|
||||
};
|
||||
|
||||
resource::response
|
||||
return resource::response
|
||||
{
|
||||
client, json::members
|
||||
{
|
||||
|
@ -132,22 +52,6 @@ get__initialsync_remote(client &client,
|
|||
}},
|
||||
}
|
||||
};
|
||||
|
||||
m::vm::opts vmopts;
|
||||
m::vm::eval eval{vmopts};
|
||||
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_PREV_STATE);
|
||||
vmopts.non_conform.set(m::event::conforms::MISSING_MEMBERSHIP);
|
||||
vmopts.prev_check_exists = false;
|
||||
vmopts.nothrows = -1U;
|
||||
|
||||
for(const auto &event : state)
|
||||
eval(event);
|
||||
|
||||
for(const auto &event : messages)
|
||||
eval(event);
|
||||
|
||||
return {}; // already returned
|
||||
}
|
||||
|
||||
resource::response
|
||||
|
@ -162,79 +66,36 @@ get__initialsync(client &client,
|
|||
|
||||
throw m::NOT_FOUND
|
||||
{
|
||||
"room_id '%s' does not exist", room_id
|
||||
"room_id '%s' does not exist", string_view{room_id}
|
||||
};
|
||||
}
|
||||
|
||||
const m::room room
|
||||
const m::room room{room_id};
|
||||
const m::room::state state
|
||||
{
|
||||
room_id
|
||||
room
|
||||
};
|
||||
|
||||
std::vector<std::string> state;
|
||||
{
|
||||
const m::room::state state_
|
||||
{
|
||||
room_id
|
||||
};
|
||||
|
||||
state.reserve(state_.count());
|
||||
state_.for_each([&state](const m::event &event)
|
||||
{
|
||||
state.emplace_back(json::strung(event));
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::string> messages;
|
||||
{
|
||||
messages.reserve(20);
|
||||
m::room::messages it{room};
|
||||
for(; it && messages.size() < 20; --it)
|
||||
messages.emplace_back(json::strung(*it));
|
||||
|
||||
std::reverse(begin(messages), end(messages));
|
||||
}
|
||||
|
||||
char membership_buffer[64];
|
||||
const string_view membership
|
||||
{
|
||||
request.user_id? room.membership(membership_buffer, m::user::id{request.user_id}) : string_view{}
|
||||
};
|
||||
|
||||
//TODO: XXX
|
||||
string_view membership{"join"};
|
||||
const string_view visibility{"public"};
|
||||
|
||||
//TODO: XXX
|
||||
std::vector<m::event> messages;
|
||||
std::vector<m::event> statev;
|
||||
std::vector<json::value> account_data;
|
||||
const json::value account_datas
|
||||
{
|
||||
account_data.data(), account_data.size()
|
||||
};
|
||||
|
||||
//TODO: derp
|
||||
const json::strung states
|
||||
{
|
||||
state.data(), state.data() + state.size()
|
||||
};
|
||||
|
||||
//TODO: derp
|
||||
const json::strung messages_chunk
|
||||
const string_view messages_start{};
|
||||
const string_view messages_end{};
|
||||
const json::strung chunk
|
||||
{
|
||||
messages.data(), messages.data() + messages.size()
|
||||
};
|
||||
|
||||
const string_view &messages_start
|
||||
const json::strung states
|
||||
{
|
||||
!messages.empty()?
|
||||
unquote(json::object{messages.front()}.at("event_id")):
|
||||
string_view{}
|
||||
statev.data(), statev.data() + statev.size()
|
||||
};
|
||||
|
||||
const string_view &messages_end
|
||||
const json::strung account_datas
|
||||
{
|
||||
!messages.empty()?
|
||||
unquote(json::object{messages.back()}.at("event_id")):
|
||||
string_view{}
|
||||
account_data.data(), account_data.data() + account_data.size()
|
||||
};
|
||||
|
||||
return resource::response
|
||||
|
@ -249,7 +110,7 @@ get__initialsync(client &client,
|
|||
{ "messages", json::members
|
||||
{
|
||||
{ "start", messages_start },
|
||||
{ "chunk", messages_chunk },
|
||||
{ "chunk", chunk },
|
||||
{ "end", messages_end },
|
||||
}},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue