Skip to content

Commit b05d2d2

Browse files
committed
IOS-5440 Support muted multichats chats
1 parent 0a77313 commit b05d2d2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

Anytype/Sources/PresentationLayer/Modules/Chat/Subviews/ChatHeader/ChatHeaderViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ final class ChatHeaderViewModel: ObservableObject {
6464
title = spaceView.title
6565
icon = spaceView.objectIconImage
6666
showWidgetsButton = spaceView.chatId == chatId && spaceView.initialScreenIsChat
67-
muted = !spaceView.pushNotificationMode.isUnmutedAll
67+
muted = !spaceView.effectiveNotificationMode(for: chatId).isUnmutedAll
6868
showAddMembersButton = participantSpaceView.participant?.permission == .owner
6969
}
7070
}

Anytype/Sources/PreviewMocks/Mocks/Models/SpaceViewMock.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ extension SpaceView {
2828
spaceOrder: "",
2929
uxType: .allCases.randomElement()!,
3030
pushNotificationEncryptionKey: "",
31-
pushNotificationMode: .allCases.randomElement()!
31+
pushNotificationMode: .allCases.randomElement()!,
32+
forceAllIds: [],
33+
forceMuteIds: [],
34+
forceMentionIds: []
3235
)
3336
}
3437
}

Anytype/Sources/ServiceLayer/SpaceStorage/Models/SpaceView.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ struct SpaceView: Identifiable, Equatable, Hashable {
2020
let uxType: SpaceUxType
2121
let pushNotificationEncryptionKey: String
2222
let pushNotificationMode: SpacePushNotificationsMode
23+
let forceAllIds: [String]
24+
let forceMuteIds: [String]
25+
let forceMentionIds: [String]
2326
}
2427

2528
extension SpaceView: DetailsModel {
@@ -41,6 +44,9 @@ extension SpaceView: DetailsModel {
4144
self.uxType = details.spaceUxTypeValue ?? .data
4245
self.pushNotificationEncryptionKey = details.spacePushNotificationEncryptionKey
4346
self.pushNotificationMode = details.spacePushNotificationModeValue ?? .all
47+
self.forceAllIds = details.spacePushNotificationForceAllIds
48+
self.forceMuteIds = details.spacePushNotificationForceMuteIds
49+
self.forceMentionIds = details.spacePushNotificationForceMentionIds
4450
}
4551

4652
static let subscriptionKeys: [BundledPropertyKey] = .builder {
@@ -62,6 +68,9 @@ extension SpaceView: DetailsModel {
6268
BundledPropertyKey.spaceUxType
6369
BundledPropertyKey.spacePushNotificationEncryptionKey
6470
BundledPropertyKey.spacePushNotificationMode
71+
BundledPropertyKey.spacePushNotificationForceAllIds
72+
BundledPropertyKey.spacePushNotificationForceMuteIds
73+
BundledPropertyKey.spacePushNotificationForceMentionIds
6574
}
6675
}
6776

@@ -125,4 +134,17 @@ extension SpaceView {
125134
private func activeWriters(participants: [Participant]) -> Int {
126135
participants.filter { $0.permission == .writer || $0.permission == .owner }.count
127136
}
137+
138+
func effectiveNotificationMode(for chatId: String) -> SpacePushNotificationsMode {
139+
if forceAllIds.contains(chatId) {
140+
return .all
141+
}
142+
if forceMuteIds.contains(chatId) {
143+
return .nothing
144+
}
145+
if forceMentionIds.contains(chatId) {
146+
return .mentions
147+
}
148+
return pushNotificationMode
149+
}
128150
}

0 commit comments

Comments
 (0)