diff --git a/src/libneochat/neochatconnection.cpp b/src/libneochat/neochatconnection.cpp index 5c15ce1ad..daa466214 100644 --- a/src/libneochat/neochatconnection.cpp +++ b/src/libneochat/neochatconnection.cpp @@ -95,6 +95,7 @@ void NeoChatConnection::connectSignals() Q_EMIT directChatsHaveHighlightNotificationsChanged(); }); } + Q_EMIT roomInvitesChanged(); connect(room, &Room::unreadStatsChanged, this, [this]() { refreshBadgeNotificationCount(); Q_EMIT homeNotificationsChanged(); @@ -456,15 +457,20 @@ bool NeoChatConnection::homeHaveHighlightNotifications() const return false; } -bool NeoChatConnection::directChatInvites() const +qsizetype NeoChatConnection::directChatInvites() const { - auto inviteRooms = rooms(JoinState::Invite); - for (const auto inviteRoom : inviteRooms) { - if (inviteRoom->isDirectChat()) { - return true; - } - } - return false; + const auto inviteRooms = rooms(JoinState::Invite); + return std::ranges::count_if(inviteRooms, [](const auto room) { + return room->isDirectChat(); + }); +} + +qsizetype NeoChatConnection::roomInvites() const +{ + const auto inviteRooms = rooms(JoinState::Invite); + return std::ranges::count_if(inviteRooms, [](const auto room) { + return !room->isDirectChat(); + }); } QCoro::Task NeoChatConnection::setupPushNotifications(QString endpoint) diff --git a/src/libneochat/neochatconnection.h b/src/libneochat/neochatconnection.h index 8389481df..41841c07a 100644 --- a/src/libneochat/neochatconnection.h +++ b/src/libneochat/neochatconnection.h @@ -66,9 +66,14 @@ class NeoChatConnection : public Quotient::Connection Q_PROPERTY(bool homeHaveHighlightNotifications READ homeHaveHighlightNotifications NOTIFY homeHaveHighlightNotificationsChanged) /** - * @brief Whether there is at least one invite to a direct chat. + * @brief The number of invites to 1-on-1 direct chats. */ - Q_PROPERTY(bool directChatInvites READ directChatInvites NOTIFY directChatInvitesChanged) + Q_PROPERTY(qsizetype directChatInvites READ directChatInvites NOTIFY directChatInvitesChanged) + + /** + * @brief The number of pending, normal room invites. + */ + Q_PROPERTY(qsizetype roomInvites READ roomInvites NOTIFY roomInvitesChanged) /** * @brief Whether the server supports querying a user's mutual rooms. @@ -200,7 +205,8 @@ public: */ static void setKeywordPushRuleDefault(PushRuleAction::Action defaultAction); - bool directChatInvites() const; + qsizetype directChatInvites() const; + qsizetype roomInvites() const; // note: this is intentionally a copied QString because // the reference could be destroyed before the task is finished @@ -225,6 +231,7 @@ Q_SIGNALS: void homeNotificationsChanged(); void homeHaveHighlightNotificationsChanged(); void directChatInvitesChanged(); + void roomInvitesChanged(); void passwordStatus(NeoChatConnection::PasswordStatus status); void userConsentRequired(QUrl url); void badgeNotificationCountChanged(int count); diff --git a/src/rooms/SpaceDrawer.qml b/src/rooms/SpaceDrawer.qml index 99b6fcede..128e08d86 100644 --- a/src/rooms/SpaceDrawer.qml +++ b/src/rooms/SpaceDrawer.qml @@ -81,12 +81,15 @@ QQC2.Control { AvatarTabButton { id: allRoomButton + readonly property int countedNotifications: root.connection.homeNotifications + root.connection.roomInvites + readonly property bool hasCountableNotifications: countedNotifications > 0 + Layout.fillWidth: true Layout.preferredHeight: width - Kirigami.Units.smallSpacing Layout.maximumHeight: width - Kirigami.Units.smallSpacing Layout.topMargin: Kirigami.Units.smallSpacing / 2 - text: i18n("Home") + text: hasCountableNotifications ? i18ncp("Home space for the uncategorized rooms", "Home (%1 notification)", "Home (%1 notifications)", countedNotifications) : i18nc("Home space for the uncategorized rooms", "Home") contentItem: Kirigami.Icon { source: "user-home-symbolic" @@ -100,15 +103,15 @@ QQC2.Control { width: Math.max(homeNotificationCountTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height) height: Kirigami.Units.iconSizes.smallMedium - text: root.connection.homeNotifications > 0 ? root.connection.homeNotifications : "" - visible: root.connection.homeNotifications > 0 && (RoomManager.currentSpace.length > 0 || RoomManager.currentSpace !== "DM") + text: allRoomButton.countedNotifications + visible: allRoomButton.hasCountableNotifications && (RoomManager.currentSpace.length > 0 || RoomManager.currentSpace !== "DM") color: Kirigami.Theme.textColor horizontalAlignment: Text.AlignHCenter background: Rectangle { visible: true Kirigami.Theme.colorSet: Kirigami.Theme.Button Kirigami.Theme.inherit: false - color: root.connection.homeHaveHighlightNotifications ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.backgroundColor + color: root.connection.homeHaveHighlightNotifications || root.connection.roomInvites > 0 ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.backgroundColor radius: height / 2 } @@ -127,7 +130,8 @@ QQC2.Control { AvatarTabButton { id: directChatButton - readonly property bool hasCountableNotifications: root.connection.directChatNotifications > 0 || root.connection.directChatInvites > 0 + readonly property int countedNotifications: root.connection.directChatNotifications + root.connection.directChatInvites + readonly property bool hasCountableNotifications: countedNotifications > 0 Layout.fillWidth: true Layout.preferredHeight: width - Kirigami.Units.smallSpacing @@ -136,7 +140,7 @@ QQC2.Control { text: { if (directChatButton.hasCountableNotifications) { - return i18ncp("@button View all one-on-one chats.", "Direct Messages (%1 notification)", "Direct Messages (%1 notifications)", root.connection.directChatNotifications + root.connection.directChatInvites); + return i18ncp("@button View all one-on-one chats.", "Direct Messages (%1 notification)", "Direct Messages (%1 notifications)", directChatButton.countedNotifications); } return i18nc("@button View all one-on-one chats.", "Direct Messages"); @@ -162,7 +166,7 @@ QQC2.Control { visible: true Kirigami.Theme.colorSet: Kirigami.Theme.Button Kirigami.Theme.inherit: false - color: root.connection.directChatsHaveHighlightNotifications || root.connection.directChatInvites ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.backgroundColor + color: root.connection.directChatsHaveHighlightNotifications || root.connection.directChatInvites > 0 ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.backgroundColor radius: height / 2 }