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.
|
|
|
|
|
|
|
|
ircd::mapi::header
|
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Client Sync :Room Account Data"
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace ircd::m::sync
|
|
|
|
{
|
2019-02-24 20:59:53 +01:00
|
|
|
static bool room_account_data_polylog_events_event(data &, const m::event &);
|
|
|
|
static bool room_account_data_polylog_events(data &);
|
|
|
|
static bool room_account_data_polylog(data &);
|
2019-02-27 02:34:07 +01:00
|
|
|
static bool room_account_data_linear(data &);
|
2019-01-10 05:39:12 +01:00
|
|
|
|
2019-01-04 02:21:02 +01:00
|
|
|
extern item room_account_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::m::sync::room_account_data)
|
|
|
|
ircd::m::sync::room_account_data
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
"rooms.account_data",
|
2019-02-27 02:34:07 +01:00
|
|
|
room_account_data_polylog,
|
|
|
|
room_account_data_linear
|
2019-01-04 02:21:02 +01:00
|
|
|
};
|
|
|
|
|
2019-02-27 02:34:07 +01:00
|
|
|
bool
|
|
|
|
ircd::m::sync::room_account_data_linear(data &data)
|
|
|
|
{
|
2019-03-01 21:42:11 +01:00
|
|
|
if(!data.event || !data.event_idx)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const m::event &event{*data.event};
|
|
|
|
if(json::get<"room_id"_>(event) != data.user_room.room_id)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
char typebuf[m::user::room_account_data::typebuf_size];
|
|
|
|
const auto type
|
|
|
|
{
|
|
|
|
m::user::room_account_data::_type(typebuf, data.room->room_id)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(json::get<"type"_>(event) != type)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
json::stack::array array
|
|
|
|
{
|
|
|
|
*data.out, "events"
|
|
|
|
};
|
|
|
|
|
|
|
|
return room_account_data_polylog_events_event(data, event);
|
2019-02-27 02:34:07 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
bool
|
2019-01-04 02:21:02 +01:00
|
|
|
ircd::m::sync::room_account_data_polylog(data &data)
|
|
|
|
{
|
2019-02-24 20:59:53 +01:00
|
|
|
return room_account_data_polylog_events(data);
|
2019-01-09 00:10:06 +01:00
|
|
|
}
|
|
|
|
|
2019-02-24 20:59:53 +01:00
|
|
|
bool
|
2019-01-10 05:39:12 +01:00
|
|
|
ircd::m::sync::room_account_data_polylog_events(data &data)
|
2019-01-09 00:10:06 +01:00
|
|
|
{
|
|
|
|
json::stack::array array
|
|
|
|
{
|
2019-02-27 00:50:58 +01:00
|
|
|
*data.out, "events"
|
2019-01-09 00:10:06 +01:00
|
|
|
};
|
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
assert(data.room);
|
2019-03-01 21:41:52 +01:00
|
|
|
char typebuf[m::user::room_account_data::typebuf_size];
|
2019-01-04 02:21:02 +01:00
|
|
|
const auto type
|
|
|
|
{
|
2019-02-21 20:53:59 +01:00
|
|
|
m::user::room_account_data::_type(typebuf, data.room->room_id)
|
|
|
|
};
|
|
|
|
|
2019-03-01 21:41:52 +01:00
|
|
|
bool ret{false};
|
|
|
|
data.user_state.for_each(type, [&data, &ret]
|
|
|
|
(const m::event::idx &event_idx)
|
2019-02-21 20:53:59 +01:00
|
|
|
{
|
2019-03-01 21:41:52 +01:00
|
|
|
if(!apropos(data, event_idx))
|
|
|
|
return;
|
2019-02-21 20:53:59 +01:00
|
|
|
|
2019-03-01 21:41:52 +01:00
|
|
|
static const event::fetch::opts fopts
|
|
|
|
{
|
|
|
|
event::keys::include {"state_key", "content"}
|
|
|
|
};
|
2019-01-04 02:21:02 +01:00
|
|
|
|
2019-03-01 21:41:52 +01:00
|
|
|
const m::event::fetch event
|
|
|
|
{
|
|
|
|
event_idx, std::nothrow, fopts
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!event.valid)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ret |= room_account_data_polylog_events_event(data, event);
|
2019-01-10 05:39:12 +01:00
|
|
|
});
|
2019-02-24 20:59:53 +01:00
|
|
|
|
|
|
|
return ret;
|
2019-01-10 05:39:12 +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_account_data_polylog_events_event(data &data,
|
|
|
|
const m::event &event)
|
|
|
|
{
|
|
|
|
json::stack::object object
|
|
|
|
{
|
2019-02-27 00:50:58 +01:00
|
|
|
*data.out
|
2019-01-10 05:39:12 +01:00
|
|
|
};
|
2019-01-04 02:21:02 +01:00
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
object, "type", at<"state_key"_>(event)
|
|
|
|
};
|
2019-01-04 02:21:02 +01:00
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
json::stack::member
|
|
|
|
{
|
|
|
|
object, "content", at<"content"_>(event)
|
|
|
|
};
|
2019-02-24 20:59:53 +01:00
|
|
|
|
|
|
|
return true;
|
2019-01-04 02:21:02 +01:00
|
|
|
}
|