2018-10-16 20:35:22 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 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.
|
|
|
|
|
2019-08-07 10:00:50 +02:00
|
|
|
namespace ircd::m
|
|
|
|
{
|
2022-08-15 02:29:23 +02:00
|
|
|
static void room_message_media(const event &, vm::eval &);
|
2022-08-13 02:53:18 +02:00
|
|
|
static void room_message_info(const event &, vm::eval &);
|
2022-08-15 02:29:23 +02:00
|
|
|
|
|
|
|
extern hookfn<vm::eval &> room_message_media_hook;
|
2022-08-13 02:53:18 +02:00
|
|
|
extern hookfn<vm::eval &> room_message_info_hook;
|
2021-05-11 07:28:52 +02:00
|
|
|
extern log::log room_message_log;
|
2019-08-07 10:00:50 +02:00
|
|
|
}
|
2018-10-16 20:35:22 +02:00
|
|
|
|
2019-08-07 10:00:50 +02:00
|
|
|
ircd::mapi::header
|
2018-10-16 20:35:22 +02:00
|
|
|
IRCD_MODULE
|
|
|
|
{
|
|
|
|
"Matrix m.room.message"
|
|
|
|
};
|
|
|
|
|
2021-05-11 07:28:52 +02:00
|
|
|
decltype(ircd::m::room_message_log)
|
|
|
|
ircd::m::room_message_log
|
|
|
|
{
|
|
|
|
"m.message"
|
|
|
|
};
|
|
|
|
|
2022-08-13 02:53:18 +02:00
|
|
|
decltype(ircd::m::room_message_info_hook)
|
|
|
|
ircd::m::room_message_info_hook
|
2018-10-16 20:35:22 +02:00
|
|
|
{
|
2022-08-13 02:53:18 +02:00
|
|
|
room_message_info,
|
2018-10-16 20:35:22 +02:00
|
|
|
{
|
2019-08-07 10:00:50 +02:00
|
|
|
{ "_site", "vm.notify" },
|
|
|
|
{ "type", "m.room.message" },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-15 02:29:23 +02:00
|
|
|
decltype(ircd::m::room_message_media_hook)
|
|
|
|
ircd::m::room_message_media_hook
|
|
|
|
{
|
|
|
|
room_message_media,
|
|
|
|
{
|
|
|
|
{ "_site", "vm.effects" },
|
|
|
|
{ "type", "m.room.message" },
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-08-07 10:00:50 +02:00
|
|
|
void
|
2022-08-13 02:53:18 +02:00
|
|
|
ircd::m::room_message_info(const event &event,
|
|
|
|
vm::eval &eval)
|
2019-08-07 10:00:50 +02:00
|
|
|
{
|
2022-08-13 02:53:18 +02:00
|
|
|
const m::room::message msg
|
2019-08-07 10:00:50 +02:00
|
|
|
{
|
|
|
|
json::get<"content"_>(event)
|
|
|
|
};
|
|
|
|
|
2022-08-13 02:53:18 +02:00
|
|
|
const auto &body
|
2019-08-07 10:00:50 +02:00
|
|
|
{
|
2022-08-13 02:53:18 +02:00
|
|
|
msg.body()
|
2019-08-07 10:00:50 +02:00
|
|
|
};
|
|
|
|
|
2022-08-13 02:53:18 +02:00
|
|
|
const auto &msgtype
|
2019-08-07 10:00:50 +02:00
|
|
|
{
|
2022-08-13 02:53:18 +02:00
|
|
|
json::get<"msgtype"_>(msg)
|
2018-10-16 20:35:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
log::info
|
|
|
|
{
|
2021-05-11 07:28:52 +02:00
|
|
|
room_message_log, "%s said %s in %s %s :%s%s",
|
2018-10-16 20:35:22 +02:00
|
|
|
json::get<"sender"_>(event),
|
2019-07-06 07:01:34 +02:00
|
|
|
string_view{event.event_id},
|
2018-10-16 20:35:22 +02:00
|
|
|
json::get<"room_id"_>(event),
|
2019-08-07 10:00:50 +02:00
|
|
|
msgtype,
|
2018-10-16 20:35:22 +02:00
|
|
|
trunc(body, 128),
|
|
|
|
size(body) > 128? "..."_sv : string_view{}
|
|
|
|
};
|
|
|
|
}
|
2022-08-15 02:29:23 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
ircd::m::room_message_media(const event &event,
|
|
|
|
vm::eval &eval)
|
|
|
|
{
|
|
|
|
const m::room::message msg
|
|
|
|
{
|
|
|
|
json::get<"content"_>(event)
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto &msgtype
|
|
|
|
{
|
|
|
|
json::get<"msgtype"_>(msg)
|
|
|
|
};
|
|
|
|
|
|
|
|
const bool match
|
|
|
|
{
|
|
|
|
false
|
|
|
|
|| msgtype == "m.image"
|
|
|
|
|| msgtype == "m.video"
|
|
|
|
|| msgtype == "m.audio"
|
|
|
|
|| msgtype == "m.file"
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!match)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto &url
|
|
|
|
{
|
|
|
|
json::get<"url"_>(msg)
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!url)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const media::mxc mxc
|
|
|
|
{
|
|
|
|
url
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto file_room_id
|
|
|
|
{
|
|
|
|
media::file::room_id(mxc)
|
|
|
|
};
|
|
|
|
|
|
|
|
log::debug
|
|
|
|
{
|
|
|
|
room_message_log, "%s posted %s at %s in %s with %s",
|
|
|
|
json::get<"sender"_>(event),
|
|
|
|
msgtype,
|
|
|
|
json::get<"url"_>(msg),
|
|
|
|
json::get<"room_id"_>(event),
|
|
|
|
string_view{event.event_id},
|
|
|
|
};
|
|
|
|
}
|