diff --git a/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift b/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift index 4cf73febe8..3acc8d5853 100644 --- a/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift +++ b/submodules/NotificationSoundSelectionUI/Sources/NotificationSoundSelection.swift @@ -377,6 +377,7 @@ public func notificationSoundSelectionController(context: AccountContext, update let playSoundDisposable = MetaDisposable() let soundActionDisposable = MetaDisposable() + let fetchedSoundsDisposable = ensureDownloadedNotificationSoundList(postbox: context.account.postbox).start() let arguments = NotificationSoundSelectionArguments(account: context.account, selectSound: { sound in updateState { state in @@ -422,6 +423,7 @@ public func notificationSoundSelectionController(context: AccountContext, update let controller = ItemListController(context: context, state: signal |> afterDisposed { playSoundDisposable.dispose() soundActionDisposable.dispose() + fetchedSoundsDisposable.dispose() }) controller.enableInteractiveDismiss = true if isModal { diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift index 5c63191c8c..2ba9dd5c20 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift @@ -694,6 +694,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { private let presentationDataValue = Promise<(PresentationTheme, PresentationStrings)>() private var listDisposable: Disposable? + private var fetchedSoundsDisposable: Disposable? private var arguments: NotificationExceptionArguments? private let stateValue: Atomic @@ -996,12 +997,15 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode { self?.enqueueTransition(transition) }) + + self.fetchedSoundsDisposable = ensureDownloadedNotificationSoundList(postbox: context.account.postbox).start() } deinit { self.listDisposable?.dispose() self.navigationActionDisposable.dispose() self.updateNotificationsDisposable.dispose() + self.fetchedSoundsDisposable?.dispose() } func updatePresentationData(_ presentationData: PresentationData) { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/NotificationSoundList.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/NotificationSoundList.swift index abe0414ec3..427fcb6aa9 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/NotificationSoundList.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/NotificationSoundList.swift @@ -139,6 +139,35 @@ func _internal_setCachedNotificationSoundList(transaction: Transaction, notifica } } +public func ensureDownloadedNotificationSoundList(postbox: Postbox) -> Signal { + return postbox.transaction { transaction -> Signal in + var signals: [Signal] = [] + + if let notificationSoundList = _internal_cachedNotificationSoundList(transaction: transaction) { + var resources: [MediaResource] = [] + + for sound in notificationSoundList.sounds { + resources.append(sound.file.resource) + } + + for resource in resources { + signals.append( + fetchedMediaResource(mediaBox: postbox.mediaBox, reference: .standalone(resource: resource)) + |> ignoreValues + |> `catch` { _ -> Signal in + return .complete() + } + ) + } + } + + return combineLatest(signals) + |> ignoreValues + } + |> switchToLatest + |> ignoreValues +} + private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Signal { return Signal { subscriber in let signal: Signal = _internal_cachedNotificationSoundList(postbox: postbox)