common: Exclude ignored messages in buffer activity
authorShane Synan <digitalcircuit36939@gmail.com>
Sun, 21 Jun 2020 23:36:38 +0000 (19:36 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 3 Oct 2020 16:07:50 +0000 (18:07 +0200)
Add a new message flag, 'Ignored', tracking if the message matched an
ignore rule when received.  In practice, this refers to dynamic ignore
rules (SoftStrictness), as permanent ignore rules (HardStrictness)
will drop the message entirely.  Simple clients/bots may use this to
apply ignore rules without having to implement the entire regular
expression rules.

Exclude messages that match an ignore rule when updating
bufferActivity and highlightCount, fixing the appearance of new
activity/highlights from ignored messages.

Fixes #1511

NOTE: Using the 'Ignored' flag is not recommended for full clients as
they will need to locally reveal hidden messages when specific dynamic
ignore rules are disabled.

Clean up leftover comment on serializing sender prefixes.

Co-authored-by: Janne Koschinski <janne@kuschku.de>
src/common/message.cpp
src/common/message.h
src/core/SQL/PostgreSQL/select_buffer_bufferactivity.sql
src/core/SQL/PostgreSQL/select_buffer_highlightcount.sql
src/core/SQL/SQLite/select_buffer_bufferactivity.sql
src/core/SQL/SQLite/select_buffer_highlightcount.sql
src/core/corebuffersyncer.h
src/core/coresession.cpp

index 66a81ce..cfe162e 100644 (file)
@@ -71,7 +71,6 @@ QDataStream& operator<<(QDataStream& out, const Message& msg)
     Q_ASSERT(SignalProxy::current());
     Q_ASSERT(SignalProxy::current()->targetPeer());
 
-    // We do not serialize the sender prefixes until we have a new protocol or client-features implemented
     out << msg.msgId();
 
     if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::LongTime)) {
index 90ecd10..39a6bd2 100644 (file)
@@ -66,6 +66,7 @@ public:
         Redirected = 0x04,
         ServerMsg  = 0x08,
         StatusMsg  = 0x10,
+        Ignored    = 0x20, ///< This message matched an active ignore rule when first received
         Backlog    = 0x80
     };
     Q_DECLARE_FLAGS(Flags, Flag)
index 2013c10..53cff93 100644 (file)
@@ -3,5 +3,6 @@ FROM
   (SELECT DISTINCT TYPE
    FROM backlog
    WHERE bufferid = :bufferid
+     AND flags & 32 = 0
      AND flags & 1 = 0
      AND messageid > :lastseenmsgid) t;
index 33058f8..d394724 100644 (file)
@@ -2,6 +2,7 @@ SELECT COALESCE(t.sum,0)
 FROM
   (SELECT COUNT(*) AS sum FROM backlog
    WHERE bufferid = :bufferid
+     AND flags & 32 = 0
      AND flags & 2 != 0
      AND flags & 1 = 0
      AND messageid > :lastseenmsgid) t;
index 2013c10..53cff93 100644 (file)
@@ -3,5 +3,6 @@ FROM
   (SELECT DISTINCT TYPE
    FROM backlog
    WHERE bufferid = :bufferid
+     AND flags & 32 = 0
      AND flags & 1 = 0
      AND messageid > :lastseenmsgid) t;
index 33058f8..d394724 100644 (file)
@@ -2,6 +2,7 @@ SELECT COALESCE(t.sum,0)
 FROM
   (SELECT COUNT(*) AS sum FROM backlog
    WHERE bufferid = :bufferid
+     AND flags & 32 = 0
      AND flags & 2 != 0
      AND flags & 1 = 0
      AND messageid > :lastseenmsgid) t;
index 87023c5..ea7f4bc 100644 (file)
@@ -40,6 +40,10 @@ public slots:
 
     void addBufferActivity(const Message& message)
     {
+        if (message.flags().testFlag(Message::Flag::Ignored)) {
+            // Don't update buffer activity with messages that are ignored
+            return;
+        }
         auto oldActivity = activity(message.bufferId());
         if (!oldActivity.testFlag(message.type())) {
             setBufferActivity(message.bufferId(), (int)(oldActivity | message.type()));
@@ -48,6 +52,10 @@ public slots:
 
     void addCoreHighlight(const Message& message)
     {
+        if (message.flags().testFlag(Message::Flag::Ignored)) {
+            // Don't increase highlight count for messages that are ignored
+            return;
+        }
         auto oldHighlightCount = highlightCount(message.bufferId());
         if (message.flags().testFlag(Message::Flag::Highlight) && !message.flags().testFlag(Message::Flag::Self)) {
             setHighlightCount(message.bufferId(), oldHighlightCount + 1);
index 6c85605..5eed0eb 100644 (file)
@@ -323,8 +323,18 @@ void CoreSession::recvMessageFromServer(RawMessage msg)
     // check for HardStrictness ignore
     CoreNetwork* currentNetwork = network(msg.networkId);
     QString networkName = currentNetwork ? currentNetwork->networkName() : QString("");
-    if (_ignoreListManager.match(msg, networkName) == IgnoreListManager::HardStrictness)
+    switch (_ignoreListManager.match(msg, networkName)) {
+    case IgnoreListManager::StrictnessType::HardStrictness:
+        // Drop the message permanently
         return;
+    case IgnoreListManager::StrictnessType::SoftStrictness:
+        // Mark the message as (dynamically) ignored
+        msg.flags |= Message::Flag::Ignored;
+        break;
+    case IgnoreListManager::StrictnessType::UnmatchedStrictness:
+        // Keep the message unmodified
+        break;
+    }
 
     if (currentNetwork && _highlightRuleManager.match(msg, currentNetwork->myNick(), currentNetwork->identityPtr()->nicks()))
         msg.flags |= Message::Flag::Highlight;