Skip to content

Commit

Permalink
Fix: Grey dot appears when you have unread messages that do not trigg…
Browse files Browse the repository at this point in the history
…er a notification (#2371)
  • Loading branch information
Velin92 authored Jan 23, 2024
1 parent 680c6ef commit 550db5e
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 88 deletions.
11 changes: 7 additions & 4 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ struct HomeScreenRoom: Identifiable, Equatable {

var name = ""

var hasUnreads = false
var hasUnreadMessages = false

var hasMentions = false
var hasUnreadMentions = false

var hasUnreadNotifications = false

var hasOngoingCall = false

Expand All @@ -165,8 +167,9 @@ struct HomeScreenRoom: Identifiable, Equatable {
HomeScreenRoom(id: UUID().uuidString,
roomId: nil,
name: "Placeholder room name",
hasUnreads: false,
hasMentions: false,
hasUnreadMessages: false,
hasUnreadMentions: false,
hasUnreadNotifications: false,
timestamp: "Now",
lastMessage: placeholderLastMessage,
isPlaceholder: true)
Expand Down
6 changes: 3 additions & 3 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol

private func buildRoom(with details: RoomSummaryDetails, invalidated: Bool) -> HomeScreenRoom {
let identifier = invalidated ? "invalidated-" + details.id : details.id
let hasMentions = appSettings.mentionsBadgeEnabled ? details.unreadMentionsCount > 0 : false

return HomeScreenRoom(id: identifier,
roomId: details.id,
name: details.name,
hasUnreads: details.unreadNotificationsCount > 0,
hasMentions: hasMentions,
hasUnreadMessages: details.unreadMessagesCount > 0,
hasUnreadMentions: details.unreadMentionsCount > 0,
hasUnreadNotifications: details.unreadNotificationsCount > 0,
hasOngoingCall: details.hasOngoingCall,
timestamp: details.lastMessageFormattedTimestamp,
lastMessage: details.lastMessage,
Expand Down
20 changes: 10 additions & 10 deletions ElementX/Sources/Screens/HomeScreen/View/HomeScreenRoomCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ struct HomeScreenRoomCell: View {
.foregroundColor(.compound.iconQuaternary)
}

if room.hasMentions, room.notificationMode != .mute {
if room.hasUnreadMentions, room.notificationMode != .mute {
mentionIcon
.foregroundColor(.compound.iconAccentTertiary)
}
Expand All @@ -143,19 +143,17 @@ struct HomeScreenRoomCell: View {
}

private var hasNewContent: Bool {
room.hasUnreads || room.hasMentions
room.hasUnreadMessages ||
room.hasUnreadMentions ||
room.hasUnreadNotifications
}

private var isHighlighted: Bool {
guard !room.isPlaceholder else {
guard !room.isPlaceholder &&
room.notificationMode != .mute else {
return false
}
return (isNotificationModeUnrestricted && hasNewContent) ||
(room.notificationMode == .mentionsAndKeywordsOnly && room.hasMentions)
}

private var isNotificationModeUnrestricted: Bool {
room.notificationMode == nil || room.notificationMode == .allMessages
return room.hasUnreadNotifications || room.hasUnreadMentions
}

private var mentionIcon: some View {
Expand Down Expand Up @@ -225,7 +223,9 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
return HomeScreenRoom(id: UUID().uuidString,
roomId: details.id,
name: details.name,
hasUnreads: details.unreadNotificationsCount > 0, hasMentions: details.unreadMentionsCount > 0,
hasUnreadMessages: details.unreadMessagesCount > 0,
hasUnreadMentions: details.unreadMentionsCount > 0,
hasUnreadNotifications: details.unreadNotificationsCount > 0,
hasOngoingCall: details.hasOngoingCall,
timestamp: Date(timeIntervalSinceReferenceDate: 0).formattedMinimal(),
lastMessage: details.lastMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ private extension InvitesScreenRoomDetails {
avatarURL: nil,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadNotificationsCount: 0,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: "#footest:somewhere.org",
inviter: inviter,
Expand All @@ -207,8 +208,9 @@ private extension InvitesScreenRoomDetails {
avatarURL: avatarURL,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadNotificationsCount: 0,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: alias,
inviter: inviter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation
import MatrixRustSDK

enum RoomNotificationModeProxy: String {
enum RoomNotificationModeProxy: String, CaseIterable {
case allMessages
case mentionsAndKeywordsOnly
case mute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: AttributedString("I do not wish to take the trouble to understand mysticism"),
lastMessageFormattedTimestamp: "14:56",
unreadNotificationsCount: 0,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .allMessages,
canonicalAlias: nil,
inviter: nil,
Expand All @@ -95,8 +96,9 @@ 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",
unreadNotificationsCount: 2,
unreadMessagesCount: 2,
unreadMentionsCount: 0,
unreadNotificationsCount: 2,
notificationMode: .mute,
canonicalAlias: nil,
inviter: nil,
Expand All @@ -107,8 +109,9 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: try? AttributedString(markdown: "He certainly seemed no *mental genius* to me"),
lastMessageFormattedTimestamp: "Some time ago",
unreadNotificationsCount: 3,
unreadMessagesCount: 3,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mentionsAndKeywordsOnly,
canonicalAlias: nil,
inviter: nil,
Expand All @@ -119,8 +122,9 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: AttributedString("There's an archaic measure of time that's called the month"),
lastMessageFormattedTimestamp: "Just now",
unreadNotificationsCount: 2,
unreadMessagesCount: 2,
unreadMentionsCount: 2,
unreadNotificationsCount: 2,
notificationMode: .allMessages,
canonicalAlias: nil,
inviter: nil,
Expand All @@ -131,8 +135,9 @@ 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",
unreadNotificationsCount: 1,
unreadMessagesCount: 1,
unreadMentionsCount: 1,
unreadNotificationsCount: 1,
notificationMode: .allMessages,
canonicalAlias: nil,
inviter: nil,
Expand All @@ -143,8 +148,9 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: AttributedString("Are you groping for the word 'paranoia'?"),
lastMessageFormattedTimestamp: "きょうはじゅういちがつじゅういちにちです",
unreadNotificationsCount: 6,
unreadMessagesCount: 6,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: .mute,
canonicalAlias: nil,
inviter: nil,
Expand All @@ -155,74 +161,54 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadNotificationsCount: 0,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
inviter: nil,
hasOngoingCall: false)),
.empty
]

static let mockRoomsWithNotificationsState: [Element] = [
.filled(details: RoomSummaryDetails(id: "1",
settingsMode: .allMessages,
hasUnreadNotifications: false,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "2",
settingsMode: .allMessages,
hasUnreadNotifications: true,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "3",
settingsMode: .allMessages,
hasUnreadNotifications: true,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "4",
settingsMode: .allMessages,
hasUnreadNotifications: false,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "5",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadNotifications: false,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "6",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadNotifications: true,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "7",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadNotifications: true,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "8",
settingsMode: .mentionsAndKeywordsOnly,
hasUnreadNotifications: false,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "9",
settingsMode: .mute,
hasUnreadNotifications: false,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "10",
settingsMode: .mute,
hasUnreadNotifications: true,
hasUnreadMentions: false)),
.filled(details: RoomSummaryDetails(id: "11",
settingsMode: .mute,
hasUnreadNotifications: true,
hasUnreadMentions: true)),
.filled(details: RoomSummaryDetails(id: "12",
settingsMode: .mute,
hasUnreadNotifications: false,
hasUnreadMentions: true))
]
static let mockRoomsWithNotificationsState: [Element] = {
var result: [Element] = []

// Iterate over settings modes
for mode in RoomNotificationModeProxy.allCases {
// Iterate over unread messages states
for hasUnreadMessages in [false, true] {
// Iterate over unread mentions states
for hasUnreadMentions in [false, true] {
// Iterate over unread notifications states
for hasUnreadNotifications in [false, true] {
// Incrementing id value for each combination
let id = result.count + 1

let room = RoomSummary.filled(details: RoomSummaryDetails(id: "\(id)",
settingsMode: mode,
hasUnreadMessages: hasUnreadMessages,
hasUnreadMentions: hasUnreadMentions,
hasUnreadNotifications: hasUnreadNotifications))

result.append(room)
}
}
}
}

return result
}()

static let mockInvites: [Element] = [
.filled(details: RoomSummaryDetails(id: "someAwesomeRoomId1", name: "First room",
isDirect: false,
avatarURL: URL.picturesDirectory,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadNotificationsCount: 0,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: "#footest:somewhere.org",
inviter: RoomMemberProxyMock.mockCharlie,
Expand All @@ -233,8 +219,9 @@ extension Array where Element == RoomSummary {
avatarURL: nil,
lastMessage: nil,
lastMessageFormattedTimestamp: nil,
unreadNotificationsCount: 0,
unreadMessagesCount: 0,
unreadMentionsCount: 0,
unreadNotificationsCount: 0,
notificationMode: nil,
canonicalAlias: nil,
inviter: RoomMemberProxyMock.mockCharlie,
Expand Down
Loading

0 comments on commit 550db5e

Please sign in to comment.