mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Implement server-side notification count
This commit is contained in:
parent
6d08e67abd
commit
86280098b4
11 changed files with 22 additions and 82 deletions
|
@ -128,6 +128,8 @@ private:
|
||||||
void updateUserMetadata(const std::vector<Collection> &collection);
|
void updateUserMetadata(const std::vector<Collection> &collection);
|
||||||
|
|
||||||
void retryInitialSync();
|
void retryInitialSync();
|
||||||
|
//! Update the room with the new notification count.
|
||||||
|
void updateRoomNotificationCount(const QString &room_id, uint16_t notification_count);
|
||||||
|
|
||||||
QHBoxLayout *topLayout_;
|
QHBoxLayout *topLayout_;
|
||||||
Splitter *splitter;
|
Splitter *splitter;
|
||||||
|
|
|
@ -68,7 +68,7 @@ public:
|
||||||
RoomInfoListItem(QString room_id, mtx::responses::InvitedRoom room, QWidget *parent = 0);
|
RoomInfoListItem(QString room_id, mtx::responses::InvitedRoom room, QWidget *parent = 0);
|
||||||
|
|
||||||
void updateUnreadMessageCount(int count);
|
void updateUnreadMessageCount(int count);
|
||||||
void clearUnreadMessageCount();
|
void clearUnreadMessageCount() { updateUnreadMessageCount(0); };
|
||||||
void setState(QSharedPointer<RoomState> state)
|
void setState(QSharedPointer<RoomState> state)
|
||||||
{
|
{
|
||||||
state_ = state;
|
state_ = state;
|
||||||
|
|
|
@ -76,7 +76,6 @@ public slots:
|
||||||
void updateUnreadMessageCount(const QString &roomid, int count);
|
void updateUnreadMessageCount(const QString &roomid, int count);
|
||||||
void updateRoomDescription(const QString &roomid, const DescInfo &info);
|
void updateRoomDescription(const QString &roomid, const DescInfo &info);
|
||||||
void closeJoinRoomDialog(bool isJoining, QString roomAlias);
|
void closeJoinRoomDialog(bool isJoining, QString roomAlias);
|
||||||
void clearRoomMessageCount(const QString &room_id);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
|
@ -83,7 +83,7 @@ public:
|
||||||
QWidget *parent = 0);
|
QWidget *parent = 0);
|
||||||
|
|
||||||
// Add new events at the end of the timeline.
|
// 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);
|
void addUserMessage(mtx::events::MessageType ty, const QString &msg);
|
||||||
|
|
||||||
template<class Widget, mtx::events::MessageType MsgType>
|
template<class Widget, mtx::events::MessageType MsgType>
|
||||||
|
@ -113,7 +113,6 @@ private slots:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateLastTimelineMessage(const QString &user, const DescInfo &info);
|
void updateLastTimelineMessage(const QString &user, const DescInfo &info);
|
||||||
void clearUnreadMessageCount(const QString &room_id);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
|
@ -57,7 +57,6 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clearRoomMessageCount(QString roomid);
|
void clearRoomMessageCount(QString roomid);
|
||||||
void unreadMessages(QString roomid, int count);
|
|
||||||
void updateRoomsLastMessage(const QString &user, const DescInfo &info);
|
void updateRoomsLastMessage(const QString &user, const DescInfo &info);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
|
@ -175,25 +175,6 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client,
|
||||||
connect(room_list_, &RoomList::acceptInvite, client_.data(), &MatrixClient::joinRoom);
|
connect(room_list_, &RoomList::acceptInvite, client_.data(), &MatrixClient::joinRoom);
|
||||||
connect(room_list_, &RoomList::declineInvite, client_.data(), &MatrixClient::leaveRoom);
|
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, [=]() {
|
connect(text_input_, &TextInputWidget::startedTyping, this, [=]() {
|
||||||
if (!userSettings_->isTypingNotificationsEnabled())
|
if (!userSettings_->isTypingNotificationsEnabled())
|
||||||
return;
|
return;
|
||||||
|
@ -844,6 +825,8 @@ ChatPage::updateJoinedRooms(const std::map<std::string, mtx::responses::JoinedRo
|
||||||
const auto roomid = QString::fromStdString(it->first);
|
const auto roomid = QString::fromStdString(it->first);
|
||||||
|
|
||||||
updateTypingUsers(roomid, it->second.ephemeral.typing);
|
updateTypingUsers(roomid, it->second.ephemeral.typing);
|
||||||
|
updateRoomNotificationCount(roomid,
|
||||||
|
it->second.unread_notifications.notification_count);
|
||||||
|
|
||||||
if (it->second.ephemeral.receipts.size() > 0)
|
if (it->second.ephemeral.receipts.size() > 0)
|
||||||
QtConcurrent::run(cache_.data(),
|
QtConcurrent::run(cache_.data(),
|
||||||
|
@ -988,3 +971,9 @@ ChatPage::retryInitialSync()
|
||||||
client_->initialSync();
|
client_->initialSync();
|
||||||
initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
|
initialSyncTimer_->start(INITIAL_SYNC_RETRY_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ChatPage::updateRoomNotificationCount(const QString &room_id, uint16_t notification_count)
|
||||||
|
{
|
||||||
|
room_list_->updateUnreadMessageCount(room_id, notification_count);
|
||||||
|
}
|
||||||
|
|
|
@ -1181,14 +1181,14 @@ MatrixClient::readEvent(const QString &room_id, const QString &event_id)
|
||||||
query.addQueryItem("access_token", token_);
|
query.addQueryItem("access_token", token_);
|
||||||
|
|
||||||
QUrl endpoint(server_);
|
QUrl endpoint(server_);
|
||||||
endpoint.setPath(clientApiUrl_ +
|
endpoint.setPath(clientApiUrl_ + QString("/rooms/%1/read_markers").arg(room_id));
|
||||||
QString("/rooms/%1/receipt/m.read/%2").arg(room_id).arg(event_id));
|
|
||||||
endpoint.setQuery(query);
|
endpoint.setQuery(query);
|
||||||
|
|
||||||
QNetworkRequest request(QString(endpoint.toEncoded()));
|
QNetworkRequest request(QString(endpoint.toEncoded()));
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
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]() {
|
connect(reply, &QNetworkReply::finished, this, [reply]() {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
|
@ -303,14 +303,7 @@ RoomInfoListItem::paintEvent(QPaintEvent *event)
|
||||||
void
|
void
|
||||||
RoomInfoListItem::updateUnreadMessageCount(int count)
|
RoomInfoListItem::updateUnreadMessageCount(int count)
|
||||||
{
|
{
|
||||||
unreadMsgCount_ += count;
|
unreadMsgCount_ = count;
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
RoomInfoListItem::clearUnreadMessageCount()
|
|
||||||
{
|
|
||||||
unreadMsgCount_ = 0;
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,18 +213,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
|
void
|
||||||
RoomList::highlightSelectedRoom(const QString &room_id)
|
RoomList::highlightSelectedRoom(const QString &room_id)
|
||||||
{
|
{
|
||||||
|
@ -235,10 +223,6 @@ RoomList::highlightSelectedRoom(const QString &room_id)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearRoomMessageCount(room_id);
|
|
||||||
|
|
||||||
calculateUnreadMessageCount();
|
|
||||||
|
|
||||||
for (auto const &room : rooms_) {
|
for (auto const &room : rooms_) {
|
||||||
if (room.second.isNull())
|
if (room.second.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -290,11 +290,9 @@ TimelineView::renderTopEvents(const std::vector<TimelineEvent> &events)
|
||||||
lastSender_ = items.at(0)->descriptionMessage().userid;
|
lastSender_ = items.at(0)->descriptionMessage().userid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
TimelineView::addEvents(const mtx::responses::Timeline &timeline)
|
TimelineView::addEvents(const mtx::responses::Timeline &timeline)
|
||||||
{
|
{
|
||||||
int message_count = 0;
|
|
||||||
|
|
||||||
if (isInitialSync) {
|
if (isInitialSync) {
|
||||||
prev_batch_token_ = QString::fromStdString(timeline.prev_batch);
|
prev_batch_token_ = QString::fromStdString(timeline.prev_batch);
|
||||||
isInitialSync = false;
|
isInitialSync = false;
|
||||||
|
@ -306,8 +304,8 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline)
|
||||||
bottomMessages_.push_back(e);
|
bottomMessages_.push_back(e);
|
||||||
|
|
||||||
// Calculate notifications.
|
// Calculate notifications.
|
||||||
if (isNotifiable(e))
|
/* if (isNotifiable(e)) */
|
||||||
message_count += 1;
|
/* sendNotification() */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bottomMessages_.empty())
|
if (!bottomMessages_.empty())
|
||||||
|
@ -324,8 +322,6 @@ TimelineView::addEvents(const mtx::responses::Timeline &timeline)
|
||||||
if (isActiveWindow())
|
if (isActiveWindow())
|
||||||
readLastEvent();
|
readLastEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
return message_count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool
|
inline bool
|
||||||
|
@ -685,12 +681,8 @@ TimelineView::showEvent(QShowEvent *event)
|
||||||
bool
|
bool
|
||||||
TimelineView::event(QEvent *event)
|
TimelineView::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::WindowActivate) {
|
if (event->type() == QEvent::WindowActivate)
|
||||||
QTimer::singleShot(1000, this, [=]() {
|
readLastEvent();
|
||||||
emit clearUnreadMessageCount(room_id_);
|
|
||||||
readLastEvent();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return QWidget::event(event);
|
return QWidget::event(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,10 +159,6 @@ TimelineViewManager::addRoom(const mtx::responses::JoinedRoom &room, const QStri
|
||||||
&TimelineView::updateLastTimelineMessage,
|
&TimelineView::updateLastTimelineMessage,
|
||||||
this,
|
this,
|
||||||
&TimelineViewManager::updateRoomsLastMessage);
|
&TimelineViewManager::updateRoomsLastMessage);
|
||||||
connect(view,
|
|
||||||
&TimelineView::clearUnreadMessageCount,
|
|
||||||
this,
|
|
||||||
&TimelineViewManager::clearRoomMessageCount);
|
|
||||||
|
|
||||||
// Add the view in the widget stack.
|
// Add the view in the widget stack.
|
||||||
addWidget(view);
|
addWidget(view);
|
||||||
|
@ -179,10 +175,6 @@ TimelineViewManager::addRoom(const QString &room_id)
|
||||||
&TimelineView::updateLastTimelineMessage,
|
&TimelineView::updateLastTimelineMessage,
|
||||||
this,
|
this,
|
||||||
&TimelineViewManager::updateRoomsLastMessage);
|
&TimelineViewManager::updateRoomsLastMessage);
|
||||||
connect(view,
|
|
||||||
&TimelineView::clearUnreadMessageCount,
|
|
||||||
this,
|
|
||||||
&TimelineViewManager::clearRoomMessageCount);
|
|
||||||
|
|
||||||
// Add the view in the widget stack.
|
// Add the view in the widget stack.
|
||||||
addWidget(view);
|
addWidget(view);
|
||||||
|
@ -201,16 +193,7 @@ TimelineViewManager::sync(const mtx::responses::Rooms &rooms)
|
||||||
|
|
||||||
auto view = views_.at(roomid);
|
auto view = views_.at(roomid);
|
||||||
|
|
||||||
int msgs_added = view->addEvents(it->second.timeline);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue