2018-02-04 03:22: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.
|
2017-09-08 11:32:49 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_M_ROOM_H
|
2017-10-25 18:47:03 +02:00
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wsubobject-linkage"
|
2017-09-08 11:32:49 +02:00
|
|
|
|
|
|
|
namespace ircd::m
|
|
|
|
{
|
|
|
|
IRCD_M_EXCEPTION(m::error, CONFLICT, http::CONFLICT);
|
|
|
|
IRCD_M_EXCEPTION(m::error, NOT_MODIFIED, http::NOT_MODIFIED);
|
|
|
|
IRCD_M_EXCEPTION(CONFLICT, ALREADY_MEMBER, http::CONFLICT);
|
|
|
|
|
|
|
|
struct room;
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2018-02-13 23:23:56 +01:00
|
|
|
// Util
|
2017-12-12 21:33:14 +01:00
|
|
|
bool my(const room &);
|
2018-02-13 23:23:56 +01:00
|
|
|
|
|
|
|
// [GET] Util
|
2018-03-08 20:38:29 +01:00
|
|
|
bool exists(const room &);
|
2017-11-30 19:51:01 +01:00
|
|
|
bool exists(const id::room &);
|
2018-03-08 20:39:09 +01:00
|
|
|
bool exists(const id::room_alias &, const bool &remote = false);
|
2018-09-13 08:21:40 +02:00
|
|
|
uint version(const id::room &);
|
2018-09-13 08:26:28 +02:00
|
|
|
bool federate(const id::room &);
|
2018-10-26 01:25:18 +02:00
|
|
|
id::user::buf creator(const id::room &);
|
|
|
|
bool creator(const id::room &, const id::user &);
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2018-04-06 06:57:17 +02:00
|
|
|
// [GET]
|
2018-02-26 13:55:27 +01:00
|
|
|
id::room room_id(const mutable_buffer &, const id::room_alias &);
|
2018-04-07 06:08:59 +02:00
|
|
|
id::room room_id(const mutable_buffer &, const string_view &id_or_alias);
|
2018-02-26 13:55:27 +01:00
|
|
|
id::room::buf room_id(const id::room_alias &);
|
2018-04-07 06:08:59 +02:00
|
|
|
id::room::buf room_id(const string_view &id_or_alias);
|
2018-02-26 13:55:27 +01:00
|
|
|
|
2018-04-06 06:57:17 +02:00
|
|
|
// [GET] Current Event ID and depth suite (non-locking) (one only)
|
2018-04-19 00:04:46 +02:00
|
|
|
std::tuple<id::event::buf, int64_t, event::idx> top(std::nothrow_t, const id::room &);
|
|
|
|
std::tuple<id::event::buf, int64_t, event::idx> top(const id::room &);
|
2018-04-06 06:57:17 +02:00
|
|
|
|
|
|
|
// [GET] Current Event ID (non-locking) (one only)
|
2018-02-20 04:37:09 +01:00
|
|
|
id::event::buf head(std::nothrow_t, const id::room &);
|
2018-02-09 05:59:48 +01:00
|
|
|
id::event::buf head(const id::room &);
|
2018-04-06 06:57:17 +02:00
|
|
|
|
2018-04-19 00:09:13 +02:00
|
|
|
// [GET] Current Event idx (non-locking) (one only)
|
|
|
|
event::idx head_idx(std::nothrow_t, const id::room &);
|
|
|
|
event::idx head_idx(const id::room &);
|
|
|
|
|
2018-05-05 05:25:06 +02:00
|
|
|
// [GET] Current Event depth (non-locking)
|
2018-02-20 04:37:09 +01:00
|
|
|
int64_t depth(std::nothrow_t, const id::room &);
|
2018-04-06 06:57:17 +02:00
|
|
|
int64_t depth(const id::room &);
|
2018-02-09 05:59:48 +01:00
|
|
|
|
2018-09-17 04:37:03 +02:00
|
|
|
// [GET] Count the events in the room between two indexes.
|
2018-09-07 15:20:32 +02:00
|
|
|
size_t count_since(const room &, const m::event::idx &, const m::event::idx &);
|
|
|
|
size_t count_since(const room &, const m::event::id &, const m::event::id &);
|
|
|
|
size_t count_since(const m::event::idx &, const m::event::idx &);
|
|
|
|
size_t count_since(const m::event::id &, const m::event::id &);
|
|
|
|
|
2018-02-09 05:59:48 +01:00
|
|
|
// [SET] Lowest-level
|
2018-01-26 21:23:28 +01:00
|
|
|
event::id::buf commit(const room &, json::iov &event, const json::iov &content);
|
|
|
|
|
2018-02-09 08:18:42 +01:00
|
|
|
// [SET] Send state to room
|
2018-01-26 21:23:28 +01:00
|
|
|
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const string_view &state_key, const json::iov &content);
|
|
|
|
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const string_view &state_key, const json::members &content);
|
|
|
|
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const string_view &state_key, const json::object &content);
|
|
|
|
|
2018-02-09 08:18:42 +01:00
|
|
|
// [SET] Send non-state to room
|
2018-01-26 21:23:28 +01:00
|
|
|
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const json::iov &content);
|
|
|
|
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const json::members &content);
|
|
|
|
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const json::object &content);
|
|
|
|
|
2018-02-09 08:18:42 +01:00
|
|
|
// [SET] Convenience sends
|
2018-02-15 23:57:56 +01:00
|
|
|
event::id::buf redact(const room &, const m::id::user &sender, const m::id::event &, const string_view &reason);
|
2018-01-26 21:23:28 +01:00
|
|
|
event::id::buf message(const room &, const m::id::user &sender, const json::members &content);
|
|
|
|
event::id::buf message(const room &, const m::id::user &sender, const string_view &body, const string_view &msgtype = "m.text");
|
2018-03-03 08:08:15 +01:00
|
|
|
event::id::buf msghtml(const room &, const m::id::user &sender, const string_view &html, const string_view &alt = {}, const string_view &msgtype = "m.notice");
|
2018-03-02 12:42:16 +01:00
|
|
|
event::id::buf notice(const room &, const m::id::user &sender, const string_view &body);
|
|
|
|
event::id::buf notice(const room &, const string_view &body); // sender is @ircd
|
2018-04-03 21:56:46 +02:00
|
|
|
event::id::buf invite(const room &, const m::id::user &target, const m::id::user &sender);
|
2018-01-26 21:23:28 +01:00
|
|
|
event::id::buf leave(const room &, const m::id::user &);
|
|
|
|
event::id::buf join(const room &, const m::id::user &);
|
2018-03-27 12:00:09 +02:00
|
|
|
event::id::buf join(const id::room_alias &, const m::id::user &);
|
2018-01-26 21:23:28 +01:00
|
|
|
|
2018-02-09 08:18:42 +01:00
|
|
|
// [SET] Create new room
|
2017-11-30 19:51:01 +01:00
|
|
|
room create(const id::room &, const id::user &creator, const id::room &parent, const string_view &type);
|
|
|
|
room create(const id::room &, const id::user &creator, const string_view &type = {});
|
2017-09-08 11:32:49 +02:00
|
|
|
}
|
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
/// Interface to a room.
|
|
|
|
///
|
|
|
|
/// This is a lightweight object which uses a room_id and an optional event_id
|
|
|
|
/// to provide an interface to a matrix room. This object itself isn't the
|
|
|
|
/// actual room data since that takes the form of events in the database;
|
|
|
|
/// this is just a handle with aforementioned string_view's used by its member
|
|
|
|
/// functions.
|
|
|
|
///
|
|
|
|
/// This object allows the programmer to represent the room either at its
|
|
|
|
/// present state, or if an event_id is given, at the point of that event.
|
|
|
|
///
|
2018-02-13 23:23:56 +01:00
|
|
|
/// Many convenience functions are provided outside of this class.
|
|
|
|
/// Additionally, several sub-classes provide functionality even more specific
|
|
|
|
/// than this interface too. If a subclass is provided, for example:
|
|
|
|
/// `struct members`, such an interface may employ optimized tactics for its
|
|
|
|
/// specific task.
|
2017-12-12 21:33:14 +01:00
|
|
|
///
|
2017-09-08 11:32:49 +02:00
|
|
|
struct ircd::m::room
|
|
|
|
{
|
2018-02-11 04:50:53 +01:00
|
|
|
struct messages;
|
2017-10-25 18:47:03 +02:00
|
|
|
struct state;
|
2017-09-26 07:17:05 +02:00
|
|
|
struct members;
|
2018-02-10 09:25:20 +01:00
|
|
|
struct origins;
|
2018-05-05 05:25:44 +02:00
|
|
|
struct head;
|
2018-06-04 23:23:39 +02:00
|
|
|
struct power;
|
2017-09-08 11:32:49 +02:00
|
|
|
|
2017-09-25 03:05:42 +02:00
|
|
|
using id = m::id::room;
|
2017-12-12 21:33:14 +01:00
|
|
|
using alias = m::id::room_alias;
|
2018-04-10 04:24:12 +02:00
|
|
|
using closure = std::function<void (const room &)>;
|
|
|
|
using closure_bool = std::function<bool (const room &)>;
|
2017-09-08 11:32:49 +02:00
|
|
|
|
2017-09-25 03:05:42 +02:00
|
|
|
id room_id;
|
2017-12-12 21:33:14 +01:00
|
|
|
event::id event_id;
|
2018-05-21 05:14:12 +02:00
|
|
|
const vm::copts *copts {nullptr};
|
2018-05-20 13:35:17 +02:00
|
|
|
const event::fetch::opts *fopts {nullptr};
|
2017-09-08 11:32:49 +02:00
|
|
|
|
2018-03-06 08:39:44 +01:00
|
|
|
operator const id &() const;
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2018-04-12 11:14:10 +02:00
|
|
|
// Convenience passthru to room::messages (linear query; newest first)
|
2018-04-18 04:14:39 +02:00
|
|
|
bool for_each(const string_view &type, const event::closure_idx_bool &) const;
|
|
|
|
void for_each(const string_view &type, const event::closure_idx &) const;
|
|
|
|
bool for_each(const string_view &type, const event::id::closure_bool &) const;
|
2018-04-12 11:14:10 +02:00
|
|
|
void for_each(const string_view &type, const event::id::closure &) const;
|
2018-04-18 04:14:39 +02:00
|
|
|
bool for_each(const string_view &type, const event::closure_bool &) const;
|
2018-04-12 11:14:10 +02:00
|
|
|
void for_each(const string_view &type, const event::closure &) const;
|
2018-04-18 04:14:39 +02:00
|
|
|
bool for_each(const event::closure_idx_bool &) const;
|
|
|
|
void for_each(const event::closure_idx &) const;
|
|
|
|
bool for_each(const event::id::closure_bool &) const;
|
2018-04-12 11:14:10 +02:00
|
|
|
void for_each(const event::id::closure &) const;
|
2018-04-18 04:14:39 +02:00
|
|
|
bool for_each(const event::closure_bool &) const;
|
2018-04-12 11:14:10 +02:00
|
|
|
void for_each(const event::closure &) const;
|
|
|
|
|
2018-02-11 02:57:22 +01:00
|
|
|
// Convenience passthru to room::state (logarithmic query)
|
2018-02-11 06:42:16 +01:00
|
|
|
bool has(const string_view &type, const string_view &state_key) const;
|
2018-02-11 02:57:22 +01:00
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure &) const;
|
|
|
|
void get(const string_view &type, const string_view &state_key, const event::closure &) const;
|
|
|
|
|
2018-02-16 04:17:09 +01:00
|
|
|
// Convenience passthru to room::messages (linear query)
|
|
|
|
bool get(std::nothrow_t, const string_view &type, const event::closure &) const;
|
|
|
|
void get(const string_view &type, const event::closure &) const;
|
|
|
|
bool has(const string_view &type) const;
|
|
|
|
|
2018-10-26 01:50:25 +02:00
|
|
|
// misc / convenience utils
|
2017-11-30 19:51:01 +01:00
|
|
|
bool membership(const m::id::user &, const string_view &membership = "join") const;
|
2018-03-01 06:05:09 +01:00
|
|
|
string_view membership(const mutable_buffer &out, const m::id::user &) const;
|
2018-05-31 13:21:54 +02:00
|
|
|
bool visible(const string_view &mxid, const m::event *const & = nullptr) const;
|
2018-10-26 01:50:25 +02:00
|
|
|
string_view join_rule(const mutable_buffer &out) const;
|
|
|
|
bool join_rule(const string_view &rule) const;
|
2018-07-01 03:48:43 +02:00
|
|
|
bool lonly() const;
|
2017-10-03 13:12:54 +02:00
|
|
|
|
2018-05-20 13:35:17 +02:00
|
|
|
room(const id &room_id,
|
|
|
|
const string_view &event_id,
|
2018-05-21 05:14:12 +02:00
|
|
|
const vm::copts *const &copts = nullptr,
|
2018-05-20 13:35:17 +02:00
|
|
|
const event::fetch::opts *const &fopts = nullptr)
|
2018-03-04 08:37:40 +01:00
|
|
|
:room_id{room_id}
|
|
|
|
,event_id{event_id? event::id{event_id} : event::id{}}
|
2018-05-21 05:14:12 +02:00
|
|
|
,copts{copts}
|
2018-05-20 13:35:17 +02:00
|
|
|
,fopts{fopts}
|
2018-03-04 08:37:40 +01:00
|
|
|
{}
|
|
|
|
|
2018-05-20 13:35:17 +02:00
|
|
|
room(const id &room_id,
|
2018-05-21 05:14:12 +02:00
|
|
|
const vm::copts *const &copts = nullptr,
|
2018-05-20 13:35:17 +02:00
|
|
|
const event::fetch::opts *const &fopts = nullptr)
|
2017-09-25 03:05:42 +02:00
|
|
|
:room_id{room_id}
|
2018-05-21 05:14:12 +02:00
|
|
|
,copts{copts}
|
2018-05-20 13:35:17 +02:00
|
|
|
,fopts{fopts}
|
2017-12-12 21:33:14 +01:00
|
|
|
{}
|
2018-02-15 21:11:28 +01:00
|
|
|
|
|
|
|
room() = default;
|
2017-12-12 21:33:14 +01:00
|
|
|
};
|
|
|
|
|
2018-02-11 04:50:53 +01:00
|
|
|
/// Interface to room messages
|
|
|
|
///
|
2018-02-13 23:25:01 +01:00
|
|
|
/// This interface has the form of an STL-style iterator over room messages
|
|
|
|
/// which are state and non-state events from all integrated timelines.
|
|
|
|
/// Moving the iterator is cheap, but the dereference operators fetch a
|
2018-04-18 04:14:39 +02:00
|
|
|
/// full event. One can iterate just event_idx's by using event_idx() instead
|
2018-02-13 23:25:01 +01:00
|
|
|
/// of the dereference operators.
|
2018-02-11 04:50:53 +01:00
|
|
|
///
|
|
|
|
struct ircd::m::room::messages
|
|
|
|
{
|
|
|
|
m::room room;
|
2018-02-13 23:25:01 +01:00
|
|
|
db::index::const_iterator it;
|
2018-04-18 04:14:39 +02:00
|
|
|
event::idx _event_idx;
|
2018-02-13 23:25:01 +01:00
|
|
|
event::fetch _event;
|
2018-02-11 04:50:53 +01:00
|
|
|
|
2018-02-13 23:25:01 +01:00
|
|
|
public:
|
|
|
|
operator bool() const { return bool(it); }
|
|
|
|
bool operator!() const { return !it; }
|
2018-02-11 04:50:53 +01:00
|
|
|
|
2018-04-18 04:14:39 +02:00
|
|
|
event::id::buf event_id(); // deprecated; will remove
|
|
|
|
const event::idx &event_idx();
|
2018-04-27 05:25:00 +02:00
|
|
|
string_view state_root() const;
|
2018-03-09 04:01:38 +01:00
|
|
|
|
2018-02-13 23:25:01 +01:00
|
|
|
const m::event &fetch(std::nothrow_t);
|
|
|
|
const m::event &fetch();
|
2018-02-11 04:50:53 +01:00
|
|
|
|
2018-09-07 15:19:21 +02:00
|
|
|
bool seek_idx(const event::idx &);
|
2018-02-13 23:25:01 +01:00
|
|
|
bool seek(const uint64_t &depth);
|
|
|
|
bool seek(const event::id &);
|
|
|
|
bool seek();
|
|
|
|
|
|
|
|
// These are reversed on purpose
|
|
|
|
auto &operator++() { return --it; }
|
|
|
|
auto &operator--() { return ++it; }
|
|
|
|
|
|
|
|
const m::event &operator*();
|
|
|
|
const m::event *operator->() { return &operator*(); }
|
|
|
|
|
2018-05-22 02:36:16 +02:00
|
|
|
messages(const m::room &room,
|
|
|
|
const uint64_t &depth,
|
|
|
|
const event::fetch::opts *const & = nullptr);
|
|
|
|
|
|
|
|
messages(const m::room &room,
|
|
|
|
const event::id &,
|
|
|
|
const event::fetch::opts *const & = nullptr);
|
|
|
|
|
|
|
|
messages(const m::room &room,
|
|
|
|
const event::fetch::opts *const & = nullptr);
|
|
|
|
|
2018-02-15 21:11:28 +01:00
|
|
|
messages() = default;
|
|
|
|
messages(const messages &) = delete;
|
|
|
|
messages &operator=(const messages &) = delete;
|
2018-02-11 04:50:53 +01:00
|
|
|
};
|
|
|
|
|
2018-02-10 09:25:20 +01:00
|
|
|
/// Interface to room state.
|
|
|
|
///
|
2018-02-11 04:50:53 +01:00
|
|
|
/// This interface focuses specifically on the details of room state. Most of
|
2018-05-05 05:25:06 +02:00
|
|
|
/// the queries to this interface respond in logarithmic time. If an event with
|
|
|
|
/// a state_key is present in room::messages but it is not present in
|
|
|
|
/// room::state (state tree) it was accepted into the room but we will not
|
|
|
|
/// apply it to our machine, though other parties may (this is a
|
|
|
|
/// state-conflict).
|
2018-02-10 09:25:20 +01:00
|
|
|
///
|
|
|
|
struct ircd::m::room::state
|
|
|
|
{
|
2018-03-04 09:12:13 +01:00
|
|
|
struct opts;
|
2018-02-10 09:25:20 +01:00
|
|
|
|
2018-04-10 04:24:56 +02:00
|
|
|
using keys = std::function<void (const string_view &)>;
|
|
|
|
using keys_bool = std::function<bool (const string_view &)>;
|
2018-09-26 01:02:19 +02:00
|
|
|
using types = std::function<void (const string_view &)>;
|
|
|
|
using types_bool = std::function<bool (const string_view &)>;
|
2018-04-10 04:24:56 +02:00
|
|
|
|
2018-11-03 04:04:17 +01:00
|
|
|
static conf::item<bool> disable_history;
|
2018-11-03 04:05:11 +01:00
|
|
|
static conf::item<size_t> readahead_size;
|
2018-11-03 04:04:17 +01:00
|
|
|
|
2018-02-11 02:34:16 +01:00
|
|
|
room::id room_id;
|
|
|
|
event::id::buf event_id;
|
|
|
|
m::state::id_buffer root_id_buf;
|
|
|
|
m::state::id root_id;
|
2018-05-20 13:35:17 +02:00
|
|
|
const event::fetch::opts *fopts {nullptr};
|
2018-10-26 00:37:35 +02:00
|
|
|
mutable bool _not_present {false}; // cached result of !present()
|
2018-02-10 09:25:20 +01:00
|
|
|
|
2018-05-05 12:35:44 +02:00
|
|
|
bool present() const;
|
|
|
|
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const types_bool &) const;
|
|
|
|
void for_each(const types &) const;
|
|
|
|
bool for_each(const string_view &type, const keys_bool &view) const;
|
2018-04-10 04:24:56 +02:00
|
|
|
void for_each(const string_view &type, const keys &) const;
|
2018-10-23 23:16:36 +02:00
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const keys_bool &view) const;
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const event::closure_idx_bool &view) const;
|
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const event::id::closure_bool &view) const;
|
|
|
|
bool for_each(const string_view &type, const string_view &lower_bound, const event::closure_bool &view) const;
|
|
|
|
bool for_each(const string_view &type, const event::closure_idx_bool &view) const;
|
2018-04-18 04:14:39 +02:00
|
|
|
void for_each(const string_view &type, const event::closure_idx &) const;
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const string_view &type, const event::id::closure_bool &view) const;
|
2018-02-10 09:25:20 +01:00
|
|
|
void for_each(const string_view &type, const event::id::closure &) const;
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const string_view &type, const event::closure_bool &view) const;
|
2018-02-10 09:25:20 +01:00
|
|
|
void for_each(const string_view &type, const event::closure &) const;
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const event::closure_idx_bool &view) const;
|
2018-04-18 04:14:39 +02:00
|
|
|
void for_each(const event::closure_idx &) const;
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const event::id::closure_bool &view) const;
|
2018-02-10 09:25:20 +01:00
|
|
|
void for_each(const event::id::closure &) const;
|
2018-09-26 01:02:19 +02:00
|
|
|
bool for_each(const event::closure_bool &view) const;
|
2018-02-10 09:25:20 +01:00
|
|
|
void for_each(const event::closure &) const;
|
|
|
|
|
2018-02-25 04:52:02 +01:00
|
|
|
// Counting / Statistics
|
|
|
|
size_t count(const string_view &type) const;
|
|
|
|
size_t count() const;
|
|
|
|
|
2018-02-10 09:25:20 +01:00
|
|
|
// Existential
|
|
|
|
bool has(const string_view &type, const string_view &state_key) const;
|
|
|
|
bool has(const string_view &type) const;
|
|
|
|
|
|
|
|
// Fetch a state event
|
2018-04-18 04:14:39 +02:00
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure_idx &) const;
|
2018-02-10 09:25:20 +01:00
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::id::closure &) const;
|
|
|
|
bool get(std::nothrow_t, const string_view &type, const string_view &state_key, const event::closure &) const;
|
2018-04-18 04:14:39 +02:00
|
|
|
void get(const string_view &type, const string_view &state_key, const event::closure_idx &) const;
|
2018-02-10 09:25:20 +01:00
|
|
|
void get(const string_view &type, const string_view &state_key, const event::id::closure &) const;
|
|
|
|
void get(const string_view &type, const string_view &state_key, const event::closure &) const;
|
|
|
|
|
2018-04-05 02:06:58 +02:00
|
|
|
// Fetch and return state event id
|
|
|
|
event::id::buf get(std::nothrow_t, const string_view &type, const string_view &state_key = "") const;
|
|
|
|
event::id::buf get(const string_view &type, const string_view &state_key = "") const;
|
|
|
|
|
2018-10-23 18:54:45 +02:00
|
|
|
// Initiate a database prefetch on the state to cache for future access.
|
|
|
|
size_t prefetch(const string_view &type, const event::idx &start = 0, const event::idx &stop = 0) const;
|
|
|
|
size_t prefetch(const event::idx &start = 0, const event::idx &stop = 0) const;
|
|
|
|
|
2018-05-22 02:36:16 +02:00
|
|
|
state(const m::room &room, const event::fetch::opts *const & = nullptr);
|
2018-02-15 21:11:28 +01:00
|
|
|
state() = default;
|
|
|
|
state(const state &) = delete;
|
|
|
|
state &operator=(const state &) = delete;
|
2018-02-10 09:25:20 +01:00
|
|
|
};
|
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
/// Interface to the members of a room.
|
|
|
|
///
|
|
|
|
/// This interface focuses specifically on room membership and its routines
|
|
|
|
/// are optimized for this area of room functionality.
|
|
|
|
///
|
|
|
|
struct ircd::m::room::members
|
|
|
|
{
|
2018-04-12 23:10:03 +02:00
|
|
|
using closure = std::function<void (const id::user &)>;
|
|
|
|
using closure_bool = std::function<bool (const id::user &)>;
|
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
m::room room;
|
|
|
|
|
2018-09-26 01:16:47 +02:00
|
|
|
bool for_each(const string_view &membership, const event::closure_bool &) const;
|
2018-04-12 23:10:03 +02:00
|
|
|
void for_each(const string_view &membership, const event::closure &) const;
|
|
|
|
bool for_each(const string_view &membership, const closure_bool &) const;
|
|
|
|
void for_each(const string_view &membership, const closure &) const;
|
2018-09-26 01:16:47 +02:00
|
|
|
bool for_each(const event::closure_bool &) const;
|
2018-04-12 23:10:03 +02:00
|
|
|
void for_each(const event::closure &) const;
|
|
|
|
bool for_each(const closure_bool &) const;
|
|
|
|
void for_each(const closure &) const;
|
2017-12-12 21:33:14 +01:00
|
|
|
|
2018-09-26 01:16:47 +02:00
|
|
|
size_t count(const string_view &membership) const;
|
|
|
|
size_t count() const;
|
|
|
|
|
2018-02-15 21:11:28 +01:00
|
|
|
members(const m::room &room)
|
2017-12-12 21:33:14 +01:00
|
|
|
:room{room}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2018-02-10 09:25:20 +01:00
|
|
|
/// Interface to the origins (autonomous systems) of a room
|
2017-12-12 21:33:14 +01:00
|
|
|
///
|
2018-02-10 09:25:20 +01:00
|
|
|
/// This interface focuses specifically on the origins (from the field in the
|
|
|
|
/// event object) which are servers/networks/autonomous systems, or something.
|
|
|
|
/// Messages have to be sent to them, and an efficient iteration of the
|
|
|
|
/// origins as provided by this interface helps with that.
|
2017-12-12 21:33:14 +01:00
|
|
|
///
|
2018-02-10 09:25:20 +01:00
|
|
|
struct ircd::m::room::origins
|
2017-12-12 21:33:14 +01:00
|
|
|
{
|
|
|
|
using closure = std::function<void (const string_view &)>;
|
|
|
|
using closure_bool = std::function<bool (const string_view &)>;
|
|
|
|
|
|
|
|
m::room room;
|
|
|
|
|
2018-09-26 01:16:47 +02:00
|
|
|
bool _for_each_(const closure_bool &view) const;
|
2018-08-23 02:42:35 +02:00
|
|
|
bool for_each(const closure_bool &view) const;
|
2018-02-10 22:03:13 +01:00
|
|
|
void for_each(const closure &view) const;
|
2018-04-03 21:49:34 +02:00
|
|
|
bool has(const string_view &origin) const;
|
2018-07-01 06:55:01 +02:00
|
|
|
bool only(const string_view &origin) const;
|
2018-03-03 14:56:42 +01:00
|
|
|
size_t count() const;
|
2017-12-12 21:33:14 +01:00
|
|
|
|
2018-08-24 13:14:24 +02:00
|
|
|
// select an origin in the room at random; use proffer to refuse and try another.
|
|
|
|
string_view random(const mutable_buffer &buf, const closure_bool &proffer = nullptr) const;
|
|
|
|
bool random(const closure &, const closure_bool &proffer = nullptr) const;
|
|
|
|
|
2018-02-15 21:11:28 +01:00
|
|
|
origins(const m::room &room)
|
2017-12-12 21:33:14 +01:00
|
|
|
:room{room}
|
2017-09-25 03:05:42 +02:00
|
|
|
{}
|
2017-09-08 11:32:49 +02:00
|
|
|
};
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2018-05-05 05:25:44 +02:00
|
|
|
/// Interface to the room head
|
|
|
|
///
|
|
|
|
/// This interface helps compute and represent aspects of the room graph,
|
|
|
|
/// specifically concerning the "head" or the "front" or the "top" of this
|
|
|
|
/// graph where events are either furthest from the m.room.create genesis,
|
|
|
|
/// or are yet unreferenced by another event. Usage of this interface is
|
|
|
|
/// fundamental when composing the references of a new event on the graph.
|
|
|
|
///
|
|
|
|
struct ircd::m::room::head
|
|
|
|
{
|
|
|
|
using closure = std::function<void (const event::idx &, const event::id &)>;
|
|
|
|
using closure_bool = std::function<bool (const event::idx &, const event::id &)>;
|
|
|
|
|
|
|
|
m::room room;
|
|
|
|
|
|
|
|
bool for_each(const closure_bool &) const;
|
|
|
|
void for_each(const closure &) const;
|
2018-05-05 11:12:48 +02:00
|
|
|
bool has(const event::id &) const;
|
2018-05-05 05:25:44 +02:00
|
|
|
size_t count() const;
|
|
|
|
|
|
|
|
head(const m::room &room)
|
|
|
|
:room{room}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2018-06-04 23:23:39 +02:00
|
|
|
/// Interface to the power levels
|
|
|
|
///
|
|
|
|
/// This interface focuses specifically on making the power levels accessible
|
|
|
|
/// to developers for common query and manipulation operations. power_levels
|
|
|
|
/// is a single state event in the room containing integer thresholds for
|
|
|
|
/// privileges in the room in addition to a list of users mapping to an integer
|
|
|
|
/// for their level. This interface hides the details of that event by
|
|
|
|
/// presenting single operations which can appear succinctly in IRCd code.
|
|
|
|
///
|
|
|
|
struct ircd::m::room::power
|
|
|
|
{
|
|
|
|
using closure = std::function<void (const string_view &, const int64_t &)>;
|
|
|
|
using closure_bool = std::function<bool (const string_view &, const int64_t &)>;
|
|
|
|
|
2018-10-26 01:28:30 +02:00
|
|
|
static const int64_t default_creator_level;
|
2018-06-04 23:23:39 +02:00
|
|
|
static const int64_t default_power_level;
|
|
|
|
static const int64_t default_event_level;
|
|
|
|
static const int64_t default_user_level;
|
|
|
|
|
|
|
|
m::room room;
|
|
|
|
m::room::state state;
|
|
|
|
|
|
|
|
bool view(const std::function<void (const json::object &)> &) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
// Iterate a collection usually either "events" or "users" as per spec.
|
|
|
|
bool for_each(const string_view &prop, const closure_bool &) const;
|
|
|
|
void for_each(const string_view &prop, const closure &) const;
|
|
|
|
|
|
|
|
// Iterates all of the integer levels, excludes the collections.
|
|
|
|
bool for_each(const closure_bool &) const;
|
|
|
|
void for_each(const closure &) const;
|
|
|
|
|
|
|
|
bool has_level(const string_view &prop) const;
|
|
|
|
bool has_collection(const string_view &prop) const;
|
|
|
|
bool has_event(const string_view &type) const;
|
|
|
|
bool has_user(const m::id::user &) const;
|
|
|
|
|
|
|
|
size_t count(const string_view &prop) const;
|
|
|
|
size_t count_collections() const;
|
|
|
|
size_t count_levels() const;
|
|
|
|
|
|
|
|
// This suite queries with full defaulting logic as per the spec. These
|
2018-10-27 23:27:53 +02:00
|
|
|
// always return suitable results. When determining power to change a state
|
|
|
|
// event rather than a non-state event, the state_key must always be
|
|
|
|
// defined. If the state_key is a default constructed string_view{} (which
|
|
|
|
// means !defined(state_key) and is not the same as string_view{""} for
|
|
|
|
// the common state_key="") then the interface considers your query for
|
|
|
|
// a non-state event rather than a state_event. Be careful.
|
2018-06-04 23:23:39 +02:00
|
|
|
int64_t level(const string_view &prop) const;
|
2018-10-27 23:27:53 +02:00
|
|
|
int64_t level_event(const string_view &type, const string_view &state_key) const;
|
2018-06-04 23:23:39 +02:00
|
|
|
int64_t level_event(const string_view &type) const;
|
|
|
|
int64_t level_user(const m::id::user &) const;
|
|
|
|
|
|
|
|
// all who attain great power and riches make use of either force or fraud"
|
2018-10-26 02:49:11 +02:00
|
|
|
bool operator()(const m::id::user &, const string_view &prop, const string_view &type = {}, const string_view &state_key = {}) const;
|
2018-06-04 23:23:39 +02:00
|
|
|
|
|
|
|
power(const m::room &room)
|
|
|
|
:room{room}
|
|
|
|
,state{room}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2018-03-06 08:39:44 +01:00
|
|
|
inline ircd::m::room::operator
|
|
|
|
const ircd::m::room::id &()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return room_id;
|
|
|
|
}
|