summary refs log tree commit diff
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-02-15 21:58:57 +0200
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-02-15 21:58:57 +0200
commit86280098b49709fed6cc850f8ba28dac0b29c216 (patch)
treec308583ee8dee63f21984ff4ab4d165e350c8128
parentSimplify variant access with std::visit (diff)
downloadnheko-86280098b49709fed6cc850f8ba28dac0b29c216.tar.xz
Implement server-side notification count
-rw-r--r--include/ChatPage.h2
-rw-r--r--include/RoomInfoListItem.h2
-rw-r--r--include/RoomList.h1
-rw-r--r--include/timeline/TimelineView.h3
-rw-r--r--include/timeline/TimelineViewManager.h1
-rw-r--r--src/ChatPage.cc27
-rw-r--r--src/MatrixClient.cc6
-rw-r--r--src/RoomInfoListItem.cc9
-rw-r--r--src/RoomList.cc16
-rw-r--r--src/timeline/TimelineView.cc18
-rw-r--r--src/timeline/TimelineViewManager.cc19
11 files changed, 22 insertions, 82 deletions
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> &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<RoomState> 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<class Widget, mtx::events::MessageType MsgType> @@ -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<MatrixClient> 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::map<std::string, mtx::responses::JoinedRo const auto roomid = QString::fromStdString(it->first); 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
@@ -214,18 +214,6 @@ RoomList::sync(const std::map<QString, QSharedPointer<RoomState>> &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) { emit roomChanged(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<TimelineEvent> &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); } }