Preload sounds

This commit is contained in:
Ali 2022-04-20 20:07:54 +04:00
parent 3b67110f83
commit 333d34e4b7
3 changed files with 35 additions and 0 deletions

View File

@ -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 {

View File

@ -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<NotificationExceptionState>
@ -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) {

View File

@ -139,6 +139,35 @@ func _internal_setCachedNotificationSoundList(transaction: Transaction, notifica
}
}
public func ensureDownloadedNotificationSoundList(postbox: Postbox) -> Signal<Never, NoError> {
return postbox.transaction { transaction -> Signal<Never, NoError> in
var signals: [Signal<Never, NoError>] = []
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<Never, NoError> in
return .complete()
}
)
}
}
return combineLatest(signals)
|> ignoreValues
}
|> switchToLatest
|> ignoreValues
}
private func pollNotificationSoundList(postbox: Postbox, network: Network) -> Signal<Never, NoError> {
return Signal<Never, NoError> { subscriber in
let signal: Signal<Never, NoError> = _internal_cachedNotificationSoundList(postbox: postbox)