summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2020-01-03 20:54:24 +0000
committerSadie Powell <sadie@witchery.services>2020-01-03 21:35:19 +0000
commit038074d7c0f25ece31a6223214887ee56a1859de (patch)
treeeca3d0bf3addb4d7bdf0b8d8a5fc00fe64c33699 /src/modules
parenta9e8e1f03ace24e9dcb50299f8e66c5fd6b42850 (diff)
Fix the chanhistory module not replaying message tags.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_chanhistory.cpp30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp
index ef7b2b177..8c73d4cd6 100644
--- a/src/modules/m_chanhistory.cpp
+++ b/src/modules/m_chanhistory.cpp
@@ -22,17 +22,23 @@
#include "modules/ircv3_batch.h"
#include "modules/server.h"
+typedef insp::flat_map<std::string, std::string> HistoryTagMap;
+
struct HistoryItem
{
time_t ts;
std::string text;
+ HistoryTagMap tags;
std::string sourcemask;
- HistoryItem(User* source, const std::string& Text)
+ HistoryItem(User* source, const std::string& Text, const ClientProtocol::TagMap& Tags)
: ts(ServerInstance->Time())
, text(Text)
, sourcemask(source->GetFullHost())
{
+ tags.reserve(Tags.size());
+ for (ClientProtocol::TagMap::const_iterator iter = Tags.begin(); iter != Tags.end(); ++iter)
+ tags[iter->first] = iter->second.value;
}
};
@@ -123,6 +129,21 @@ class ModuleChanHistory
IRCv3::Batch::API batchmanager;
IRCv3::Batch::Batch batch;
IRCv3::ServerTime::API servertimemanager;
+ ClientProtocol::MessageTagEvent tagevent;
+
+ void AddTag(ClientProtocol::Message& msg, const std::string& tagkey, std::string& tagval)
+ {
+ const Events::ModuleEventProvider::SubscriberList& list = tagevent.GetSubscribers();
+ for (Events::ModuleEventProvider::SubscriberList::const_iterator i = list.begin(); i != list.end(); ++i)
+ {
+ ClientProtocol::MessageTagProvider* const tagprov = static_cast<ClientProtocol::MessageTagProvider*>(*i);
+ const ModResult res = tagprov->OnProcessTag(ServerInstance->FakeClient, tagkey, tagval);
+ if (res == MOD_RES_ALLOW)
+ msg.AddTag(tagkey, tagprov, tagval);
+ else if (res == MOD_RES_DENY)
+ break;
+ }
+ }
void SendHistory(LocalUser* user, Channel* channel, HistoryList* list, time_t mintime)
{
@@ -134,10 +155,12 @@ class ModuleChanHistory
for(std::deque<HistoryItem>::iterator i = list->lines.begin(); i != list->lines.end(); ++i)
{
- const HistoryItem& item = *i;
+ HistoryItem& item = *i;
if (item.ts >= mintime)
{
ClientProtocol::Messages::Privmsg msg(ClientProtocol::Messages::Privmsg::nocopy, item.sourcemask, channel, item.text);
+ for (HistoryTagMap::iterator iter = item.tags.begin(); iter != item.tags.end(); ++iter)
+ AddTag(msg, iter->first, iter->second);
if (servertimemanager)
servertimemanager->Set(msg, item.ts);
batch.AddToBatch(msg);
@@ -158,6 +181,7 @@ class ModuleChanHistory
, batchmanager(this)
, batch("chathistory")
, servertimemanager(this)
+ , tagevent(this)
{
}
@@ -182,7 +206,7 @@ class ModuleChanHistory
HistoryList* list = m.ext.get(c);
if (list)
{
- list->lines.push_back(HistoryItem(user, details.text));
+ list->lines.push_back(HistoryItem(user, details.text, details.tags_out));
if (list->lines.size() > list->maxlen)
list->lines.pop_front();
}