Display the notification mode for each room in the the room list (#1595)

Co-authored-by: Stefan Ceriu <stefan.ceriu@gmail.com>
This commit is contained in:
Nicolas Mauri
2023-08-31 13:15:38 +02:00
committed by GitHub
parent f0fad25d09
commit 3ab7b1b1c7
17 changed files with 145 additions and 63 deletions
@@ -139,6 +139,14 @@ struct HomeScreenRoom: Identifiable, Equatable {
var avatarURL: URL?
var notificationMode: RoomNotificationModeProxy?
var hasDecoration: Bool {
// notification setting is displayed only for .mentionsAndKeywords and .mute
let showNotificationSettings = notificationMode != nil
return hasUnreads || showNotificationSettings
}
var isPlaceholder = false
static func placeholder() -> HomeScreenRoom {
@@ -266,13 +266,16 @@ 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 || appSettings.notificationSettingsEnabled == false ? nil : details.notificationMode
return HomeScreenRoom(id: identifier,
roomId: details.id,
name: details.name,
hasUnreads: details.unreadNotificationCount > 0,
timestamp: details.lastMessageFormattedTimestamp,
lastMessage: .init(attributedString: details.lastMessage, isLoading: false),
avatarURL: details.avatarURL)
avatarURL: details.avatarURL,
notificationMode: notificationMode)
}
private func updateVisibleRange(_ range: Range<Int>) {
@@ -15,6 +15,7 @@
//
import Combine
import Compound
import SwiftUI
struct HomeScreenRoomCell: View {
@@ -115,17 +116,42 @@ struct HomeScreenRoomCell: View {
Spacer()
if room.hasUnreads {
Circle()
.frame(width: 12, height: 12)
.foregroundColor(.compound.iconAccentTertiary)
.padding(.leading, 12)
} else {
// Force extra padding between last message text and the right border of the screen if there is no unread dot
Circle()
.frame(width: 12, height: 12)
.hidden()
HStack(spacing: 8) {
if let notificationMode = room.notificationMode {
notificationModeIcon
.foregroundColor(room.hasUnreads ? .compound.iconAccentTertiary : .compound.iconQuaternary)
}
if room.hasUnreads {
Circle()
.frame(width: 12, height: 12)
.foregroundColor(.compound.iconAccentTertiary)
}
if !room.hasDecoration {
// Force extra padding between last message text and the right border of the screen if there is no unread dot
Circle()
.frame(width: 12, height: 12)
.hidden()
}
}
.padding(.leading, room.hasDecoration ? 12 : 0)
}
}
@ViewBuilder
var notificationModeIcon: some View {
switch room.notificationMode {
case .none, .allMessages:
EmptyView()
case .mentionsAndKeywordsOnly:
CompoundIcon(\.mention)
.font(.system(size: 15))
.accessibilityLabel(L10n.a11yNotificationsMentionsOnly)
case .mute:
CompoundIcon(\.notificationsSolidOff)
.font(.system(size: 15))
.accessibilityLabel(L10n.a11yNotificationsMuted)
}
}
@@ -191,7 +217,8 @@ struct HomeScreenRoomCell_Previews: PreviewProvider {
hasUnreads: details.unreadNotificationCount > 0,
timestamp: Date.now.formattedMinimal(),
lastMessage: .init(attributedString: details.lastMessage,
isLoading: false))
isLoading: false),
notificationMode: details.notificationMode)
}
}