2019-01-04 23:47:01 +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 :Rooms"
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace ircd::m::sync
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
static void _rooms_polylog_room(data &, const m::room &);
|
|
|
|
static void _rooms_polylog(data &, const string_view &membership);
|
2019-01-10 22:19:07 +01:00
|
|
|
static void rooms_polylog(data &);
|
2019-01-10 05:39:12 +01:00
|
|
|
|
|
|
|
static void _rooms_linear(data &, const string_view &membership);
|
2019-01-10 22:19:07 +01:00
|
|
|
static void rooms_linear(data &);
|
2019-01-10 05:39:12 +01:00
|
|
|
|
2019-01-04 23:47:01 +01:00
|
|
|
extern item rooms;
|
|
|
|
}
|
|
|
|
|
|
|
|
decltype(ircd::m::sync::rooms)
|
|
|
|
ircd::m::sync::rooms
|
|
|
|
{
|
|
|
|
"rooms",
|
|
|
|
rooms_polylog,
|
|
|
|
rooms_linear
|
|
|
|
};
|
|
|
|
|
2019-01-10 22:19:07 +01:00
|
|
|
void
|
2019-01-04 23:47:01 +01:00
|
|
|
ircd::m::sync::rooms_linear(data &data)
|
|
|
|
{
|
2019-01-10 05:39:12 +01:00
|
|
|
json::stack::object object{data.out};
|
|
|
|
_rooms_linear(data, "invite");
|
|
|
|
_rooms_linear(data, "join");
|
|
|
|
_rooms_linear(data, "leave");
|
|
|
|
_rooms_linear(data, "ban");
|
2019-01-04 23:47:01 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
void
|
|
|
|
ircd::m::sync::_rooms_linear(data &data,
|
|
|
|
const string_view &membership)
|
|
|
|
{
|
|
|
|
const scope_restore<decltype(data.membership)> theirs
|
|
|
|
{
|
|
|
|
data.membership, membership
|
|
|
|
};
|
|
|
|
|
|
|
|
m::sync::for_each("rooms", [&](item &item)
|
|
|
|
{
|
|
|
|
json::stack::member member
|
|
|
|
{
|
|
|
|
data.out, item.member_name()
|
|
|
|
};
|
|
|
|
|
|
|
|
item.linear(data);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-10 22:19:07 +01:00
|
|
|
void
|
2019-01-04 23:47:01 +01:00
|
|
|
ircd::m::sync::rooms_polylog(data &data)
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
json::stack::object object{data.out};
|
|
|
|
_rooms_polylog(data, "invite");
|
|
|
|
_rooms_polylog(data, "join");
|
|
|
|
_rooms_polylog(data, "leave");
|
|
|
|
_rooms_polylog(data, "ban");
|
2019-01-10 22:19:07 +01:00
|
|
|
return;
|
2019-01-04 23:47:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::sync::_rooms_polylog(data &data,
|
|
|
|
const string_view &membership)
|
|
|
|
{
|
2019-01-10 05:39:12 +01:00
|
|
|
const scope_restore<decltype(data.membership)> theirs
|
|
|
|
{
|
|
|
|
data.membership, membership
|
|
|
|
};
|
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
json::stack::object object
|
2019-01-04 23:47:01 +01:00
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
data.out, membership
|
2019-01-04 23:47:01 +01:00
|
|
|
};
|
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
data.user_rooms.for_each(membership, [&data]
|
2019-01-10 05:39:12 +01:00
|
|
|
(const m::room &room, const string_view &membership_)
|
2019-01-04 23:47:01 +01:00
|
|
|
{
|
2019-01-26 01:18:21 +01:00
|
|
|
#ifdef RB_DEBUG
|
2019-01-10 22:19:07 +01:00
|
|
|
sync::stats stats
|
|
|
|
{
|
|
|
|
data.stats?
|
|
|
|
*data.stats:
|
|
|
|
sync::stats{}
|
|
|
|
};
|
|
|
|
|
|
|
|
if(data.stats)
|
|
|
|
stats.timer = timer{};
|
2019-01-04 23:47:01 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
_rooms_polylog_room(data, room);
|
2019-01-04 23:47:01 +01:00
|
|
|
|
|
|
|
#ifdef RB_DEBUG
|
2019-01-09 00:10:06 +01:00
|
|
|
thread_local char tmbuf[32];
|
2019-01-26 01:18:21 +01:00
|
|
|
if(data.stats) log::debug
|
2019-01-04 23:47:01 +01:00
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
log, "polylog %s %s in %s",
|
|
|
|
loghead(data),
|
2019-01-04 23:47:01 +01:00
|
|
|
string_view{room.room_id},
|
2019-01-27 02:01:36 +01:00
|
|
|
ircd::pretty(tmbuf, stats.timer.at<milliseconds>(), true)
|
2019-01-04 23:47:01 +01:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::sync::_rooms_polylog_room(data &data,
|
|
|
|
const m::room &room)
|
|
|
|
{
|
|
|
|
const scope_restore<decltype(data.room)> theirs
|
|
|
|
{
|
|
|
|
data.room, &room
|
|
|
|
};
|
|
|
|
|
2019-01-10 05:39:12 +01:00
|
|
|
json::stack::object object
|
|
|
|
{
|
|
|
|
data.out, room.room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
m::sync::for_each("rooms", [&data]
|
|
|
|
(item &item)
|
2019-01-04 23:47:01 +01:00
|
|
|
{
|
|
|
|
json::stack::member member
|
|
|
|
{
|
2019-01-09 00:10:06 +01:00
|
|
|
data.out, item.member_name()
|
2019-01-04 23:47:01 +01:00
|
|
|
};
|
|
|
|
|
2019-01-09 00:10:06 +01:00
|
|
|
item.polylog(data);
|
|
|
|
return true;
|
|
|
|
});
|
2019-01-04 23:47:01 +01:00
|
|
|
}
|