X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fclient%2Fmessagefilter.cpp;h=578f340ef004f64d2973e531817a24895ff7e889;hp=1001ea321a265452df84b0ba3c33825e3a737d3f;hb=158443f71d48215eea8b47b836b61afd77654b78;hpb=d6dd4ff24cade95ed49570786c8b81f10c6bddce diff --git a/src/client/messagefilter.cpp b/src/client/messagefilter.cpp index 1001ea32..578f340e 100644 --- a/src/client/messagefilter.cpp +++ b/src/client/messagefilter.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2015 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -20,6 +20,8 @@ #include "messagefilter.h" +#include + #include "buffersettings.h" #include "client.h" #include "buffermodel.h" @@ -61,7 +63,7 @@ void MessageFilter::init() _messageTypeFilter = defaultSettings.messageFilter(); defaultSettings.notify("MessageTypeFilter", this, SLOT(messageTypeFilterChanged())); - BufferSettings mySettings(idString()); + BufferSettings mySettings(MessageFilter::idString()); if (mySettings.hasFilter()) _messageTypeFilter = mySettings.messageFilter(); mySettings.notify("MessageTypeFilter", this, SLOT(messageTypeFilterChanged())); @@ -81,7 +83,7 @@ void MessageFilter::messageTypeFilterChanged() if (_messageTypeFilter != newFilter) { _messageTypeFilter = newFilter; - _filteredQuitMsgs.clear(); + _filteredQuitMsgTime.clear(); invalidateFilter(); } } @@ -221,16 +223,30 @@ bool MessageFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourcePar if (myNetworkId != msgNetworkId) return false; - uint messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole).value().toTime_t(); - QString quiter = sourceModel()->data(sourceIdx, Qt::DisplayRole).toString().section(' ', 0, 0, QString::SectionSkipEmpty).toLower(); + // Extract timestamp and nickname from the new quit message + qint64 messageTimestamp = sourceModel()->data(sourceIdx, MessageModel::TimestampRole) + .value().toMSecsSinceEpoch(); + QString quiter = nickFromMask(sourceModel()->data(sourceIdx, MessageModel::MessageRole) + .value().sender()).toLower(); + + // Check that nickname matches query name if (quiter != bufferName().toLower()) return false; - if (_filteredQuitMsgs.contains(quiter, messageTimestamp)) + // Check if a quit message was already forwarded within +/- 1000 ms + static constexpr qint64 MAX_QUIT_DELTA_MS = 1 * 1000; + // No need to check if it's the appropriate buffer, each query has a unique message filter + if (std::binary_search(_filteredQuitMsgTime.begin(), _filteredQuitMsgTime.end(), + messageTimestamp, + [](qint64 a, qint64 b) { return ((a + MAX_QUIT_DELTA_MS) < b); } )) { + // New element is less than if at least 1000 ms older/newer + // Match found, no need to forward another quit message return false; + } + // Mark query as having a quit message inserted MessageFilter *that = const_cast(this); - that->_filteredQuitMsgs.insert(quiter, messageTimestamp); + that->_filteredQuitMsgTime.insert(messageTimestamp); return true; } }