2019-03-15 00:01:41 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 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. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#include "rooms.h"
|
|
|
|
|
|
|
|
using namespace ircd;
|
|
|
|
|
|
|
|
conf::item<size_t>
|
|
|
|
reason_max
|
|
|
|
{
|
|
|
|
{ "name", "ircd.client.rooms.report.reason.max" },
|
|
|
|
{ "default", 512L }
|
|
|
|
};
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
m::resource::response
|
2019-03-15 00:01:41 +01:00
|
|
|
post__report(client &client,
|
2019-09-29 01:12:07 +02:00
|
|
|
const m::resource::request &request,
|
2019-03-15 00:01:41 +01:00
|
|
|
const m::room::id &room_id)
|
|
|
|
{
|
|
|
|
if(request.parv.size() < 3)
|
|
|
|
throw m::NEED_MORE_PARAMS
|
|
|
|
{
|
|
|
|
"event_id path parameter required"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!m::exists(room_id))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Cannot take a report about %s which is not found.",
|
|
|
|
string_view{room_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
m::event::id::buf event_id
|
|
|
|
{
|
|
|
|
url::decode(event_id, request.parv[2])
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!m::exists(event_id))
|
|
|
|
throw m::NOT_FOUND
|
|
|
|
{
|
|
|
|
"Cannot take a report about %s which is not found.",
|
|
|
|
string_view{event_id}
|
|
|
|
};
|
|
|
|
|
|
|
|
const short &score
|
|
|
|
{
|
|
|
|
request.get<short>("score")
|
|
|
|
};
|
|
|
|
|
|
|
|
const json::string &reason
|
|
|
|
{
|
2021-02-06 08:31:59 +01:00
|
|
|
trunc(request.at("reason"), size_t(reason_max))
|
2019-03-15 00:01:41 +01:00
|
|
|
};
|
|
|
|
|
2019-10-01 05:50:58 +02:00
|
|
|
const m::room::id::buf report_room_id
|
|
|
|
{
|
|
|
|
"abuse", request.user_id.host()
|
|
|
|
};
|
|
|
|
|
2019-03-15 00:01:41 +01:00
|
|
|
const m::room room
|
|
|
|
{
|
|
|
|
report_room_id
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!exists(room))
|
|
|
|
throw m::UNAVAILABLE
|
|
|
|
{
|
|
|
|
"Sorry, reporting content is not available right now."
|
|
|
|
};
|
|
|
|
|
2021-02-06 08:31:59 +01:00
|
|
|
// Include raw report data for bots.
|
|
|
|
const json::members report
|
2019-03-15 00:01:41 +01:00
|
|
|
{
|
2021-02-06 08:31:59 +01:00
|
|
|
{ "room_id", room_id },
|
|
|
|
{ "event_id", event_id },
|
|
|
|
{ "score", score },
|
|
|
|
{ "reason", reason },
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate a plaintext summary for text clients.
|
|
|
|
const fmt::bsprintf<2_KiB> body
|
|
|
|
{
|
|
|
|
"Report by %s of %s in %s :%s",
|
|
|
|
string_view{request.user_id},
|
|
|
|
string_view{event_id},
|
|
|
|
string_view{room_id},
|
|
|
|
reason,
|
|
|
|
};
|
|
|
|
|
|
|
|
const fmt::snstringf formatted_body
|
|
|
|
{
|
|
|
|
4_KiB,
|
|
|
|
R"(
|
|
|
|
<h4>Reported %s</h4>
|
|
|
|
<blockquote>%s</blockquote>
|
|
|
|
https://matrix.to/#/%s/%s
|
|
|
|
)",
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{reason},
|
|
|
|
string_view{room_id},
|
|
|
|
string_view{event_id},
|
|
|
|
};
|
|
|
|
|
|
|
|
// Generate a relates_to/in_reply_to of the event being reported so the
|
|
|
|
// censors can be debauched by its content directly in the !abuse room.
|
|
|
|
const json::members relates_to[2]
|
|
|
|
{
|
|
|
|
{ { "event_id", event_id } },
|
|
|
|
{ { "m.in_reply_to", relates_to[0] } },
|
|
|
|
};
|
|
|
|
|
|
|
|
send(room, request.user_id, "m.room.message",
|
|
|
|
{
|
|
|
|
{ "msgtype", "m.notice" },
|
|
|
|
{ "format", "org.matrix.custom.html" },
|
|
|
|
{ "formatted_body", stripa(formatted_body) },
|
|
|
|
{ "body", body },
|
|
|
|
{ "m.relates_to", relates_to[1] },
|
|
|
|
{ "ircd.report", report },
|
2019-03-15 00:01:41 +01:00
|
|
|
});
|
|
|
|
|
2019-09-29 01:12:07 +02:00
|
|
|
return m::resource::response
|
2019-03-15 00:01:41 +01:00
|
|
|
{
|
|
|
|
client, http::OK
|
|
|
|
};
|
|
|
|
}
|