From 54ead1bace1c9306ccfd5ebd7fb7bbd0c9843db7 Mon Sep 17 00:00:00 2001 From: Janne Koschinski Date: Sun, 27 Aug 2017 02:02:29 +0200 Subject: [PATCH] Implement client UI integration, add feature flag (0x400) --- src/client/client.cpp | 21 +++++++---- src/client/client.h | 4 +- src/client/networkmodel.cpp | 46 +++++++++++++++++++---- src/client/networkmodel.h | 3 ++ src/common/buffersyncer.h | 11 +++++- src/common/quassel.h | 6 +-- src/core/corebuffersyncer.h | 2 +- src/uisupport/abstractbuffercontainer.cpp | 4 +- 8 files changed, 76 insertions(+), 21 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 5319a9a6..8875b70b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -390,6 +390,7 @@ void Client::setSyncedToCore() connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), this, SLOT(buffersPermanentlyMerged(BufferId, BufferId))); connect(bufferSyncer(), SIGNAL(buffersPermanentlyMerged(BufferId, BufferId)), _messageModel, SLOT(buffersPermanentlyMerged(BufferId, BufferId))); connect(bufferSyncer(), SIGNAL(bufferMarkedAsRead(BufferId)), SIGNAL(bufferMarkedAsRead(BufferId))); + connect(bufferSyncer(), SIGNAL(bufferActivityChange(BufferId, const Message::Types)), _networkModel, SLOT(bufferActivityChanged(BufferId, const Message::Types))); connect(networkModel(), SIGNAL(requestSetLastSeenMsg(BufferId, MsgId)), bufferSyncer(), SLOT(requestSetLastSeenMsg(BufferId, const MsgId &))); SignalProxy *p = signalProxy(); @@ -428,27 +429,33 @@ void Client::setSyncedToCore() } // trigger backlog request once all active bufferviews are initialized - connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + connect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(finishConnectionInitialization())); _connected = true; emit connected(); emit coreConnectionStateChanged(true); } - -void Client::requestInitialBacklog() +void Client::finishConnectionInitialization() { // usually it _should_ take longer until the bufferViews are initialized, so that's what // triggers this slot. But we have to make sure that we know all buffers yet. // so we check the BufferSyncer and in case it wasn't initialized we wait for that instead if (!bufferSyncer()->isInitialized()) { - disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); - connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(finishConnectionInitialization())); + connect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(finishConnectionInitialization())); return; } - disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); - disconnect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(requestInitialBacklog())); + disconnect(bufferViewOverlay(), SIGNAL(initDone()), this, SLOT(finishConnectionInitialization())); + disconnect(bufferSyncer(), SIGNAL(initDone()), this, SLOT(finishConnectionInitialization())); + + requestInitialBacklog(); + bufferSyncer()->markActivitiesChanged(); +} + +void Client::requestInitialBacklog() +{ _backlogManager->requestInitialBacklog(); } diff --git a/src/client/client.h b/src/client/client.h index ec5e9559..127a07f8 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -226,7 +226,7 @@ private slots: void corePasswordChanged(PeerPtr, bool success); - void requestInitialBacklog(); + void finishConnectionInitialization(); void sendBufferedUserInput(); @@ -235,6 +235,8 @@ private: virtual ~Client(); void init(); + void requestInitialBacklog(); + static void addNetwork(Network *); static inline BufferSyncer *bufferSyncer() { return instance()->_bufferSyncer; } diff --git a/src/client/networkmodel.cpp b/src/client/networkmodel.cpp index 974f31a6..f3896e58 100644 --- a/src/client/networkmodel.cpp +++ b/src/client/networkmodel.cpp @@ -307,6 +307,10 @@ void BufferItem::clearActivityLevel() void BufferItem::updateActivityLevel(const Message &msg) { + if (Client::coreFeatures().testFlag(Quassel::Feature::BufferActivitySync)) { + return; + } + if (isCurrentBuffer()) { return; } @@ -327,19 +331,35 @@ void BufferItem::updateActivityLevel(const Message &msg) _firstUnreadMsgId = msg.msgId(); } + if (addActivity(Message::Types(msg.type()), msg.flags().testFlag(Message::Highlight)) || stateChanged) { + emit dataChanged(); + } +} + +void BufferItem::setActivity(Message::Types type, bool highlight) { BufferInfo::ActivityLevel oldLevel = activityLevel(); - _activity |= BufferInfo::OtherActivity; - if (msg.type() & (Message::Plain | Message::Notice | Message::Action)) + _activity = BufferInfo::Activity(); + addActivity(type, highlight); + + if (_activity != oldLevel) { + emit dataChanged(); + } +} + +bool BufferItem::addActivity(Message::Types type, bool highlight) { + auto oldActivity = activityLevel(); + + if (type != 0) + _activity |= BufferInfo::OtherActivity; + + if (type.testFlag(Message::Plain) || type.testFlag(Message::Notice) || type.testFlag(Message::Action)) _activity |= BufferInfo::NewMessage; - if (msg.flags() & Message::Highlight) + if (highlight) _activity |= BufferInfo::Highlight; - stateChanged |= (oldLevel != _activity); - - if (stateChanged) - emit dataChanged(); + return oldActivity != _activity; } @@ -1706,3 +1726,15 @@ void NetworkModel::messageRedirectionSettingsChanged() _serverNoticesTarget = bufferSettings.serverNoticesTarget(); _errorMsgsTarget = bufferSettings.errorMsgsTarget(); } + +void NetworkModel::bufferActivityChanged(BufferId bufferId, const Message::Types activity) { + auto bufferItem = findBufferItem(bufferId); + if (!bufferItem) { + qDebug() << "NetworkModel::clearBufferActivity(): buffer is unknown:" << bufferId; + return; + } + auto hiddenTypes = BufferSettings(bufferId).messageFilter(); + auto visibleTypes = ~hiddenTypes; + auto activityVisibleTypesIntersection = activity & visibleTypes; + bufferItem->setActivity(activityVisibleTypesIntersection, false); +} diff --git a/src/client/networkmodel.h b/src/client/networkmodel.h index b2d3a3b8..c3577f4c 100644 --- a/src/client/networkmodel.h +++ b/src/client/networkmodel.h @@ -131,6 +131,8 @@ public : void setActivityLevel(BufferInfo::ActivityLevel level); void clearActivityLevel(); void updateActivityLevel(const Message &msg); + void setActivity(Message::Types msg, bool highlight); + bool addActivity(Message::Types msg, bool highlight); inline const MsgId &firstUnreadMsgId() const { return _firstUnreadMsgId; } @@ -383,6 +385,7 @@ public slots: void clearBufferActivity(const BufferId &bufferId); void updateBufferActivity(Message &msg); void networkRemoved(const NetworkId &networkId); + void bufferActivityChanged(BufferId, Message::Types); signals: void requestSetLastSeenMsg(BufferId buffer, MsgId msg); diff --git a/src/common/buffersyncer.h b/src/common/buffersyncer.h index 9faadfc6..ff78eb19 100644 --- a/src/common/buffersyncer.h +++ b/src/common/buffersyncer.h @@ -40,6 +40,12 @@ public: MsgId markerLine(BufferId buffer) const; Message::Types activity(BufferId buffer) const; + void markActivitiesChanged() { + for (auto buffer : _bufferActivities.keys()) { + emit bufferActivityChange(buffer, activity(buffer)); + } + } + public slots: QVariantList initLastSeenMsg() const; void initSetLastSeenMsg(const QVariantList &); @@ -54,8 +60,10 @@ public slots: virtual inline void requestSetMarkerLine(BufferId buffer, const MsgId &msgId) { REQUEST(ARG(buffer), ARG(msgId)) setMarkerLine(buffer, msgId); } virtual inline void setBufferActivity(BufferId buffer, const int &activity) { + auto flags = Message::Types(activity); SYNC(ARG(buffer), ARG(activity)); - _bufferActivities[buffer] = Message::Types(activity); + _bufferActivities[buffer] = flags; + emit bufferActivityChange(buffer, flags); } virtual inline void requestRemoveBuffer(BufferId buffer) { REQUEST(ARG(buffer)) } @@ -79,6 +87,7 @@ signals: void bufferRenamed(BufferId buffer, QString newName); void buffersPermanentlyMerged(BufferId buffer1, BufferId buffer2); void bufferMarkedAsRead(BufferId buffer); + void bufferActivityChange(BufferId, Message::Types); protected slots: bool setLastSeenMsg(BufferId buffer, const MsgId &msgId); diff --git a/src/common/quassel.h b/src/common/quassel.h index eb85ebf6..21aaec77 100644 --- a/src/common/quassel.h +++ b/src/common/quassel.h @@ -76,10 +76,10 @@ public: CustomRateLimits = 0x0080, /// IRC server custom message rate limits DccFileTransfer = 0x0100, AwayFormatTimestamp = 0x0200, /// Timestamp formatting in away (e.g. %%hh:mm%%) - // Whether or not the core supports auth backends. - Authenticators = 0x0400, + Authenticators = 0x0400, /// Whether or not the core supports auth backends. + BufferActivitySync = 0x0800, /// Sync buffer activity status - NumFeatures = 0x0400 + NumFeatures = 0x0800 }; Q_DECLARE_FLAGS(Features, Feature) diff --git a/src/core/corebuffersyncer.h b/src/core/corebuffersyncer.h index c490419a..af009d06 100644 --- a/src/core/corebuffersyncer.h +++ b/src/core/corebuffersyncer.h @@ -58,7 +58,7 @@ public slots: virtual void requestPurgeBufferIds(); virtual inline void requestMarkBufferAsRead(BufferId buffer) { - setLastSeenMsg(buffer, (int) Message::Types()); + setBufferActivity(buffer, (int) Message::Types()); markBufferAsRead(buffer); } diff --git a/src/uisupport/abstractbuffercontainer.cpp b/src/uisupport/abstractbuffercontainer.cpp index 0651d704..ca9c101d 100644 --- a/src/uisupport/abstractbuffercontainer.cpp +++ b/src/uisupport/abstractbuffercontainer.cpp @@ -126,7 +126,9 @@ void AbstractBufferContainer::setCurrentBuffer(BufferId bufferId) _currentBuffer = bufferId; showChatView(bufferId); - Client::networkModel()->clearBufferActivity(bufferId); + if (!Client::coreFeatures().testFlag(Quassel::Feature::BufferActivitySync)) { + Client::networkModel()->clearBufferActivity(bufferId); + } Client::setBufferLastSeenMsg(bufferId, _chatViews[bufferId]->lastMsgId()); Client::backlogManager()->checkForBacklog(bufferId); setFocus(); -- 2.20.1