]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Add a user mode which allows disabling receiving channel history.
authorSadie Powell <sadie@witchery.services>
Mon, 11 Jan 2021 10:07:11 +0000 (10:07 +0000)
committerSadie Powell <sadie@witchery.services>
Mon, 11 Jan 2021 10:07:11 +0000 (10:07 +0000)
Closes #1830.

docs/conf/modules.conf.example
src/modules/m_chanhistory.cpp

index 4fab166d27f55389ef0c204b01d8c1d33cc06ce4..1faec808cd0d84c751df251fbe7209595be9e0d7 100644 (file)
 # 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
index f689b292c1960adff28e31e974288cdad46a3b5a..4bd230a7c649c1278717696dcb84feb4efc6d7df 100644 (file)
@@ -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;