From 58a0a7e01422e62de1565a8eb0a1febdc463d04d Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 13 Aug 2018 20:17:46 +0100 Subject: Implement IRCv3 message tag support. Co-authored-by: Attila Molnar --- src/modules/m_ircv3_echomessage.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/modules/m_ircv3_echomessage.cpp') diff --git a/src/modules/m_ircv3_echomessage.cpp b/src/modules/m_ircv3_echomessage.cpp index 056b02194..702552ea7 100644 --- a/src/modules/m_ircv3_echomessage.cpp +++ b/src/modules/m_ircv3_echomessage.cpp @@ -21,8 +21,6 @@ #include "inspircd.h" #include "modules/cap.h" -static const char* MessageTypeStringSp[] = { "PRIVMSG ", "NOTICE " }; - class ModuleIRCv3EchoMessage : public Module { Cap::Capability cap; @@ -38,27 +36,31 @@ class ModuleIRCv3EchoMessage : public Module if (!cap.get(user)) return; - std::string msg = MessageTypeStringSp[details.type]; + // Caps are only set on local users + LocalUser* const localuser = static_cast(user); + + const std::string& text = details.echooriginal ? details.originaltext : details.text; if (target.type == MessageTarget::TYPE_USER) { User* destuser = target.Get(); - msg.append(destuser->nick); + ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, destuser, text, details.type); + privmsg.AddTags(details.tags_in); + localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg); } else if (target.type == MessageTarget::TYPE_CHANNEL) { - if (target.status) - msg.push_back(target.status); - Channel* chan = target.Get(); - msg.append(chan->name); + ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, chan, text, details.type, target.status); + privmsg.AddTags(details.tags_in); + localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg); } else { const std::string* servername = target.Get(); - msg.append(*servername); + ClientProtocol::Messages::Privmsg privmsg(ClientProtocol::Messages::Privmsg::nocopy, user, *servername, text, details.type); + privmsg.AddTags(details.tags_in); + localuser->Send(ServerInstance->GetRFCEvents().privmsg, privmsg); } - msg.append(" :").append(details.echooriginal ? details.originaltext : details.text); - user->WriteFrom(user, msg); } void OnUserMessageBlocked(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE -- cgit v1.2.3