From 44ff77a03fd5db8e220bc9f5b87e4b2fb1e9600f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 22 Feb 2018 19:50:48 -0800 Subject: [PATCH] ircd::m: Move redact() definition to modules/client/rooms/redact modules/client/rooms/redact: renamespacing. --- ircd/m/m.cc | 16 ++++++++++ ircd/m/room.cc | 26 ----------------- modules/client/rooms/redact.cc | 53 +++++++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/ircd/m/m.cc b/ircd/m/m.cc index 86b4f7289..c1256e2e4 100644 --- a/ircd/m/m.cc +++ b/ircd/m/m.cc @@ -328,3 +328,19 @@ ircd::m::leave(const room &room, return function(room, user_id); } + +ircd::m::event::id::buf +ircd::m::redact(const room &room, + const id::user &sender, + const id::event &event_id, + const string_view &reason) +{ + using prototype = event::id::buf (const m::room &, const id::user &, const id::event &, const string_view &); + + static import function + { + "client_rooms", "redact__" + }; + + return function(room, sender, event_id, reason); +} diff --git a/ircd/m/room.cc b/ircd/m/room.cc index e86e43339..f31bb967d 100644 --- a/ircd/m/room.cc +++ b/ircd/m/room.cc @@ -50,32 +50,6 @@ 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, diff --git a/modules/client/rooms/redact.cc b/modules/client/rooms/redact.cc index 10cce9baa..586072844 100644 --- a/modules/client/rooms/redact.cc +++ b/modules/client/rooms/redact.cc @@ -10,26 +10,33 @@ #include "rooms.h" +using namespace ircd::m; using namespace ircd; +extern "C" event::id::buf +redact__(const room &room, + const id::user &sender, + const id::event &event_id, + const string_view &reason); + resource::response put__redact(client &client, const resource::request &request, - const m::room::id &room_id) + const room::id &room_id) { if(request.parv.size() < 3) - throw m::NEED_MORE_PARAMS + throw NEED_MORE_PARAMS { "event_id parameter missing" }; - m::event::id::buf redacts + event::id::buf redacts { url::decode(request.parv[2], redacts) }; if(request.parv.size() < 4) - throw m::NEED_MORE_PARAMS + throw NEED_MORE_PARAMS { "txnid parameter missing" }; @@ -39,7 +46,7 @@ put__redact(client &client, request.parv[3] }; - const m::room room + const room room { room_id }; @@ -51,7 +58,7 @@ put__redact(client &client, const auto event_id { - redact(room, request.user_id, redacts, reason) + redact__(room, request.user_id, redacts, reason) }; return resource::response @@ -66,20 +73,20 @@ put__redact(client &client, resource::response post__redact(client &client, const resource::request &request, - const m::room::id &room_id) + const room::id &room_id) { if(request.parv.size() < 3) - throw m::NEED_MORE_PARAMS + throw NEED_MORE_PARAMS { "event_id parameter missing" }; - m::event::id::buf redacts + event::id::buf redacts { url::decode(request.parv[2], redacts) }; - const m::room room + const room room { room_id }; @@ -102,3 +109,29 @@ post__redact(client &client, } }; } + +event::id::buf +redact__(const room &room, + const id::user &sender, + const id::event &event_id, + const string_view &reason) +{ + json::iov event; + const json::iov::push push[] + { + { event, { "type", "m.room.redaction" }}, + { event, { "sender", sender }}, + { event, { "redacts", event_id }}, + }; + + json::iov content; + const json::iov::set_if _reason + { + content, !empty(reason), + { + "reason", reason + } + }; + + return commit(room, event, content); +}