From 5a19ff00aca5d979bf9ca45a2b0d6e85acdc9fc3 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 11 Jan 2021 10:07:11 +0000 Subject: [PATCH] Add a user mode which allows disabling receiving channel history. Closes #1830. --- docs/conf/modules.conf.example | 26 +++++++++++++++++++------- src/modules/m_chanhistory.cpp | 28 ++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index 4fab166d2..1faec808c 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -450,13 +450,25 @@ # the current topic of conversation is when joining the channel. # # -# Set the maximum number of lines allowed to be stored per channel below. -# This is the hard limit for 'X'. -# If prefixmsg is set to yes, joining users without batch support will get -# a NOTICE before playback telling them about the following lines being -# the pre-join history. -# If bots is set to yes, it will also send to users marked with +B -# +#-#-#-#-#-#-#-#-#-#-#- CHANHISTORY CONFIGURATION -#-#-#-#-#-#-#-#-#-#-# +# # +# bots - Whether to send channel history to bots. Defaults to yes. # +# # +# enableumode - Whether to enable the +N user mode which allows users # +# to opt-out of receiving channel history. Defaults to # +# no. # +# # +# maxlines - The maximum number of lines of chat history to send to a # +# joining users. Defaults to 50. # +# # +# prefixmsg - Whether to send an explanatory message to clients that # +# don't support the chathistory batch type. Defaults to # +# yes. # +# # +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Channel logging module: Used to send snotice output to channels, to diff --git a/src/modules/m_chanhistory.cpp b/src/modules/m_chanhistory.cpp index f689b292c..4bd230a7c 100644 --- a/src/modules/m_chanhistory.cpp +++ b/src/modules/m_chanhistory.cpp @@ -124,12 +124,24 @@ class HistoryMode : public ParamMode > } }; +class NoHistoryMode : public SimpleUserModeHandler +{ +public: + NoHistoryMode(Module* Creator) + : SimpleUserModeHandler(Creator, "nohistory", 'N') + { + if (!ServerInstance->Config->ConfValue("chanhistory")->getBool("enableumode")) + DisableAutoRegister(); + } +}; + class ModuleChanHistory : public Module , public ServerProtocol::BroadcastEventListener { private: - HistoryMode m; + HistoryMode historymode; + NoHistoryMode nohistorymode; bool prefixmsg; UserModeReference botmode; bool dobots; @@ -183,7 +195,8 @@ class ModuleChanHistory public: ModuleChanHistory() : ServerProtocol::BroadcastEventListener(this) - , m(this) + , historymode(this) + , nohistorymode(this) , botmode(this, "bot") , batchcap(this) , batchmanager(this) @@ -196,14 +209,14 @@ class ModuleChanHistory void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* tag = ServerInstance->Config->ConfValue("chanhistory"); - m.maxlines = tag->getUInt("maxlines", 50, 1); + historymode.maxlines = tag->getUInt("maxlines", 50, 1); prefixmsg = tag->getBool("prefixmsg", tag->getBool("notice", true)); dobots = tag->getBool("bots", true); } ModResult OnBroadcastMessage(Channel* channel, const Server* server) CXX11_OVERRIDE { - return channel->IsModeSet(m) ? MOD_RES_ALLOW : MOD_RES_PASSTHRU; + return channel->IsModeSet(historymode) ? MOD_RES_ALLOW : MOD_RES_PASSTHRU; } void OnUserPostMessage(User* user, const MessageTarget& target, const MessageDetails& details) CXX11_OVERRIDE @@ -212,7 +225,7 @@ class ModuleChanHistory if ((target.type == MessageTarget::TYPE_CHANNEL) && (target.status == 0) && (!details.IsCTCP(ctcpname) || irc::equals(ctcpname, "ACTION"))) { Channel* c = target.Get(); - HistoryList* list = m.ext.get(c); + HistoryList* list = historymode.ext.get(c); if (list) { list->lines.push_back(HistoryItem(user, details)); @@ -231,7 +244,10 @@ class ModuleChanHistory if (memb->user->IsModeSet(botmode) && !dobots) return; - HistoryList* list = m.ext.get(memb->chan); + if (memb->user->IsModeSet(nohistorymode)) + return; + + HistoryList* list = historymode.ext.get(memb->chan); if (!list) return; -- 2.39.2