0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 08:23:56 +01:00

ircd:Ⓜ️ Remove the room::state::tuple contraption.

This commit is contained in:
Jason Volk 2018-09-13 07:53:51 -07:00
parent a2160443ca
commit 08d9f2c606
2 changed files with 0 additions and 137 deletions

View file

@ -243,7 +243,6 @@ struct ircd::m::room::messages
///
struct ircd::m::room::state
{
struct tuple;
struct opts;
using keys = std::function<void (const string_view &)>;
@ -449,53 +448,6 @@ struct ircd::m::room::power
{}
};
/// 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.
///
struct ircd::m::room::state::tuple
:json::tuple
<
json::property<name::m_room_aliases, event>,
json::property<name::m_room_canonical_alias, event>,
json::property<name::m_room_create, event>,
json::property<name::m_room_join_rules, event>,
json::property<name::m_room_power_levels, event>,
json::property<name::m_room_message, event>,
json::property<name::m_room_name, event>,
json::property<name::m_room_topic, event>,
json::property<name::m_room_avatar, event>,
json::property<name::m_room_pinned_events, event>,
json::property<name::m_room_history_visibility, event>,
json::property<name::m_room_third_party_invite, event>,
json::property<name::m_room_guest_access, event>
>
{
using super_type::tuple;
tuple(const json::array &pdus);
tuple(const m::room &, const mutable_buffer &);
tuple() = default;
using super_type::operator=;
friend std::string pretty(const room::state::tuple &);
friend std::string pretty_oneline(const room::state::tuple &);
};
#pragma GCC diagnostic pop
inline ircd::m::room::operator
const ircd::m::room::id &()
const

View file

@ -2371,92 +2371,3 @@ const
closure(json::get<"content"_>(event));
});
}
//
// room::state::tuple
//
ircd::m::room::state::tuple::tuple(const m::room &room,
const mutable_buffer &buf_)
{
const m::room::state state
{
room
};
window_buffer buf{buf_};
json::for_each(*this, [&state, &buf]
(const string_view &type, auto &event)
{
state.get(std::nothrow, type, "", [&buf, &event]
(const event::idx &event_idx)
{
buf([&event, &event_idx]
(const mutable_buffer &buf)
{
event = m::event
{
event_idx, buf
};
return serialized(event);
});
});
});
}
ircd::m::room::state::tuple::tuple(const json::array &pdus)
{
for(const json::object &pdu : pdus)
{
const m::event &event{pdu};
json::set(*this, at<"type"_>(event), event);
}
}
std::string
ircd::m::pretty(const room::state::tuple &state)
{
std::string ret;
std::stringstream s;
pubsetbuf(s, ret, 2048);
const auto out{[&s]
(const string_view &key, const auto &event)
{
if(!json::get<"event_id"_>(event))
return;
s << std::setw(28) << std::right << key
<< " :" << json::get<"depth"_>(event)
<< " " << at<"event_id"_>(event)
<< " " << json::get<"sender"_>(event)
<< " " << json::get<"content"_>(event)
<< std::endl;
}};
json::for_each(state, out);
resizebuf(s, ret);
return ret;
}
std::string
ircd::m::pretty_oneline(const room::state::tuple &state)
{
std::string ret;
std::stringstream s;
pubsetbuf(s, ret, 1024);
const auto out{[&s]
(const string_view &key, const auto &event)
{
if(!json::get<"event_id"_>(event))
return;
s << key << " ";
}};
json::for_each(state, out);
resizebuf(s, ret);
return ret;
}