From 1b727223860ce01779ba944a41fdb41fe332486d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 16 Oct 2018 11:35:22 -0700 Subject: [PATCH] modules: Start an m_room_message protocol handler stub. --- modules/Makefile.am | 2 ++ modules/m_room_message.cc | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 modules/m_room_message.cc diff --git a/modules/Makefile.am b/modules/Makefile.am index d8c691693..9365ba6b0 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -99,6 +99,7 @@ m_room_join_rules_la_SOURCES = m_room_join_rules.cc m_room_history_visibility_la_SOURCES = m_room_history_visibility.cc m_room_canonical_alias_la_SOURCES = m_room_canonical_alias.cc m_room_aliases_la_SOURCES = m_room_aliases.cc +m_room_message_la_SOURCES = m_room_message.cc m_module_LTLIBRARIES = \ m_noop.la \ @@ -114,6 +115,7 @@ m_module_LTLIBRARIES = \ m_room_history_visibility.la \ m_room_canonical_alias.la \ m_room_aliases.la \ + m_room_message.la \ ### ############################################################################### diff --git a/modules/m_room_message.cc b/modules/m_room_message.cc new file mode 100644 index 000000000..8cff5bc3a --- /dev/null +++ b/modules/m_room_message.cc @@ -0,0 +1,48 @@ +// Matrix Construct +// +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// 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. + +using namespace ircd; + +mapi::header +IRCD_MODULE +{ + "Matrix m.room.message" +}; + +static void +_message_notify(const m::event &event, + m::vm::eval &eval) +{ + const auto &body + { + unquote(json::get<"content"_>(event).get("body")) + }; + + log::info + { + "%s %s said in %s %s :%s%s", + json::get<"origin"_>(event), + json::get<"sender"_>(event), + json::get<"room_id"_>(event), + json::get<"content"_>(event).get("msgtype"), + trunc(body, 128), + size(body) > 128? "..."_sv : string_view{} + }; +} + +const m::hookfn +_message_notify_hookfn +{ + { + { "_site", "vm.notify" }, + { "type", "m.room.message" }, + }, + _message_notify +};