From 8f6946c6b4125cca0ec9a03a5e9fa3700b306e48 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 5 Nov 2019 22:19:30 +0400 Subject: [PATCH] Cleanup --- .../Sources/MediaPlayerAudioRenderer.swift | 4 +- .../Sources/GroupInfoController.swift | 8 +++- .../Sources/ManagedAudioSession.swift | 40 ++++++++++-------- .../TelegramUI/ChatHistoryListNode.swift | 9 +++- .../PreparedChatHistoryViewTransition.swift | 42 +++++++++---------- 5 files changed, 59 insertions(+), 44 deletions(-) diff --git a/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift b/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift index 32cea5361d..f8e3c7efe7 100644 --- a/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift +++ b/submodules/MediaPlayer/Sources/MediaPlayerAudioRenderer.swift @@ -430,7 +430,7 @@ private final class AudioPlayerRendererContext { return } - print("MediaPlayerAudioRenderer initialize audio unit: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") + print("\(CFAbsoluteTimeGetCurrent()) MediaPlayerAudioRenderer initialize audio unit: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") self.audioGraph = audioGraph self.timePitchAudioUnit = timePitchAudioUnit @@ -508,7 +508,7 @@ private final class AudioPlayerRendererContext { return } - print("MediaPlayerAudioRenderer start audio unit: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") + print("\(CFAbsoluteTimeGetCurrent()) MediaPlayerAudioRenderer start audio unit: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") } } diff --git a/submodules/PeerInfoUI/Sources/GroupInfoController.swift b/submodules/PeerInfoUI/Sources/GroupInfoController.swift index ba41b7e6e5..41c6a0792e 100644 --- a/submodules/PeerInfoUI/Sources/GroupInfoController.swift +++ b/submodules/PeerInfoUI/Sources/GroupInfoController.swift @@ -2203,9 +2203,13 @@ public func groupInfoController(context: AccountContext, peerId originalPeerId: updateDescription = .complete() } - let signal = combineLatest(updateTitle, updateDescription) + let signal = combineLatest(queue: .mainQueue(), + updateTitle, + updateDescription + ) - updatePeerNameDisposable.set((signal |> deliverOnMainQueue).start(error: { _ in + updatePeerNameDisposable.set((signal + |> deliverOnMainQueue).start(error: { _ in updateState { state in return state.withUpdatedSavingData(false) } diff --git a/submodules/TelegramAudio/Sources/ManagedAudioSession.swift b/submodules/TelegramAudio/Sources/ManagedAudioSession.swift index e6a81f2810..693b0cd7da 100644 --- a/submodules/TelegramAudio/Sources/ManagedAudioSession.swift +++ b/submodules/TelegramAudio/Sources/ManagedAudioSession.swift @@ -159,7 +159,7 @@ public class ManagedAudioSessionControl { public final class ManagedAudioSession { private var nextId: Int32 = 0 - private let queue = Queue() + private let queue: Queue private let hasLoudspeaker: Bool private var holders: [HolderRecord] = [] private var currentTypeAndOutputMode: (ManagedAudioSessionType, AudioSessionOutputMode)? @@ -175,6 +175,8 @@ public final class ManagedAudioSession { private let isPlaybackActiveSubscribers = Bag<(Bool) -> Void>() public init() { + self.queue = Queue() + self.hasLoudspeaker = UIDevice.current.model == "iPhone" let queue = self.queue @@ -522,21 +524,23 @@ public final class ManagedAudioSession { if deactivate { self.holders[activeIndex].active = false let id = self.holders[activeIndex].id - self.holders[activeIndex].deactivatingDisposable = (self.holders[activeIndex].deactivate() |> deliverOn(self.queue)).start(completed: { [weak self] in - if let strongSelf = self { - var index = 0 - for currentRecord in strongSelf.holders { - if currentRecord.id == id { - currentRecord.deactivatingDisposable = nil - if currentRecord.once { - strongSelf.holders.remove(at: index) - } - break - } - index += 1 - } - strongSelf.updateHolders() + self.holders[activeIndex].deactivatingDisposable = (self.holders[activeIndex].deactivate() + |> deliverOn(self.queue)).start(completed: { [weak self] in + guard let strongSelf = self else { + return } + var index = 0 + for currentRecord in strongSelf.holders { + if currentRecord.id == id { + currentRecord.deactivatingDisposable = nil + if currentRecord.once { + strongSelf.holders.remove(at: index) + } + break + } + index += 1 + } + strongSelf.updateHolders() }) } } else if activeIndex == nil { @@ -753,15 +757,15 @@ public final class ManagedAudioSession { try AVAudioSession.sharedInstance().setActive(true, options: [.notifyOthersOnDeactivation]) - print("AudioSession activate: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") + print("\(CFAbsoluteTimeGetCurrent()) AudioSession activate: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") self.updateCurrentAudioRouteInfo() - print("AudioSession updateCurrentAudioRouteInfo: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") + print("\(CFAbsoluteTimeGetCurrent()) AudioSession updateCurrentAudioRouteInfo: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") try self.setupOutputMode(outputMode, type: type) - print("AudioSession setupOutputMode: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") + print("\(CFAbsoluteTimeGetCurrent()) AudioSession setupOutputMode: \((CFAbsoluteTimeGetCurrent() - startTime) * 1000.0) ms") if case .voiceCall = type { try AVAudioSession.sharedInstance().setPreferredIOBufferDuration(0.005) diff --git a/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift b/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift index 250f459485..ffec9487af 100644 --- a/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift @@ -571,7 +571,14 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode { let nextTransitionVersion = Atomic(value: 0) - let historyViewTransitionDisposable = combineLatest(queue: messageViewQueue, historyViewUpdate, self.chatPresentationDataPromise.get(), selectedMessages, automaticDownloadNetworkType, self.historyAppearsClearedPromise.get(), animatedEmojiStickers).start(next: { [weak self] update, chatPresentationData, selectedMessages, networkType, historyAppearsCleared, animatedEmojiStickers in + let historyViewTransitionDisposable = combineLatest(queue: messageViewQueue, + historyViewUpdate, + self.chatPresentationDataPromise.get(), + selectedMessages, + automaticDownloadNetworkType, + self.historyAppearsClearedPromise.get(), + animatedEmojiStickers + ).start(next: { [weak self] update, chatPresentationData, selectedMessages, networkType, historyAppearsCleared, animatedEmojiStickers in func applyHole() { Queue.mainQueue().async { if let strongSelf = self { diff --git a/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift b/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift index 41732298c8..8d0a8134ae 100644 --- a/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift +++ b/submodules/TelegramUI/TelegramUI/PreparedChatHistoryViewTransition.swift @@ -37,28 +37,28 @@ func preparedChatHistoryViewTransition(from fromView: ChatHistoryView?, to toVie var scrollToItem: ListViewScrollToItem? switch reason { - case let .Initial(fadeIn): - if fadeIn { - animateIn = true - } else { - let _ = options.insert(.LowLatency) - let _ = options.insert(.Synchronous) - let _ = options.insert(.PreferSynchronousResourceLoading) + case let .Initial(fadeIn): + if fadeIn { + animateIn = true + } else { + let _ = options.insert(.LowLatency) + let _ = options.insert(.Synchronous) + let _ = options.insert(.PreferSynchronousResourceLoading) + } + case .InteractiveChanges: + let _ = options.insert(.AnimateAlpha) + let _ = options.insert(.AnimateInsertion) + + for (index, _, _) in mergeResult.indicesAndItems.sorted(by: { $0.0 > $1.0 }) { + let adjustedIndex = updatedCount - 1 - index + if adjustedIndex == maxAnimatedInsertionIndex + 1 { + maxAnimatedInsertionIndex += 1 } - case .InteractiveChanges: - let _ = options.insert(.AnimateAlpha) - let _ = options.insert(.AnimateInsertion) - - for (index, _, _) in mergeResult.indicesAndItems.sorted(by: { $0.0 > $1.0 }) { - let adjustedIndex = updatedCount - 1 - index - if adjustedIndex == maxAnimatedInsertionIndex + 1 { - maxAnimatedInsertionIndex += 1 - } - } - case .Reload: - stationaryItemRange = (0, Int.max) - case .HoleReload: - stationaryItemRange = (0, Int.max) + } + case .Reload: + stationaryItemRange = (0, Int.max) + case .HoleReload: + stationaryItemRange = (0, Int.max) } for (index, entry, previousIndex) in mergeResult.indicesAndItems {