summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2021-01-11 10:07:11 +0000
committerSadie Powell <sadie@witchery.services>2021-01-11 10:07:11 +0000
commit5a19ff00aca5d979bf9ca45a2b0d6e85acdc9fc3 (patch)
tree3e5c31e168342671b38b77cab5eafe9b797bcc37
parent8d6b550e0b30983886dc240fd3261fae786d5693 (diff)
Add a user mode which allows disabling receiving channel history.
Closes #1830.
-rw-r--r--docs/conf/modules.conf.example26
-rw-r--r--src/modules/m_chanhistory.cpp28
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.
#<module name="chanhistory">
#
-# 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 maxlines="50" prefixmsg="yes" bots="yes">
+#-#-#-#-#-#-#-#-#-#-#- 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. #
+# #
+#<chanhistory bots="yes"
+# enableumode="yes"
+# maxlines="50"
+# prefixmsg="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<HistoryMode, SimpleExtItem<HistoryList> >
}
};
+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<Channel>();
- 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;