From f844cd1a2f7f83fa40a029468d1980e98667aa72 Mon Sep 17 00:00:00 2001 From: Mauro <34335419+Velin92@users.noreply.github.com> Date: Fri, 22 Dec 2023 17:57:07 +0100 Subject: [PATCH] MentionBadge FF (#2281) --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 +- .../Sources/Application/AppSettings.swift | 4 + .../Screens/HomeScreen/HomeScreenModels.swift | 3 + .../HomeScreen/HomeScreenViewModel.swift | 8 +- .../HomeScreen/View/HomeScreenRoomCell.swift | 129 ++++++++++++------ .../View/InvitesScreenCell.swift | 6 +- .../DeveloperOptionsScreenModels.swift | 1 + .../View/DeveloperOptionsScreen.swift | 7 + .../RoomNotificationModeProxy.swift | 2 +- .../RoomSummary/MockRoomSummaryProvider.swift | 78 +++++++++-- .../Room/RoomSummary/RoomSummaryDetails.swift | 23 +++- .../RoomSummary/RoomSummaryProvider.swift | 3 +- UnitTests/Sources/LoggingTests.swift | 3 +- .../PreviewTests/test_homeScreen.Loaded.png | 4 +- .../test_homeScreenRoomCell.1.png | 3 - .../test_homeScreenRoomCell.Generic.png | 3 + ...homeScreenRoomCell.Notifications-State.png | 3 + changelog.d/2281.feature | 1 + project.yml | 2 +- 20 files changed, 216 insertions(+), 73 deletions(-) delete mode 100644 UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.1.png create mode 100644 UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Generic.png create mode 100644 UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Notifications-State.png create mode 100644 changelog.d/2281.feature diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 319aa188a4..299f2a310c 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -6650,7 +6650,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = "0.0.1-december23"; + version = 1.1.31; }; }; 821C67C9A7F8CC3FD41B28B4 /* XCRemoteSwiftPackageReference "emojibase-bindings" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 66101085d1..d2ddf01a7e 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -130,8 +130,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "c0027815b6ac690837e4f437ae874e7a4b5bc2a7", - "version" : "0.0.1-december23" + "revision" : "c9c6725af2c9fa93c19f710e307b0b25e0f1fa26", + "version" : "1.1.31" } }, { diff --git a/ElementX/Sources/Application/AppSettings.swift b/ElementX/Sources/Application/AppSettings.swift index 74f3864055..6a72393350 100644 --- a/ElementX/Sources/Application/AppSettings.swift +++ b/ElementX/Sources/Application/AppSettings.swift @@ -45,6 +45,7 @@ final class AppSettings { case shouldCollapseRoomStateEvents case userSuggestionsEnabled case swiftUITimelineEnabled + case mentionsBadgeEnabled } private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier @@ -266,6 +267,9 @@ final class AppSettings { @UserPreference(key: UserDefaultsKeys.swiftUITimelineEnabled, defaultValue: false, storageType: .volatile) var swiftUITimelineEnabled + + @UserPreference(key: UserDefaultsKeys.mentionsBadgeEnabled, defaultValue: false, storageType: .userDefaults(store)) + var mentionsBadgeEnabled #endif diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift index a9f5a82ed1..9dea90a929 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift @@ -147,6 +147,8 @@ struct HomeScreenRoom: Identifiable, Equatable { var hasUnreads = false + var hasMentions = false + var hasOngoingCall = false var timestamp: String? @@ -164,6 +166,7 @@ struct HomeScreenRoom: Identifiable, Equatable { roomId: nil, name: "Placeholder room name", hasUnreads: false, + hasMentions: false, timestamp: "Now", lastMessage: placeholderLastMessage, isPlaceholder: true) diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index c9493baa67..effa07d5e3 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -287,18 +287,18 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol private func buildRoom(with details: RoomSummaryDetails, invalidated: Bool) -> HomeScreenRoom { let identifier = invalidated ? "invalidated-" + details.id : details.id - - let notificationMode = details.notificationMode == .allMessages ? nil : details.notificationMode + let hasMentions = appSettings.mentionsBadgeEnabled ? details.unreadMentionsCount > 0 : false return HomeScreenRoom(id: identifier, roomId: details.id, name: details.name, - hasUnreads: details.unreadNotificationCount > 0, + hasUnreads: details.unreadMessagesCount > 0, + hasMentions: hasMentions, hasOngoingCall: details.hasOngoingCall, timestamp: details.lastMessageFormattedTimestamp, lastMessage: details.lastMessage, avatarURL: details.avatarURL, - notificationMode: notificationMode) + notificationMode: details.notificationMode) } private func updateVisibleRange(_ range: Range) { diff --git a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift index 3d4e8b9516..9def8d4e96 100644 --- a/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift +++ b/ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift @@ -95,8 +95,8 @@ struct HomeScreenRoomCell: View { if let timestamp = room.timestamp { Text(timestamp) - .font(room.hasUnreads ? .compound.bodySMSemibold : .compound.bodySM) - .foregroundColor(room.hasUnreads ? .compound.textActionAccent : .compound.textSecondary) + .font(isHighlighted ? .compound.bodySMSemibold : .compound.bodySM) + .foregroundColor(isHighlighted ? .compound.textActionAccent : .compound.textSecondary) } } } @@ -119,33 +119,48 @@ struct HomeScreenRoomCell: View { HStack(spacing: 8) { if room.hasOngoingCall { CompoundIcon(\.videoCallSolid, size: .xSmall, relativeTo: .compound.bodySM) - .foregroundColor(room.hasUnreads ? .compound.iconAccentTertiary : .compound.iconQuaternary) + .foregroundColor(isHighlighted ? .compound.iconAccentTertiary : .compound.iconQuaternary) + } + + if room.notificationMode == .mute { + CompoundIcon(\.notificationsSolidOff, size: .custom(15), relativeTo: .compound.bodyMD) + .accessibilityLabel(L10n.a11yNotificationsMuted) + .foregroundColor(.compound.iconQuaternary) } - notificationModeIcon - .foregroundColor(room.hasUnreads ? .compound.iconAccentTertiary : .compound.iconQuaternary) + if room.hasMentions, room.notificationMode != .mute { + mentionIcon + .foregroundColor(.compound.iconAccentTertiary) + } - if room.hasUnreads { + if hasNewContent { Circle() .frame(width: 12, height: 12) - .foregroundColor(.compound.iconAccentTertiary) + .foregroundColor(isHighlighted ? .compound.iconAccentTertiary : .compound.iconQuaternary) } } } } - @ViewBuilder - private var notificationModeIcon: some View { - switch room.notificationMode { - case .none, .allMessages: - EmptyView() - case .mentionsAndKeywordsOnly: - CompoundIcon(\.mention, size: .custom(15), relativeTo: .compound.bodyMD) - .accessibilityLabel(L10n.a11yNotificationsMentionsOnly) - case .mute: - CompoundIcon(\.notificationsSolidOff, size: .custom(15), relativeTo: .compound.bodyMD) - .accessibilityLabel(L10n.a11yNotificationsMuted) + private var hasNewContent: Bool { + room.hasUnreads || room.hasMentions + } + + private var isHighlighted: Bool { + guard !room.isPlaceholder else { + return false } + return (isNotificationModeUnrestricted && hasNewContent) || + (room.notificationMode == .mentionsAndKeywordsOnly && room.hasMentions) + } + + private var isNotificationModeUnrestricted: Bool { + room.notificationMode == nil || room.notificationMode == .allMessages + } + + private var mentionIcon: some View { + CompoundIcon(\.mention, size: .custom(15), relativeTo: .compound.bodyMD) + .accessibilityLabel(L10n.a11yNotificationsMentionsOnly) } @ViewBuilder @@ -178,41 +193,67 @@ private extension View { } struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview { - static var previews: some View { - let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockRooms)) + static let summaryProviderGeneric = MockRoomSummaryProvider(state: .loaded(.mockRooms)) + static let viewModelGeneric = { + let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProviderGeneric), + mediaProvider: MockMediaProvider(), + voiceMessageMediaManager: VoiceMessageMediaManagerMock()) - let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProvider), + return HomeScreenViewModel(userSession: userSession, + selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), + appSettings: ServiceLocator.shared.settings, + userIndicatorController: ServiceLocator.shared.userIndicatorController) + }() + + static let summaryProviderForNotificationsState = MockRoomSummaryProvider(state: .loaded(.mockRoomsWithNotificationsState)) + static let viewModelForNotificationsState = { + let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProviderForNotificationsState), mediaProvider: MockMediaProvider(), voiceMessageMediaManager: VoiceMessageMediaManagerMock()) - let viewModel = HomeScreenViewModel(userSession: userSession, - selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), - appSettings: ServiceLocator.shared.settings, - userIndicatorController: ServiceLocator.shared.userIndicatorController) - - let rooms: [HomeScreenRoom] = summaryProvider.roomListPublisher.value.compactMap { summary -> HomeScreenRoom? in - switch summary { - case .empty: - return nil - case .invalidated(let details), .filled(let details): - return HomeScreenRoom(id: UUID().uuidString, - roomId: details.id, - name: details.name, - hasUnreads: details.unreadNotificationCount > 0, - hasOngoingCall: details.hasOngoingCall, - timestamp: Date(timeIntervalSinceReferenceDate: 0).formattedMinimal(), - lastMessage: details.lastMessage, - notificationMode: details.notificationMode) - } + return HomeScreenViewModel(userSession: userSession, + selectedRoomPublisher: CurrentValueSubject(nil).asCurrentValuePublisher(), + appSettings: ServiceLocator.shared.settings, + userIndicatorController: ServiceLocator.shared.userIndicatorController) + }() + + static func mockRoom(summary: RoomSummary) -> HomeScreenRoom? { + switch summary { + case .empty: + return nil + case .invalidated(let details), .filled(let details): + return HomeScreenRoom(id: UUID().uuidString, + roomId: details.id, + name: details.name, + hasUnreads: details.unreadMessagesCount > 0, hasMentions: details.unreadMentionsCount > 0, + hasOngoingCall: details.hasOngoingCall, + timestamp: Date(timeIntervalSinceReferenceDate: 0).formattedMinimal(), + lastMessage: details.lastMessage, + notificationMode: details.notificationMode) } + } + + static var previews: some View { + let genericRooms: [HomeScreenRoom] = summaryProviderGeneric.roomListPublisher.value.compactMap(mockRoom) + + let notificationsStateRooms: [HomeScreenRoom] = summaryProviderForNotificationsState.roomListPublisher.value.compactMap(mockRoom) - return VStack(spacing: 0) { - ForEach(rooms) { room in - HomeScreenRoomCell(room: room, context: viewModel.context, isSelected: false) + VStack(spacing: 0) { + ForEach(genericRooms) { room in + HomeScreenRoomCell(room: room, context: viewModelGeneric.context, isSelected: false) } - HomeScreenRoomCell(room: .placeholder(), context: viewModel.context, isSelected: false) + HomeScreenRoomCell(room: .placeholder(), context: viewModelGeneric.context, isSelected: false) .redacted(reason: .placeholder) } + .previewDisplayName("Generic") + + VStack(spacing: 0) { + ForEach(notificationsStateRooms) { room in + HomeScreenRoomCell(room: room, context: viewModelForNotificationsState.context, isSelected: false) + } + } + .previewLayout(.sizeThatFits) + .previewDisplayName("Notifications State") } } diff --git a/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreenCell.swift b/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreenCell.swift index 0f83e1c38c..2ad1991596 100644 --- a/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreenCell.swift +++ b/ElementX/Sources/Screens/InvitesScreen/View/InvitesScreenCell.swift @@ -186,7 +186,8 @@ private extension InvitesScreenRoomDetails { avatarURL: nil, lastMessage: nil, lastMessageFormattedTimestamp: nil, - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: nil, canonicalAlias: "#footest:somewhere.org", inviter: inviter, @@ -206,7 +207,8 @@ private extension InvitesScreenRoomDetails { avatarURL: avatarURL, lastMessage: nil, lastMessageFormattedTimestamp: nil, - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: nil, canonicalAlias: alias, inviter: inviter, diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift index a39a6726fb..5531adf06c 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/DeveloperOptionsScreenModels.swift @@ -49,6 +49,7 @@ protocol DeveloperOptionsProtocol: AnyObject { var shouldCollapseRoomStateEvents: Bool { get set } var userSuggestionsEnabled: Bool { get set } var swiftUITimelineEnabled: Bool { get set } + var mentionsBadgeEnabled: Bool { get set } var elementCallBaseURL: URL { get set } var elementCallUseEncryption: Bool { get set } diff --git a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift index e446ce9317..b9bbf4ebf8 100644 --- a/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift +++ b/ElementX/Sources/Screens/Settings/DeveloperOptionsScreen/View/DeveloperOptionsScreen.swift @@ -49,6 +49,13 @@ struct DeveloperOptionsScreen: View { } } + Section("Mentions") { + Toggle(isOn: $context.mentionsBadgeEnabled) { + Text("Mentions badge") + Text("Requires app reboot") + } + } + Section("Element Call") { TextField(context.elementCallBaseURL.absoluteString, text: $elementCallBaseURLString) .submitLabel(.done) diff --git a/ElementX/Sources/Services/NotificationSettings/RoomNotificationModeProxy.swift b/ElementX/Sources/Services/NotificationSettings/RoomNotificationModeProxy.swift index d70c948444..1587058584 100644 --- a/ElementX/Sources/Services/NotificationSettings/RoomNotificationModeProxy.swift +++ b/ElementX/Sources/Services/NotificationSettings/RoomNotificationModeProxy.swift @@ -17,7 +17,7 @@ import Foundation import MatrixRustSDK -enum RoomNotificationModeProxy { +enum RoomNotificationModeProxy: String { case allMessages case mentionsAndKeywordsOnly case mute diff --git a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift index a1e8f77ce2..eb136c708b 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/MockRoomSummaryProvider.swift @@ -83,7 +83,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"), lastMessageFormattedTimestamp: "14:56", - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: .allMessages, canonicalAlias: nil, inviter: nil, @@ -94,7 +95,8 @@ extension Array where Element == RoomSummary { avatarURL: URL.picturesDirectory, lastMessage: AttributedString("How do you see the Emperor then? You think he keeps office hours?"), lastMessageFormattedTimestamp: "2:56 PM", - unreadNotificationCount: 2, + unreadMessagesCount: 2, + unreadMentionsCount: 0, notificationMode: .mute, canonicalAlias: nil, inviter: nil, @@ -105,7 +107,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"), lastMessageFormattedTimestamp: "Some time ago", - unreadNotificationCount: 3, + unreadMessagesCount: 3, + unreadMentionsCount: 0, notificationMode: .mentionsAndKeywordsOnly, canonicalAlias: nil, inviter: nil, @@ -116,7 +119,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: AttributedString("There's an archaic measure of time that's called the month"), lastMessageFormattedTimestamp: "Just now", - unreadNotificationCount: 4, + unreadMessagesCount: 2, + unreadMentionsCount: 2, notificationMode: .allMessages, canonicalAlias: nil, inviter: nil, @@ -127,7 +131,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: AttributedString("Clearly, if Earth is powerful enough to do that, it might also be capable of adjusting minds in order to force belief in its radioactivity"), lastMessageFormattedTimestamp: "1986", - unreadNotificationCount: 5, + unreadMessagesCount: 1, + unreadMentionsCount: 1, notificationMode: .allMessages, canonicalAlias: nil, inviter: nil, @@ -138,7 +143,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: AttributedString("Are you groping for the word 'paranoia'?"), lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです", - unreadNotificationCount: 6, + unreadMessagesCount: 6, + unreadMentionsCount: 0, notificationMode: .mute, canonicalAlias: nil, inviter: nil, @@ -149,7 +155,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: nil, lastMessageFormattedTimestamp: nil, - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: nil, canonicalAlias: nil, inviter: nil, @@ -157,13 +164,65 @@ extension Array where Element == RoomSummary { .empty ] + static let mockRoomsWithNotificationsState: [Element] = [ + .filled(details: RoomSummaryDetails(id: "1", + settingsMode: .allMessages, + hasUnreadMessages: false, + hasUnreadMentions: false)), + .filled(details: RoomSummaryDetails(id: "2", + settingsMode: .allMessages, + hasUnreadMessages: true, + hasUnreadMentions: false)), + .filled(details: RoomSummaryDetails(id: "3", + settingsMode: .allMessages, + hasUnreadMessages: true, + hasUnreadMentions: true)), + .filled(details: RoomSummaryDetails(id: "4", + settingsMode: .allMessages, + hasUnreadMessages: false, + hasUnreadMentions: true)), + .filled(details: RoomSummaryDetails(id: "5", + settingsMode: .mentionsAndKeywordsOnly, + hasUnreadMessages: false, + hasUnreadMentions: false)), + .filled(details: RoomSummaryDetails(id: "6", + settingsMode: .mentionsAndKeywordsOnly, + hasUnreadMessages: true, + hasUnreadMentions: false)), + .filled(details: RoomSummaryDetails(id: "7", + settingsMode: .mentionsAndKeywordsOnly, + hasUnreadMessages: true, + hasUnreadMentions: true)), + .filled(details: RoomSummaryDetails(id: "8", + settingsMode: .mentionsAndKeywordsOnly, + hasUnreadMessages: false, + hasUnreadMentions: true)), + .filled(details: RoomSummaryDetails(id: "9", + settingsMode: .mute, + hasUnreadMessages: false, + hasUnreadMentions: false)), + .filled(details: RoomSummaryDetails(id: "10", + settingsMode: .mute, + hasUnreadMessages: true, + hasUnreadMentions: false)), + .filled(details: RoomSummaryDetails(id: "11", + settingsMode: .mute, + hasUnreadMessages: true, + hasUnreadMentions: true)), + .filled(details: RoomSummaryDetails(id: "12", + settingsMode: .mute, + hasUnreadMessages: false, + hasUnreadMentions: true)) + ] + static let mockInvites: [Element] = [ .filled(details: RoomSummaryDetails(id: "someAwesomeRoomId1", name: "First room", isDirect: false, avatarURL: URL.picturesDirectory, lastMessage: nil, lastMessageFormattedTimestamp: nil, - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: nil, canonicalAlias: "#footest:somewhere.org", inviter: RoomMemberProxyMock.mockCharlie, @@ -174,7 +233,8 @@ extension Array where Element == RoomSummary { avatarURL: nil, lastMessage: nil, lastMessageFormattedTimestamp: nil, - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: nil, canonicalAlias: nil, inviter: RoomMemberProxyMock.mockCharlie, diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryDetails.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryDetails.swift index 380b232c7b..7857677f12 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryDetails.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryDetails.swift @@ -24,7 +24,8 @@ struct RoomSummaryDetails { let avatarURL: URL? let lastMessage: AttributedString? let lastMessageFormattedTimestamp: String? - let unreadNotificationCount: UInt + let unreadMessagesCount: UInt + let unreadMentionsCount: UInt let notificationMode: RoomNotificationModeProxy? let canonicalAlias: String? let inviter: RoomMemberProxyProtocol? @@ -33,6 +34,24 @@ struct RoomSummaryDetails { extension RoomSummaryDetails: CustomStringConvertible { var description: String { - "id: \"\(id)\", isDirect: \"\(isDirect)\", unreadNotificationCount: \"\(unreadNotificationCount)\"" + "RoomSummaryDetails: - id: \(id) - isDirect: \(isDirect) - unreadMessagesCount: \(unreadMessagesCount) - unreadMentionsCount: \(unreadMentionsCount) - notificationMode: \(notificationMode?.rawValue ?? "nil")" + } +} + +extension RoomSummaryDetails { + init(id: String, settingsMode: RoomNotificationModeProxy, hasUnreadMessages: Bool, hasUnreadMentions: Bool) { + self.id = id + let string = "\(settingsMode) - hasUnreadMessages: \(hasUnreadMessages) - hasUnreadMentions: \(hasUnreadMentions)" + name = string + isDirect = true + avatarURL = nil + lastMessage = AttributedString(string) + lastMessageFormattedTimestamp = "Now" + unreadMessagesCount = hasUnreadMessages ? 1 : 0 + unreadMentionsCount = hasUnreadMentions ? 1 : 0 + notificationMode = settingsMode + canonicalAlias = nil + inviter = nil + hasOngoingCall = false } } diff --git a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift index 5d169f159b..175dcd00e4 100644 --- a/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift +++ b/ElementX/Sources/Services/Room/RoomSummary/RoomSummaryProvider.swift @@ -245,7 +245,8 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol { avatarURL: roomInfo.avatarUrl.flatMap(URL.init(string:)), lastMessage: attributedLastMessage, lastMessageFormattedTimestamp: lastMessageFormattedTimestamp, - unreadNotificationCount: UInt(roomInfo.notificationCount), + unreadMessagesCount: UInt(roomInfo.notificationCount), + unreadMentionsCount: UInt(roomInfo.numUnreadMentions), notificationMode: notificationMode, canonicalAlias: roomInfo.canonicalAlias, inviter: inviterProxy, diff --git a/UnitTests/Sources/LoggingTests.swift b/UnitTests/Sources/LoggingTests.swift index 58d48e1dbf..3a8f2d6997 100644 --- a/UnitTests/Sources/LoggingTests.swift +++ b/UnitTests/Sources/LoggingTests.swift @@ -229,7 +229,8 @@ class LoggingTests: XCTestCase { avatarURL: nil, lastMessage: AttributedString(lastMessage), lastMessageFormattedTimestamp: "Now", - unreadNotificationCount: 0, + unreadMessagesCount: 0, + unreadMentionsCount: 0, notificationMode: nil, canonicalAlias: nil, inviter: nil, diff --git a/UnitTests/__Snapshots__/PreviewTests/test_homeScreen.Loaded.png b/UnitTests/__Snapshots__/PreviewTests/test_homeScreen.Loaded.png index 0386b07524..110f535f32 100644 --- a/UnitTests/__Snapshots__/PreviewTests/test_homeScreen.Loaded.png +++ b/UnitTests/__Snapshots__/PreviewTests/test_homeScreen.Loaded.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5d6d5a6fa799a80f4057b45c490d47fd32d191034a7f035d30bd5b31e1a6855b -size 297086 +oid sha256:8a5f5fcf811ce8ed53b9556f4ac19f3d269273f5b36a5b473fc081a382481d27 +size 293688 diff --git a/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.1.png b/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.1.png deleted file mode 100644 index d5a2d141e9..0000000000 --- a/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.1.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:144567bde78b790121261ea07309fb16470310564a23f38d91117b83034b07fc -size 243748 diff --git a/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Generic.png b/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Generic.png new file mode 100644 index 0000000000..fd0afbfeb0 --- /dev/null +++ b/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Generic.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a008adeae6b250d84187e72067a734e213b2a7557258f4bcd251b45b64c9dc3 +size 241273 diff --git a/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Notifications-State.png b/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Notifications-State.png new file mode 100644 index 0000000000..2cc7925302 --- /dev/null +++ b/UnitTests/__Snapshots__/PreviewTests/test_homeScreenRoomCell.Notifications-State.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:280155439f431f4f3694c9482807857e053088a6afd904da0027ec06b39fdb66 +size 421031 diff --git a/changelog.d/2281.feature b/changelog.d/2281.feature new file mode 100644 index 0000000000..7349ae8085 --- /dev/null +++ b/changelog.d/2281.feature @@ -0,0 +1 @@ +Added back the mention badge option but only behind a feature flag. \ No newline at end of file diff --git a/project.yml b/project.yml index 3738a87791..cd612f8f39 100644 --- a/project.yml +++ b/project.yml @@ -47,7 +47,7 @@ packages: # Element/Matrix dependencies MatrixRustSDK: url: https://github.com/matrix-org/matrix-rust-components-swift - exactVersion: 0.0.1-december23 + exactVersion: 1.1.31 # path: ../matrix-rust-sdk Compound: url: https://github.com/element-hq/compound-ios