permanently ignored (HardStrictness) messages can no longer trigger a buffer creation
authorMarcus Eggenberger <egs@quassel-irc.org>
Thu, 11 Mar 2010 16:02:29 +0000 (17:02 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Thu, 11 Mar 2010 16:02:29 +0000 (17:02 +0100)
src/common/ignorelistmanager.cpp
src/common/ignorelistmanager.h
src/core/coreignorelistmanager.cpp
src/core/coreignorelistmanager.h
src/core/coresession.cpp
src/core/coresession.h

index bd37a20..b4831c0 100644 (file)
 #include <QStringList>
 #include <QRegExp>
 
-#include "message.h"
-
 INIT_SYNCABLE_OBJECT(IgnoreListManager)
-
 IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other) {
   if(this == &other)
     return *this;
@@ -117,21 +114,25 @@ void IgnoreListManager::addIgnoreListItem(int type, const QString &ignoreRule, b
   SYNC(ARG(type), ARG(ignoreRule), ARG(isRegEx), ARG(strictness), ARG(scope), ARG(scopeRule), ARG(isActive))
 }
 
-IgnoreListManager::StrictnessType IgnoreListManager::match(const Message &msg, const QString &network) {
-  if(!(msg.type() & (Message::Plain | Message::Notice | Message::Action)))
+IgnoreListManager::StrictnessType IgnoreListManager::_match(const QString &msgContents, const QString &msgSender, Message::Type msgType, const QString &network, const QString &bufferName) {
+  // We method don't rely on a proper Message object to make this method more versatile.
+  // This allows us to use it in the core with unprocessed Messages or in the Client
+  // with properly preprocessed Messages.
+  if(!(msgType & (Message::Plain | Message::Notice | Message::Action)))
     return UnmatchedStrictness;
 
   foreach(IgnoreListItem item, _ignoreList) {
     if(!item.isActive || item.type == CtcpIgnore)
       continue;
-    if(item.scope == GlobalScope || (item.scope == NetworkScope && scopeMatch(item.scopeRule, network)) ||
-       (item.scope == ChannelScope && scopeMatch(item.scopeRule, msg.bufferInfo().bufferName()))) {
+    if(item.scope == GlobalScope
+       || (item.scope == NetworkScope && scopeMatch(item.scopeRule, network))
+       || (item.scope == ChannelScope && scopeMatch(item.scopeRule, bufferName))) {
 
       QString str;
       if(item.type == MessageIgnore)
-        str = msg.contents();
+        str = msgContents;
       else
-        str = msg.sender();
+        str = msgSender;
 
       QRegExp ruleRx = QRegExp(item.ignoreRule);
       ruleRx.setCaseSensitivity(Qt::CaseInsensitive);
@@ -154,6 +155,7 @@ IgnoreListManager::StrictnessType IgnoreListManager::match(const Message &msg, c
   return UnmatchedStrictness;
 }
 
+
 bool IgnoreListManager::scopeMatch(const QString &scopeRule, const QString &string) const {
   foreach(QString rule, scopeRule.split(";")) {
     QRegExp ruleRx = QRegExp(rule.trimmed());
index 171f8b2..b5bdf22 100644 (file)
 
 #include <QString>
 
+#include "message.h"
 #include "syncableobject.h"
 
-class Message;
-
 class IgnoreListManager : public SyncableObject
 {
   SYNCABLE_OBJECT
@@ -92,7 +91,7 @@ public:
     * \param network The networkname the message belongs to
     * \return UnmatchedStrictness, HardStrictness or SoftStrictness representing the match type
     */
-  StrictnessType match(const Message &msg, const QString &network = QString());
+  inline StrictnessType match(const Message &msg, const QString &network = QString()) { return _match(msg.contents(), msg.sender(), msg.type(), network, msg.bufferInfo().bufferName()); }
 
   bool ctcpMatch(const QString sender, const QString &network, const QString &type = QString());
 
@@ -137,8 +136,10 @@ public slots:
 
 protected:
   void setIgnoreList(const QList<IgnoreListItem> &ignoreList) { _ignoreList = ignoreList; }
-  // scopeRule is a ; separated list, string is a network/channel-name
-  bool scopeMatch(const QString &scopeRule, const QString &string) const;
+  bool scopeMatch(const QString &scopeRule, const QString &string) const;   // scopeRule is a ';'-separated list, string is a network/channel-name
+
+  StrictnessType _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, const QString &network, const QString &bufferName);
+
 
 signals:
   void ignoreAdded(IgnoreType type, const QString &ignoreRule, bool isRegex, StrictnessType strictness, ScopeType scope, const QVariant &scopeRule, bool isActive);
index a1e298c..e3cc70b 100644 (file)
@@ -24,7 +24,6 @@
 #include "coresession.h"
 
 INIT_SYNCABLE_OBJECT(CoreIgnoreListManager)
-
 CoreIgnoreListManager::CoreIgnoreListManager(CoreSession *parent)
   : IgnoreListManager(parent)
 {
@@ -44,6 +43,11 @@ CoreIgnoreListManager::CoreIgnoreListManager(CoreSession *parent)
     //loadDefaults();
 }
 
+IgnoreListManager::StrictnessType CoreIgnoreListManager::match(const RawMessage &rawMsg, const QString &networkName) {
+  //StrictnessType _match(const QString &msgContents, const QString &msgSender, Message::Type msgType, const QString &network, const QString &bufferName);
+  return _match(rawMsg.text, rawMsg.sender, rawMsg.type, networkName, rawMsg.target);
+}
+
 void CoreIgnoreListManager::save() const {
   CoreSession *session = qobject_cast<CoreSession *>(parent());
   if(!session) {
index c12e323..d7d5c9c 100644 (file)
@@ -24,6 +24,7 @@
 #include "ignorelistmanager.h"
 
 class CoreSession;
+struct RawMessage;
 
 class CoreIgnoreListManager : public IgnoreListManager {
   SYNCABLE_OBJECT
@@ -34,6 +35,8 @@ public:
 
   inline virtual const QMetaObject *syncMetaObject() const { return &IgnoreListManager::staticMetaObject; }
 
+  StrictnessType match(const RawMessage &rawMsg, const QString &networkName);
+
 public slots:
   virtual inline void requestToggleIgnoreRule(const QString &ignoreRule) { toggleIgnoreRule(ignoreRule); }
   virtual inline void requestRemoveIgnoreListItem(const QString &ignoreRule) { removeIgnoreListItem(ignoreRule); }
index c515fae..b7ac9df 100644 (file)
@@ -219,8 +219,15 @@ void CoreSession::recvMessageFromServer(NetworkId networkId, Message::Type type,
   // KDE's notifications), hence we remove those just to be safe.
   QString text = text_;
   text.remove(QChar(0xfdd0)).remove(QChar(0xfdd1));
+  RawMessage rawMsg(networkId, type, bufferType, target, text, sender, flags);
 
-  _messageQueue << RawMessage(networkId, type, bufferType, target, text, sender, flags);
+  // check for HardStrictness ignore
+  CoreNetwork *currentNetwork = network(networkId);
+  QString networkName = currentNetwork ? currentNetwork->networkName() : QString("");
+  if(_ignoreListManager.match(rawMsg, networkName) == IgnoreListManager::HardStrictness)
+    return;
+
+  _messageQueue << rawMsg;
   if(!_processMessages) {
     _processMessages = true;
     QCoreApplication::postEvent(this, new ProcessMessagesEvent());
@@ -246,19 +253,12 @@ void CoreSession::customEvent(QEvent *event) {
 }
 
 void CoreSession::processMessages() {
-  QString networkName;
   if(_messageQueue.count() == 1) {
     const RawMessage &rawMsg = _messageQueue.first();
     BufferInfo bufferInfo = Core::bufferInfo(user(), rawMsg.networkId, rawMsg.bufferType, rawMsg.target);
     Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, rawMsg.flags);
-
-    CoreNetwork *currentNetwork = network(bufferInfo.networkId());
-    networkName = currentNetwork ? currentNetwork->networkName() : QString("");
-    // if message is ignored with "HardStrictness" we discard it here
-    if(_ignoreListManager.match(msg, networkName) != IgnoreListManager::HardStrictness) {
-      Core::storeMessage(msg);
-      emit displayMsg(msg);
-    }
+    Core::storeMessage(msg);
+    emit displayMsg(msg);
   } else {
     QHash<NetworkId, QHash<QString, BufferInfo> > bufferInfoCache;
     MessageList messages;
@@ -273,11 +273,6 @@ void CoreSession::processMessages() {
       }
 
       Message msg(bufferInfo, rawMsg.type, rawMsg.text, rawMsg.sender, rawMsg.flags);
-      CoreNetwork *currentNetwork = network(bufferInfo.networkId());
-      networkName = currentNetwork ? currentNetwork->networkName() : QString("");
-      // if message is ignored with "HardStrictness" we discard it here
-      if(_ignoreListManager.match(msg, networkName) == IgnoreListManager::HardStrictness)
-        continue;
       messages << msg;
     }
     Core::storeMessages(messages);
index 117f690..4f341ee 100644 (file)
@@ -177,20 +177,21 @@ private:
 
   QScriptEngine *scriptEngine;
 
-  struct RawMessage {
-    NetworkId networkId;
-    Message::Type type;
-    BufferInfo::Type bufferType;
-    QString target;
-    QString text;
-    QString sender;
-    Message::Flags flags;
-    RawMessage(NetworkId networkId, Message::Type type, BufferInfo::Type bufferType, const QString &target, const QString &text, const QString &sender, Message::Flags flags)
-      : networkId(networkId), type(type), bufferType(bufferType), target(target), text(text), sender(sender), flags(flags) {}
-  };
   QList<RawMessage> _messageQueue;
   bool _processMessages;
   CoreIgnoreListManager _ignoreListManager;
 };
 
+struct RawMessage {
+  NetworkId networkId;
+  Message::Type type;
+  BufferInfo::Type bufferType;
+  QString target;
+  QString text;
+  QString sender;
+  Message::Flags flags;
+  RawMessage(NetworkId networkId, Message::Type type, BufferInfo::Type bufferType, const QString &target, const QString &text, const QString &sender, Message::Flags flags)
+    : networkId(networkId), type(type), bufferType(bufferType), target(target), text(text), sender(sender), flags(flags) {}
+};
+
 #endif