diff --git a/include/ChatPage.h b/include/ChatPage.h index f784231a..3a11f091 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -128,6 +128,8 @@ private: void updateUserMetadata(const std::vector &collection); void retryInitialSync(); + //! Update the room with the new notification count. + void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count); QHBoxLayout *topLayout_; Splitter *splitter; diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index 4e3fe0ce..213f0479 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -68,7 +68,7 @@ public: RoomInfoListItem(QString room_id, mtx::responses::InvitedRoom room, QWidget *parent = 0); void updateUnreadMessageCount(int count); - void clearUnreadMessageCount(); + void clearUnreadMessageCount() { updateUnreadMessageCount(0); }; void setState(QSharedPointer state) { state_ = state; diff --git a/include/RoomList.h b/include/RoomList.h index 7ceffd22..bcac8094 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -76,7 +76,6 @@ public slots: void updateUnreadMessageCount(const QString &roomid, int count); void updateRoomDescription(const QString &roomid, const DescInfo &info); void closeJoinRoomDialog(bool isJoining, QString roomAlias); - void clearRoomMessageCount(const QString &room_id); protected: void paintEvent(QPaintEvent *event) override; diff --git a/include/timeline/TimelineView.h b/include/timeline/TimelineView.h index fb7c6485..6e1287c8 100644 --- a/include/timeline/TimelineView.h +++ b/include/timeline/TimelineView.h @@ -83,7 +83,7 @@ public: QWidget *parent = 0); // Add new events at the end of the timeline. - int addEvents(const mtx::responses::Timeline &timeline); + void addEvents(const mtx::responses::Timeline &timeline); void addUserMessage(mtx::events::MessageType ty, const QString &msg); template @@ -113,7 +113,6 @@ private slots: signals: void updateLastTimelineMessage(const QString &user, const DescInfo &info); - void clearUnreadMessageCount(const QString &room_id); protected: void paintEvent(QPaintEvent *event) override; diff --git a/include/timeline/TimelineViewManager.h b/include/timeline/TimelineViewManager.h index e3cc311e..74d8588c 100644 --- a/include/timeline/TimelineViewManager.h +++ b/include/timeline/TimelineViewManager.h @@ -57,7 +57,6 @@ public: signals: void clearRoomMessageCount(QString roomid); - void unreadMessages(QString roomid, int count); void updateRoomsLastMessage(const QString &user, const DescInfo &info); public slots: diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 64368da2..42884567 100644 --- a/src/ChatPage.cc +++ b/src/ChatPage.cc @@ -175,25 +175,6 @@ ChatPage::ChatPage(QSharedPointer client, connect(room_list_, &RoomList::acceptInvite, client_.data(), &MatrixClient::joinRoom); connect(room_list_, &RoomList::declineInvite, client_.data(), &MatrixClient::leaveRoom); - connect(view_manager_, - &TimelineViewManager::clearRoomMessageCount, - room_list_, - &RoomList::clearRoomMessageCount); - - connect(view_manager_, - &TimelineViewManager::unreadMessages, - this, - [=](const QString &roomid, int count) { - if (roomSettings_.find(roomid) == roomSettings_.end()) { - qWarning() << "RoomId does not have settings" << roomid; - room_list_->updateUnreadMessageCount(roomid, count); - return; - } - - if (roomSettings_[roomid]->isNotificationsEnabled()) - room_list_->updateUnreadMessageCount(roomid, count); - }); - connect(text_input_, &TextInputWidget::startedTyping, this, [=]() { if (!userSettings_->isTypingNotificationsEnabled()) return; @@ -844,6 +825,8 @@ ChatPage::updateJoinedRooms(const std::mapfirst); updateTypingUsers(roomid, it->second.ephemeral.typing); + updateRoomNotificationCount(roomid, + it->second.unread_notifications.notification_count); if (it->second.ephemeral.receipts.size() > 0) QtConcurrent::run(cache_.data(), @@ -988,3 +971,9 @@ ChatPage::retryInitialSync() client_->initialSync(); initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT); } + +void +ChatPage::updateRoomNotificationCount(const QString &room_id, uint16_t notification_count) +{ + room_list_->updateUnreadMessageCount(room_id, notification_count); +} diff --git a/src/MatrixClient.cc b/src/MatrixClient.cc index b51c14c8..1d42e36c 100644 --- a/src/MatrixClient.cc +++ b/src/MatrixClient.cc @@ -1181,14 +1181,14 @@ MatrixClient::readEvent(const QString &room_id, const QString &event_id) query.addQueryItem("access_token", token_); QUrl endpoint(server_); - endpoint.setPath(clientApiUrl_ + - QString("/rooms/%1/receipt/m.read/%2").arg(room_id).arg(event_id)); + endpoint.setPath(clientApiUrl_ + QString("/rooms/%1/read_markers").arg(room_id)); endpoint.setQuery(query); QNetworkRequest request(QString(endpoint.toEncoded())); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); - auto reply = post(request, "{}"); + QJsonObject body({{"m.fully_read", event_id}, {"m.read", event_id}}); + auto reply = post(request, QJsonDocument(body).toJson(QJsonDocument::Compact)); connect(reply, &QNetworkReply::finished, this, [reply]() { reply->deleteLater(); diff --git a/src/RoomInfoListItem.cc b/src/RoomInfoListItem.cc index 45ee6148..29d7d339 100644 --- a/src/RoomInfoListItem.cc +++ b/src/RoomInfoListItem.cc @@ -303,14 +303,7 @@ RoomInfoListItem::paintEvent(QPaintEvent *event) void RoomInfoListItem::updateUnreadMessageCount(int count) { - unreadMsgCount_ += count; - update(); -} - -void -RoomInfoListItem::clearUnreadMessageCount() -{ - unreadMsgCount_ = 0; + unreadMsgCount_ = count; update(); } diff --git a/src/RoomList.cc b/src/RoomList.cc index d4b12690..bb4b7956 100644 --- a/src/RoomList.cc +++ b/src/RoomList.cc @@ -213,18 +213,6 @@ RoomList::sync(const std::map> &states, } } -void -RoomList::clearRoomMessageCount(const QString &room_id) -{ - if (!roomExists(room_id)) - return; - - auto room = rooms_[room_id]; - room->clearUnreadMessageCount(); - - calculateUnreadMessageCount(); -} - void RoomList::highlightSelectedRoom(const QString &room_id) { @@ -235,10 +223,6 @@ RoomList::highlightSelectedRoom(const QString &room_id) return; } - clearRoomMessageCount(room_id); - - calculateUnreadMessageCount(); - for (auto const &room : rooms_) { if (room.second.isNull()) continue; diff --git a/src/timeline/TimelineView.cc b/src/timeline/TimelineView.cc index d32832a4..063b9f9d 100644 --- a/src/timeline/TimelineView.cc +++ b/src/timeline/TimelineView.cc @@ -290,11 +290,9 @@ TimelineView::renderTopEvents(const std::vector &events) lastSender_ = items.at(0)->descriptionMessage().userid; } -int +void TimelineView::addEvents(const mtx::responses::Timeline &timeline) { - int message_count = 0; - if (isInitialSync) { prev_batch_token_ = QString::fromStdString(timeline.prev_batch); isInitialSync = false; @@ -306,8 +304,8 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline) bottomMessages_.push_back(e); // Calculate notifications. - if (isNotifiable(e)) - message_count += 1; + /* if (isNotifiable(e)) */ + /* sendNotification() */ } if (!bottomMessages_.empty()) @@ -324,8 +322,6 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline) if (isActiveWindow()) readLastEvent(); } - - return message_count; } inline bool @@ -685,12 +681,8 @@ TimelineView::showEvent(QShowEvent *event) bool TimelineView::event(QEvent *event) { - if (event->type() == QEvent::WindowActivate) { - QTimer::singleShot(1000, this, [=]() { - emit clearUnreadMessageCount(room_id_); - readLastEvent(); - }); - } + if (event->type() == QEvent::WindowActivate) + readLastEvent(); return QWidget::event(event); } diff --git a/src/timeline/TimelineViewManager.cc b/src/timeline/TimelineViewManager.cc index fdc3b9e2..7bee8869 100644 --- a/src/timeline/TimelineViewManager.cc +++ b/src/timeline/TimelineViewManager.cc @@ -159,10 +159,6 @@ TimelineViewManager::addRoom(const mtx::responses::JoinedRoom &room, const QStri &TimelineView::updateLastTimelineMessage, this, &TimelineViewManager::updateRoomsLastMessage); - connect(view, - &TimelineView::clearUnreadMessageCount, - this, - &TimelineViewManager::clearRoomMessageCount); // Add the view in the widget stack. addWidget(view); @@ -179,10 +175,6 @@ TimelineViewManager::addRoom(const QString &room_id) &TimelineView::updateLastTimelineMessage, this, &TimelineViewManager::updateRoomsLastMessage); - connect(view, - &TimelineView::clearUnreadMessageCount, - this, - &TimelineViewManager::clearRoomMessageCount); // Add the view in the widget stack. addWidget(view); @@ -201,16 +193,7 @@ TimelineViewManager::sync(const mtx::responses::Rooms &rooms) auto view = views_.at(roomid); - int msgs_added = view->addEvents(it->second.timeline); - - if (msgs_added > 0) { - // TODO: When the app window gets active the current - // unread count (if any) should be cleared. - auto isAppActive = QApplication::activeWindow() != nullptr; - - if (roomid != active_room_ || !isAppActive) - emit unreadMessages(roomid, msgs_added); - } + view->addEvents(it->second.timeline); } }