mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd:Ⓜ️ Add redacts
to main event; add redact(room, ...) committer.
This commit is contained in:
parent
2921692571
commit
01251573bc
8 changed files with 54 additions and 0 deletions
|
@ -38,6 +38,7 @@ origin
|
|||
origin_server_ts
|
||||
prev_events
|
||||
prev_state
|
||||
redacts
|
||||
room_id
|
||||
sender
|
||||
signatures
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace ircd::m::dbs::desc
|
|||
extern const database::descriptor events_origin_server_ts;
|
||||
extern const database::descriptor events_prev_events;
|
||||
extern const database::descriptor events_prev_state;
|
||||
extern const database::descriptor events_redacts;
|
||||
extern const database::descriptor events_room_id;
|
||||
extern const database::descriptor events_sender;
|
||||
extern const database::descriptor events_signatures;
|
||||
|
|
|
@ -54,6 +54,7 @@ struct ircd::m::event
|
|||
json::property<name::origin_server_ts, time_t>,
|
||||
json::property<name::prev_events, json::array>,
|
||||
json::property<name::prev_state, json::array>,
|
||||
json::property<name::redacts, json::string>,
|
||||
json::property<name::room_id, json::string>,
|
||||
json::property<name::sender, json::string>,
|
||||
json::property<name::signatures, json::object>,
|
||||
|
|
|
@ -35,6 +35,7 @@ namespace ircd::m::name
|
|||
constexpr const char *const origin_server_ts {"origin_server_ts"};
|
||||
constexpr const char *const prev_events {"prev_events"};
|
||||
constexpr const char *const prev_state {"prev_state"};
|
||||
constexpr const char *const redacts {"redacts"};
|
||||
constexpr const char *const room_id {"room_id"};
|
||||
constexpr const char *const sender {"sender"};
|
||||
constexpr const char *const signatures {"signatures"};
|
||||
|
|
|
@ -46,6 +46,7 @@ namespace ircd::m
|
|||
event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const json::object &content);
|
||||
|
||||
// [SET] Convenience sends
|
||||
event::id::buf redact(const room &, const m::id::user &sender, const m::id::event &, const string_view &reason);
|
||||
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");
|
||||
event::id::buf membership(const room &, const m::id::user &, const string_view &membership);
|
||||
|
|
|
@ -565,6 +565,26 @@ ircd::m::dbs::desc::events_content
|
|||
}
|
||||
};
|
||||
|
||||
const ircd::database::descriptor
|
||||
ircd::m::dbs::desc::events_redacts
|
||||
{
|
||||
// name
|
||||
"redacts",
|
||||
|
||||
// explanation
|
||||
R"(### protocol note:
|
||||
|
||||
### developer note:
|
||||
key is event_id
|
||||
value is targeted event_id
|
||||
)",
|
||||
|
||||
// typing (key, value)
|
||||
{
|
||||
typeid(ircd::string_view), typeid(ircd::string_view)
|
||||
}
|
||||
};
|
||||
|
||||
const ircd::database::descriptor
|
||||
ircd::m::dbs::desc::events_room_id
|
||||
{
|
||||
|
@ -1104,6 +1124,7 @@ ircd::m::dbs::desc::events
|
|||
events_origin_server_ts,
|
||||
events_prev_events,
|
||||
events_prev_state,
|
||||
events_redacts,
|
||||
events_room_id,
|
||||
events_sender,
|
||||
events_signatures,
|
||||
|
|
|
@ -165,6 +165,7 @@ ircd::m::pretty(const event &event)
|
|||
"depth",
|
||||
"state_key",
|
||||
"membership",
|
||||
"redacts",
|
||||
};
|
||||
|
||||
json::for_each(event, top_keys, out);
|
||||
|
@ -295,6 +296,7 @@ ircd::m::pretty_oneline(const event &event)
|
|||
s << "*" << " ";
|
||||
|
||||
out("membership", json::get<"membership"_>(event));
|
||||
out("redacts", json::get<"redacts"_>(event));
|
||||
|
||||
const json::object &contents{json::get<"content"_>(event)};
|
||||
if(!contents.empty())
|
||||
|
|
|
@ -124,6 +124,32 @@ ircd::m::message(const room &room,
|
|||
return send(room, sender, "m.room.message", contents);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::redact(const room &room,
|
||||
const m::id::user &sender,
|
||||
const m::id::event &event_id,
|
||||
const string_view &reason)
|
||||
{
|
||||
json::iov event;
|
||||
json::iov::push push[]
|
||||
{
|
||||
{ event, { "type", "m.room.redaction" }},
|
||||
{ event, { "sender", sender }},
|
||||
{ event, { "redacts", event_id }},
|
||||
};
|
||||
|
||||
json::iov content;
|
||||
json::iov::set_if _reason
|
||||
{
|
||||
content, !empty(reason),
|
||||
{
|
||||
"reason", reason
|
||||
}
|
||||
};
|
||||
|
||||
return commit(room, event, content);
|
||||
}
|
||||
|
||||
ircd::m::event::id::buf
|
||||
ircd::m::send(const room &room,
|
||||
const m::id::user &sender,
|
||||
|
|
Loading…
Reference in a new issue