2017-09-08 11:32:49 +02:00
|
|
|
/*
|
|
|
|
* charybdis: 21st Century IRC++d
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Charybdis Development Team
|
|
|
|
* Copyright (C) 2016 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
bool my(const room &);
|
2017-11-30 19:51:01 +01:00
|
|
|
bool exists(const id::room &);
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
event::id::buf send(room, const m::id::user &sender, const string_view &type, const json::iov &content);
|
|
|
|
event::id::buf send(room, const m::id::user &sender, const string_view &type, const json::members &content);
|
|
|
|
event::id::buf send(room, const m::id::user &sender, const string_view &type, const string_view &state_key, const json::iov &content);
|
|
|
|
event::id::buf send(room, const m::id::user &sender, const string_view &type, const string_view &state_key, const json::members &content);
|
2017-11-30 19:51:01 +01:00
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
event::id::buf message(room, const m::id::user &sender, const json::members &content);
|
|
|
|
event::id::buf message(room, const m::id::user &sender, const string_view &body, const string_view &msgtype = "m.text");
|
|
|
|
event::id::buf membership(room, const m::id::user &, const string_view &membership);
|
|
|
|
event::id::buf leave(room, const m::id::user &);
|
|
|
|
event::id::buf join(room, const m::id::user &);
|
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.
|
|
|
|
///
|
|
|
|
/// Many convenience functions are provided outside of this class to
|
|
|
|
/// accomplish general tasks using rooms in one statement. 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-09-08 11:32:49 +02:00
|
|
|
struct ircd::m::room
|
|
|
|
{
|
2017-10-25 18:47:03 +02:00
|
|
|
struct state;
|
2017-09-26 07:17:05 +02:00
|
|
|
struct members;
|
2017-10-25 18:47:03 +02:00
|
|
|
struct fetch;
|
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;
|
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;
|
2017-09-08 11:32:49 +02:00
|
|
|
|
2017-11-16 02:48:25 +01:00
|
|
|
operator const id &() const { return room_id; }
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2017-11-30 19:51:01 +01:00
|
|
|
// observer
|
|
|
|
void for_each(const string_view &type, const event::closure &view) const;
|
2017-12-12 21:33:14 +01:00
|
|
|
bool test(const string_view &type, const event::closure_bool &view) const;
|
2017-11-30 19:51:01 +01:00
|
|
|
bool has(const string_view &type, const string_view &state_key) const;
|
|
|
|
bool has(const string_view &type) const;
|
2017-12-12 21:33:14 +01:00
|
|
|
|
2017-11-30 19:51:01 +01:00
|
|
|
bool get(const string_view &type, const string_view &state_key, const event::closure &) const;
|
|
|
|
bool get(const string_view &type, const event::closure &view) const;
|
2017-12-12 21:33:14 +01:00
|
|
|
bool get(const event::closure &view) const;
|
|
|
|
|
|
|
|
bool prev(const string_view &type, const string_view &state_key, const event::closure &) const;
|
|
|
|
bool prev(const string_view &type, const event::closure &view) const;
|
|
|
|
bool prev(const event::closure &view) const;
|
2017-10-25 18:47:03 +02:00
|
|
|
|
2017-11-30 19:51:01 +01:00
|
|
|
// observer misc
|
|
|
|
bool membership(const m::id::user &, const string_view &membership = "join") const;
|
2017-10-25 18:47:03 +02:00
|
|
|
uint64_t maxdepth(event::id::buf &) const;
|
|
|
|
uint64_t maxdepth() const;
|
2017-10-03 13:12:54 +02:00
|
|
|
|
2017-11-30 19:51:01 +01:00
|
|
|
// modify
|
2017-09-26 06:42:07 +02:00
|
|
|
event::id::buf send(json::iov &event);
|
2017-11-30 19:51:01 +01:00
|
|
|
event::id::buf send(json::iov &event, const json::iov &content);
|
|
|
|
event::id::buf message(json::iov &event, const json::iov &content);
|
2017-09-08 11:32:49 +02:00
|
|
|
|
2017-12-12 21:33:14 +01:00
|
|
|
room(const alias &, const event::id &event_id = {});
|
|
|
|
room(const id &room_id, const event::id &event_id = {})
|
2017-09-25 03:05:42 +02:00
|
|
|
:room_id{room_id}
|
2017-12-12 21:33:14 +01:00
|
|
|
,event_id{event_id}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// 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
|
|
|
|
{
|
|
|
|
struct origins;
|
|
|
|
|
|
|
|
m::room room;
|
|
|
|
|
|
|
|
bool until(const string_view &membership, const event::closure_bool &view) const;
|
|
|
|
bool until(const event::closure_bool &view) const;
|
|
|
|
|
|
|
|
members(m::room room)
|
|
|
|
:room{room}
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Interface to the origins of members of a room
|
|
|
|
///
|
|
|
|
/// This interface focuses even more specifically on the servers (origins) for
|
|
|
|
/// the members of a room. As multiple users from the same origin may be
|
|
|
|
/// members of a room -- all in different membership states etc -- this
|
|
|
|
/// interface distills that fact away from what would otherwise burden users
|
|
|
|
/// of the more general room::members interface.
|
|
|
|
///
|
|
|
|
struct ircd::m::room::members::origins
|
|
|
|
{
|
|
|
|
using closure = std::function<void (const string_view &)>;
|
|
|
|
using closure_bool = std::function<bool (const string_view &)>;
|
|
|
|
|
|
|
|
m::room room;
|
|
|
|
|
|
|
|
bool until(const closure_bool &view) const;
|
|
|
|
|
|
|
|
origins(m::room room)
|
|
|
|
: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
|
|
|
|
|
|
|
namespace ircd::m::name
|
|
|
|
{
|
|
|
|
constexpr const char *const m_room_aliases {"m.room.aliases"};
|
|
|
|
constexpr const char *const m_room_canonical_alias {"m.room.canonical_alias"};
|
|
|
|
constexpr const char *const m_room_create {"m.room.create"};
|
|
|
|
constexpr const char *const m_room_join_rules {"m.room.join_rules"};
|
|
|
|
constexpr const char *const m_room_member {"m.room.member"};
|
|
|
|
constexpr const char *const m_room_power_levels {"m.room.power_levels"};
|
|
|
|
constexpr const char *const m_room_message {"m.room.message"};
|
|
|
|
constexpr const char *const m_room_name {"m.room.name"};
|
|
|
|
constexpr const char *const m_room_topic {"m.room.topic"};
|
|
|
|
constexpr const char *const m_room_avatar {"m.room.avatar"};
|
2017-11-16 02:48:25 +01:00
|
|
|
constexpr const char *const m_room_pinned_events {"m.room.pinned_events"};
|
|
|
|
constexpr const char *const m_room_history_visibility {"m.room.history_visibility"};
|
|
|
|
constexpr const char *const m_room_third_party_invite {"m.room.third_party_invite"};
|
|
|
|
constexpr const char *const m_room_guest_access {"m.room.guest_access"};
|
2017-10-25 18:47:03 +02:00
|
|
|
}
|
|
|
|
|
2017-11-16 02:48:25 +01:00
|
|
|
/// Tuple to represent fundamental room state singletons (state_key = "")
|
|
|
|
///
|
|
|
|
/// This is not a complete representation of room state. Missing from here
|
|
|
|
/// are any state events with a state_key which is not an empty string. When
|
|
|
|
/// the state_key is not "", multiple events of that type contribute to the
|
|
|
|
/// room's eigenvalue. Additionally, state events which are not related to
|
|
|
|
/// the matrix protocol `m.room.*` are not represented here.
|
|
|
|
///
|
|
|
|
/// NOTE that in C++-land state_key="" is represented as a valid but empty
|
|
|
|
/// character pointer. It is not a string containing "". Testing for a
|
|
|
|
/// "" state_key `ircd::defined(string_view) && ircd::empty(string_view)`
|
|
|
|
/// analogous to `data() && !*data()`. A default constructed string_view{}
|
|
|
|
/// is considered "JS undefined" because the character pointers are null.
|
|
|
|
/// A "JS null" is rarer and carried with a hack which will not be discussed
|
|
|
|
/// here.
|
|
|
|
///
|
2017-10-25 18:47:03 +02:00
|
|
|
struct ircd::m::room::state
|
|
|
|
:json::tuple
|
|
|
|
<
|
|
|
|
json::property<m::name::m_room_aliases, event>,
|
|
|
|
json::property<m::name::m_room_canonical_alias, event>,
|
|
|
|
json::property<m::name::m_room_create, event>,
|
|
|
|
json::property<m::name::m_room_join_rules, event>,
|
|
|
|
json::property<m::name::m_room_power_levels, event>,
|
|
|
|
json::property<m::name::m_room_message, event>,
|
|
|
|
json::property<m::name::m_room_name, event>,
|
|
|
|
json::property<m::name::m_room_topic, event>,
|
2017-11-16 02:48:25 +01:00
|
|
|
json::property<m::name::m_room_avatar, event>,
|
|
|
|
json::property<m::name::m_room_pinned_events, event>,
|
|
|
|
json::property<m::name::m_room_history_visibility, event>,
|
|
|
|
json::property<m::name::m_room_third_party_invite, event>,
|
|
|
|
json::property<m::name::m_room_guest_access, event>
|
2017-10-25 18:47:03 +02:00
|
|
|
>
|
|
|
|
{
|
|
|
|
struct fetch;
|
2017-11-16 02:48:25 +01:00
|
|
|
|
|
|
|
using super_type::tuple;
|
|
|
|
|
|
|
|
state(const json::array &pdus);
|
|
|
|
state(fetch &);
|
|
|
|
state(const room::id &, const event::id &, const mutable_buffer &);
|
|
|
|
state() = default;
|
|
|
|
using super_type::operator=;
|
|
|
|
|
|
|
|
friend std::string pretty(const room::state &);
|
|
|
|
friend std::string pretty_oneline(const room::state &);
|
|
|
|
};
|
|
|
|
|
2017-10-25 18:47:03 +02:00
|
|
|
#pragma GCC diagnostic pop
|