Implement client UI integration, add feature flag (0x400)
authorJanne Koschinski <janne@kuschku.de>
Sun, 27 Aug 2017 00:02:29 +0000 (02:02 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 19 Dec 2017 20:08:33 +0000 (21:08 +0100)
src/client/client.cpp
src/client/client.h
src/client/networkmodel.cpp
src/client/networkmodel.h
src/common/buffersyncer.h
src/common/quassel.h
src/core/corebuffersyncer.h
src/uisupport/abstractbuffercontainer.cpp

index 5319a9a..8875b70 100644 (file)
@@ -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();
 }
 
index ec5e955..127a07f 100644 (file)
@@ -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; }
 
index 974f31a..f3896e5 100644 (file)
@@ -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);
+}
index b2d3a3b..c3577f4 100644 (file)
@@ -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);
index 9faadfc..ff78eb1 100644 (file)
@@ -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);
index eb85ebf..21aaec7 100644 (file)
@@ -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)
 
index c490419..af009d0 100644 (file)
@@ -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);
     }
 
index 0651d70..ca9c101 100644 (file)
@@ -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();