summary refs log tree commit diff
path: root/src
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 /src
parentSimplify variant access with std::visit (diff)
downloadnheko-86280098b49709fed6cc850f8ba28dac0b29c216.tar.xz
Implement server-side notification count
Diffstat (limited to 'src')
-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
6 files changed, 18 insertions, 77 deletions
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); } }