2019-01-04 02:21:02 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
namespace ircd::m::sync
|
|
|
|
{
|
2019-02-24 20:59:53 +01:00
|
|
|
static bool room_state_polylog_events(data &);
|
|
|
|
static bool room_state_polylog(data &);
|
2019-01-10 05:39:12 +01:00
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
static bool room_state_linear_events(data &);
|
|
|
|
static bool room_state_linear(data &);
|
2019-01-09 00:10:06 +01:00
|
|
|
|
|
|
|
extern const event::keys::include _default_keys;
|
2019-01-18 22:05:31 +01:00
|
|
|
extern event::fetch::opts _default_fopts;
|
2019-01-17 01:46:01 +01:00
|
|
|
|
2019-01-04 02:21:02 +01:00
|
|
|
extern item room_state;
|
|
|
|
}
|
|
|
|
|
2019-01-18 22:05:31 +01:00
|
|
|
ircd::mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Client Sync :Room State", []
|
|
|
|
{
|
|
|
|
ircd::m::sync::_default_fopts.query_json_force = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-04 02:21:02 +01:00
|
|
|
decltype(ircd::m::sync::room_state)
|
|
|
|
ircd::m::sync::room_state
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
"rooms.state",
|
2019-01-04 23:47:01 +01:00
|
|
|
room_state_polylog,
|
|
|
|
room_state_linear
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
decltype(ircd::m::sync::_default_keys)
|
|
|
|
ircd::m::sync::_default_keys
|
|
|
|
{
|
|
|
|
"content",
|
|
|
|
"depth",
|
|
|
|
"event_id",
|
|
|
|
"origin_server_ts",
|
|
|
|
"redacts",
|
|
|
|
"room_id",
|
|
|
|
"sender",
|
|
|
|
"state_key",
|
|
|
|
"type",
|
|
|
|
};
|
|
|
|
|
2019-01-17 01:46:01 +01:00
|
|
|
decltype(ircd::m::sync::_default_fopts)
|
2019-01-17 03:39:40 +01:00
|
|
|
ircd::m::sync::_default_fopts
|
2019-01-17 01:46:01 +01:00
|
|
|
{
|
2019-01-17 03:39:40 +01:00
|
|
|
_default_keys
|
|
|
|
};
|
2019-01-17 01:46:01 +01:00
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
bool
|
2019-01-04 23:47:01 +01:00
|
|
|
ircd::m::sync::room_state_linear(data &data)
|
|
|
|
{
|
2019-02-28 21:43:59 +01:00
|
|
|
// if since token is non-zero, any events in the range are
|
|
|
|
// included in the timeline array and not the state array.
|
|
|
|
if(data.range.first)
|
|
|
|
return false;
|
|
|
|
|
2019-02-28 03:24:12 +01:00
|
|
|
if(!data.event_idx)
|
|
|
|
return false;
|
|
|
|
|
2019-01-04 23:47:01 +01:00
|
|
|
assert(data.event);
|
|
|
|
if(!json::get<"state_key"_>(*data.event))
|
2019-02-24 20:59:53 +01:00
|
|
|
return false;
|
2019-01-04 23:47:01 +01:00
|
|
|
|
2019-02-27 02:34:07 +01:00
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
*data.out, "events"
|
|
|
|
};
|
2019-01-04 23:47:01 +01:00
|
|
|
|
2019-02-27 02:34:07 +01:00
|
|
|
array.append(*data.event);
|
|
|
|
return true;
|
2019-01-04 23:47:01 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
bool
|
2019-01-04 02:21:02 +01:00
|
|
|
ircd::m::sync::room_state_polylog(data &data)
|
|
|
|
{
|
2019-02-24 20:59:53 +01:00
|
|
|
if(!apropos(data, data.room_head))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return room_state_polylog_events(data);
|
2019-01-09 00:10:06 +01:00
|
|
|
}
|
2019-01-04 02:21:02 +01:00
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
bool
|
2019-01-10 05:39:12 +01:00
|
|
|
ircd::m::sync::room_state_polylog_events(data &data)
|
2019-01-09 00:10:06 +01:00
|
|
|
{
|
2019-01-18 22:05:31 +01:00
|
|
|
const m::room &room{*data.room};
|
|
|
|
const m::room::state state{room};
|
2019-01-04 02:21:02 +01:00
|
|
|
json::stack::array array
|
|
|
|
{
|
2019-02-27 00:50:58 +01:00
|
|
|
*data.out, "events"
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
bool ret{false};
|
2019-01-04 02:21:02 +01:00
|
|
|
ctx::mutex mutex;
|
2019-02-24 20:59:53 +01:00
|
|
|
const event::closure_idx each_idx{[&data, &array, &mutex, &ret]
|
2019-01-21 20:53:57 +01:00
|
|
|
(const m::event::idx event_idx)
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-18 22:05:31 +01:00
|
|
|
const event::fetch event
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-17 01:46:01 +01:00
|
|
|
event_idx, std::nothrow, _default_fopts
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
2019-01-26 01:19:17 +01:00
|
|
|
//assert(event.valid);
|
2019-01-18 22:05:31 +01:00
|
|
|
if(unlikely(!event.valid))
|
2019-01-04 02:21:02 +01:00
|
|
|
return;
|
|
|
|
|
2019-03-02 21:33:32 +01:00
|
|
|
const std::lock_guard lock{mutex};
|
2019-01-04 02:21:02 +01:00
|
|
|
array.append(event);
|
2019-02-24 20:59:53 +01:00
|
|
|
ret = true;
|
2019-01-04 02:21:02 +01:00
|
|
|
}};
|
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
//TODO: conf
|
2019-01-21 20:53:57 +01:00
|
|
|
std::array<event::idx, 64> md;
|
2019-01-09 00:10:06 +01:00
|
|
|
ctx::parallel<event::idx> parallel
|
2019-01-04 02:21:02 +01:00
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
m::sync::pool, md, each_idx
|
|
|
|
};
|
2019-01-04 02:21:02 +01:00
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
state.for_each([&data, ¶llel]
|
|
|
|
(const m::event::idx &event_idx)
|
|
|
|
{
|
|
|
|
if(apropos(data, event_idx))
|
|
|
|
parallel(event_idx);
|
|
|
|
});
|
2019-02-24 20:59:53 +01:00
|
|
|
|
|
|
|
return ret;
|
2019-01-04 02:21:02 +01:00
|
|
|
}
|