From 17147dbb28c17fb69ad4479faec1fcd12ca764c4 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Thu, 11 Mar 2010 17:02:29 +0100 Subject: [PATCH] permanently ignored (HardStrictness) messages can no longer trigger a buffer creation --- src/common/ignorelistmanager.cpp | 20 +++++++++++--------- src/common/ignorelistmanager.h | 11 ++++++----- src/core/coreignorelistmanager.cpp | 6 +++++- src/core/coreignorelistmanager.h | 3 +++ src/core/coresession.cpp | 25 ++++++++++--------------- src/core/coresession.h | 23 ++++++++++++----------- 6 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/common/ignorelistmanager.cpp b/src/common/ignorelistmanager.cpp index bd37a20e..b4831c07 100644 --- a/src/common/ignorelistmanager.cpp +++ b/src/common/ignorelistmanager.cpp @@ -24,10 +24,7 @@ #include #include -#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()); diff --git a/src/common/ignorelistmanager.h b/src/common/ignorelistmanager.h index 171f8b23..b5bdf227 100644 --- a/src/common/ignorelistmanager.h +++ b/src/common/ignorelistmanager.h @@ -23,10 +23,9 @@ #include +#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 &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); diff --git a/src/core/coreignorelistmanager.cpp b/src/core/coreignorelistmanager.cpp index a1e298cc..e3cc70b4 100644 --- a/src/core/coreignorelistmanager.cpp +++ b/src/core/coreignorelistmanager.cpp @@ -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(parent()); if(!session) { diff --git a/src/core/coreignorelistmanager.h b/src/core/coreignorelistmanager.h index c12e323b..d7d5c9cf 100644 --- a/src/core/coreignorelistmanager.h +++ b/src/core/coreignorelistmanager.h @@ -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); } diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index c515faed..b7ac9df3 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -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 > 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); diff --git a/src/core/coresession.h b/src/core/coresession.h index 117f690e..4f341ee5 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -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 _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 -- 2.20.1