From d5420331259abba26a6764bc47243e74b91f1762 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 15 Jan 2025 17:50:42 -0500 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. --- 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 58ef4270d..37a2a8e37 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 21a9a6650..1a4c1181a 100644 --- a/src/neochatconnection.cpp +++ b/src/neochatconnection.cpp @@ -107,10 +107,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 d3a652ac9..c0401d154 100644 --- a/src/neochatconnection.h +++ b/src/neochatconnection.h @@ -207,11 +207,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 876b3f919..e518a1448 100644 --- a/src/neochatroom.cpp +++ b/src/neochatroom.cpp @@ -127,9 +127,6 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS updatePushNotificationState(u"m.push_rules"_s); 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 062f938cd..d8bcbb6d2 100644 --- a/src/neochatroom.h +++ b/src/neochatroom.h @@ -706,14 +706,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 a7b1d13cc..f4a9edb6d 100644 --- a/src/notificationsmanager.cpp +++ b/src/notificationsmanager.cpp @@ -127,9 +127,8 @@ void NotificationsManager::processNotificationJob(QPointer co } auto sender = room->member(notification["event"_L1]["sender"_L1].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; }