#include <QStringList>
#include <QRegExp>
-#include "message.h"
-
INIT_SYNCABLE_OBJECT(IgnoreListManager)
-
IgnoreListManager &IgnoreListManager::operator=(const IgnoreListManager &other) {
if(this == &other)
return *this;
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);
return UnmatchedStrictness;
}
+
bool IgnoreListManager::scopeMatch(const QString &scopeRule, const QString &string) const {
foreach(QString rule, scopeRule.split(";")) {
QRegExp ruleRx = QRegExp(rule.trimmed());
#include <QString>
+#include "message.h"
#include "syncableobject.h"
-class Message;
-
class IgnoreListManager : public SyncableObject
{
SYNCABLE_OBJECT
* \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());
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);
#include "coresession.h"
INIT_SYNCABLE_OBJECT(CoreIgnoreListManager)
-
CoreIgnoreListManager::CoreIgnoreListManager(CoreSession *parent)
: IgnoreListManager(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) {
#include "ignorelistmanager.h"
class CoreSession;
+struct RawMessage;
class CoreIgnoreListManager : public IgnoreListManager {
SYNCABLE_OBJECT
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); }
// 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());
}
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;
}
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);
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