From 46b95662425498d959850d572984b2da6f59a370 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Thu, 16 Jan 2025 20:49:07 +0000 Subject: [PATCH] Don't spam pending invites every time NeoChat is started Currently the way we show invite notifications is sub-optimal. We did it during the initial room state load, which meant it shows an invite notification *every time* you opened NeoChat. This gets annoying very quickly if you have any pending invitations you don't want to take action on just yet. Instead, let's handle this in NotificationsManager directly, and also remove some scaffolding now that it isn't plumbed through NeoChatRoom/NeoChatConnection. (cherry picked from commit d5420331259abba26a6764bc47243e74b91f1762) Co-authored-by: Joshua Goins --- src/controller.cpp | 1 - src/neochatconnection.cpp | 4 ---- src/neochatconnection.h | 5 ----- src/neochatroom.cpp | 3 --- src/neochatroom.h | 8 -------- src/notificationsmanager.cpp | 3 +-- 6 files changed, 1 insertion(+), 23 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index 4c54896a7..bc4445b58 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -168,7 +168,6 @@ void Controller::addConnection(NeoChatConnection *c) connect(c, &NeoChatConnection::syncDone, this, [this, c]() { m_notificationsManager.handleNotifications(c); }); - connect(c, &NeoChatConnection::showInviteNotification, &m_notificationsManager, &NotificationsManager::postInviteNotification); c->sync(); diff --git a/src/neochatconnection.cpp b/src/neochatconnection.cpp index 74dd8a4e2..cd14f8ce8 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -109,10 +109,6 @@ void NeoChatConnection::connectSignals() Q_EMIT homeHaveHighlightNotificationsChanged(); }); }); - connect(this, &NeoChatConnection::invitedRoom, this, [this](Quotient::Room *room) { - auto r = dynamic_cast(room); - connect(r, &NeoChatRoom::showInviteNotification, this, &NeoChatConnection::showInviteNotification); - }); connect(this, &NeoChatConnection::leftRoom, this, [this](Room *room, Room *prev) { Q_UNUSED(room) if (prev && prev->isDirectChat()) { diff --git a/src/neochatconnection.h b/src/neochatconnection.h index 79054994c..06c5cfccc 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -205,11 +205,6 @@ Q_SIGNALS: */ void errorOccured(const QString &error); - /** - * @brief Request a notification be shown for an invite to this room. - */ - void showInviteNotification(NeoChatRoom *room); - private: bool m_isOnline = true; void setIsOnline(bool isOnline); diff --git a/src/neochatroom.cpp b/src/neochatroom.cpp index d8ef7aac0..c82b8e777 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -124,9 +124,6 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS updatePushNotificationState(QStringLiteral("m.push_rules")); Q_EMIT canEncryptRoomChanged(); - if (this->joinState() == JoinState::Invite) { - Q_EMIT showInviteNotification(this); - } }, Qt::SingleShotConnection); connect(this, &Room::changed, this, [this] { diff --git a/src/neochatroom.h b/src/neochatroom.h index 849ca5707..76ffb7944 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -654,14 +654,6 @@ Q_SIGNALS: */ void showMessage(MessageType::Type messageType, const QString &message); - /** - * @brief Request a notification be shown for an invite to this room. - * - * @note This may later be blocked if there are any rules on where invites can - * come from, but this is not NeoChatRoom's responsibility. - */ - void showInviteNotification(NeoChatRoom *room); - public Q_SLOTS: /** * @brief Upload a file to the matrix server and post the file to the room. diff --git a/src/notificationsmanager.cpp b/src/notificationsmanager.cpp index ebe17f2a4..dcef8f7a9 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -127,9 +127,8 @@ void NotificationsManager::processNotificationJob(QPointer co } auto sender = room->member(notification["event"_ls]["sender"_ls].toString()); - // Don't display notifications for events in invited rooms - // This should prevent empty notifications from appearing when they shouldn't if (room->joinState() == JoinState::Invite) { + postInviteNotification(qobject_cast(room)); continue; }