0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-01 19:22:53 +01:00

ircd:Ⓜ️ Add redacts to main event; add redact(room, ...) committer.

This commit is contained in:
Jason Volk 2018-02-15 14:57:56 -08:00
parent 2921692571
commit 01251573bc
8 changed files with 54 additions and 0 deletions

View file

@ -38,6 +38,7 @@ origin
origin_server_ts origin_server_ts
prev_events prev_events
prev_state prev_state
redacts
room_id room_id
sender sender
signatures signatures

View file

@ -61,6 +61,7 @@ namespace ircd::m::dbs::desc
extern const database::descriptor events_origin_server_ts; extern const database::descriptor events_origin_server_ts;
extern const database::descriptor events_prev_events; extern const database::descriptor events_prev_events;
extern const database::descriptor events_prev_state; 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_room_id;
extern const database::descriptor events_sender; extern const database::descriptor events_sender;
extern const database::descriptor events_signatures; extern const database::descriptor events_signatures;

View file

@ -54,6 +54,7 @@ struct ircd::m::event
json::property<name::origin_server_ts, time_t>, json::property<name::origin_server_ts, time_t>,
json::property<name::prev_events, json::array>, json::property<name::prev_events, json::array>,
json::property<name::prev_state, 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::room_id, json::string>,
json::property<name::sender, json::string>, json::property<name::sender, json::string>,
json::property<name::signatures, json::object>, json::property<name::signatures, json::object>,

View file

@ -35,6 +35,7 @@ namespace ircd::m::name
constexpr const char *const origin_server_ts {"origin_server_ts"}; constexpr const char *const origin_server_ts {"origin_server_ts"};
constexpr const char *const prev_events {"prev_events"}; constexpr const char *const prev_events {"prev_events"};
constexpr const char *const prev_state {"prev_state"}; 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 room_id {"room_id"};
constexpr const char *const sender {"sender"}; constexpr const char *const sender {"sender"};
constexpr const char *const signatures {"signatures"}; constexpr const char *const signatures {"signatures"};

View file

@ -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); event::id::buf send(const room &, const m::id::user &sender, const string_view &type, const json::object &content);
// [SET] Convenience sends // [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 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 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); event::id::buf membership(const room &, const m::id::user &, const string_view &membership);

View file

@ -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 const ircd::database::descriptor
ircd::m::dbs::desc::events_room_id ircd::m::dbs::desc::events_room_id
{ {
@ -1104,6 +1124,7 @@ ircd::m::dbs::desc::events
events_origin_server_ts, events_origin_server_ts,
events_prev_events, events_prev_events,
events_prev_state, events_prev_state,
events_redacts,
events_room_id, events_room_id,
events_sender, events_sender,
events_signatures, events_signatures,

View file

@ -165,6 +165,7 @@ ircd::m::pretty(const event &event)
"depth", "depth",
"state_key", "state_key",
"membership", "membership",
"redacts",
}; };
json::for_each(event, top_keys, out); json::for_each(event, top_keys, out);
@ -295,6 +296,7 @@ ircd::m::pretty_oneline(const event &event)
s << "*" << " "; s << "*" << " ";
out("membership", json::get<"membership"_>(event)); out("membership", json::get<"membership"_>(event));
out("redacts", json::get<"redacts"_>(event));
const json::object &contents{json::get<"content"_>(event)}; const json::object &contents{json::get<"content"_>(event)};
if(!contents.empty()) if(!contents.empty())

View file

@ -124,6 +124,32 @@ ircd::m::message(const room &room,
return send(room, sender, "m.room.message", contents); 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::event::id::buf
ircd::m::send(const room &room, ircd::m::send(const room &room,
const m::id::user &sender, const m::id::user &sender,