Skip to content

Commit b15cb04

Browse files
authored
Merge pull request #4220 from anyproto/ios-5440-support-notifications-preferences-configured-from-desktop
IOS-5440 Support notifications preferences configured from desktop
2 parents 38b12a9 + d4d1bb1 commit b15cb04

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
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/PresentationLayer/Modules/SpaceHub/Subviews/SpaceCard/SpaceCard.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ struct SpaceCard: View {
6363
onTapMute()
6464
} label: {
6565
HStack {
66-
Text(model.allNotificationsUnmuted ? Loc.mute : Loc.unmute)
66+
Text(!model.isMuted ? Loc.mute : Loc.unmute)
6767
Spacer()
68-
Image(systemName: model.allNotificationsUnmuted ? "bell.slash" : "bell")
68+
Image(systemName: !model.isMuted ? "bell.slash" : "bell")
6969
}
7070
}
7171
}

Anytype/Sources/PresentationLayer/Modules/SpaceHub/Subviews/SpaceCard/SpaceCardModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ struct SpaceCardModel: Equatable, Identifiable {
1111
let isShared: Bool
1212
let isMuted: Bool
1313
let uxTypeName: String
14-
let allNotificationsUnmuted: Bool
1514

1615
let lastMessage: SpaceCardLastMessageModel?
1716
let unreadCounter: Int

Anytype/Sources/PresentationLayer/Modules/SpaceHub/Subviews/SpaceCard/SpaceCardModelBuilder.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ final class SpaceCardModelBuilder: SpaceCardModelBuilderProtocol, Sendable {
6060
isShared: spaceView.isShared,
6161
isMuted: !spaceView.pushNotificationMode.isUnmutedAll,
6262
uxTypeName: spaceView.uxType.name,
63-
allNotificationsUnmuted: spaceView.pushNotificationMode.isUnmutedAll,
6463
lastMessage: lastMessage,
6564
unreadCounter: preview.unreadCounter,
6665
mentionCounter: preview.mentionCounter,

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)