Delete an existing broadcast (#7219)

This commit is contained in:
Yoan Pintas
2023-01-10 09:32:18 +00:00
committed by GitHub
parent b22a301081
commit 27023ef037
7 changed files with 54 additions and 21 deletions
@@ -56,6 +56,10 @@ final class VoiceBroadcastPlaybackCoordinator: Coordinator, Presentable {
}
deinit {
viewModel.context.send(viewAction: .redact)
}
// MARK: - Public
func start() { }
@@ -29,7 +29,19 @@ import Foundation
}
}
}
var coordinatorsForEventIdentifiers = [String: VoiceBroadcastPlaybackCoordinator]()
private var coordinatorsForEventIdentifiers = [String: VoiceBroadcastPlaybackCoordinator]() {
didSet {
if !self.coordinatorsForEventIdentifiers.isEmpty && self.redactionsListener == nil {
redactionsListener = session?.listenToEvents([MXEventType(identifier: kMXEventTypeStringRoomRedaction)], self.handleEvent)
}
if self.coordinatorsForEventIdentifiers.isEmpty && self.redactionsListener != nil {
session?.removeListener(self.redactionsListener)
self.redactionsListener = nil
}
}
}
private var redactionsListener: Any?
private override init() { }
@@ -58,16 +70,24 @@ import Foundation
return coordinator.toPresentable()
}
/// Retrieve the voiceBroadcast timeline coordinator for the given event or nil if it hasn't been created yet
func voiceBroadcastPlaybackCoordinatorForEventIdentifier(_ eventIdentifier: String) -> VoiceBroadcastPlaybackCoordinator? {
coordinatorsForEventIdentifiers[eventIdentifier]
}
/// Pause current voice broadcast playback.
@objc public func pausePlaying() {
coordinatorsForEventIdentifiers.forEach { _, coordinator in
coordinator.pausePlaying()
}
}
private func handleEvent(event: MXEvent, direction: MXTimelineDirection, customObject: Any?) {
if direction == .backwards {
// ignore backwards events
return
}
var coordinator = coordinatorsForEventIdentifiers.removeValue(forKey: event.redacts)
coordinator?.toPresentable().dismiss(animated: false) {
coordinator = nil
}
}
}
@@ -102,10 +102,9 @@ class VoiceBroadcastPlaybackViewModel: VoiceBroadcastPlaybackViewModelType, Voic
private func release() {
MXLog.debug("[VoiceBroadcastPlaybackViewModel] release")
if let audioPlayer = audioPlayer {
audioPlayer.deregisterDelegate(self)
self.audioPlayer = nil
}
self.stop()
self.voiceBroadcastAggregator.delegate = nil
self.voiceBroadcastAggregator.stop()
}
// MARK: - Public
@@ -116,6 +115,8 @@ class VoiceBroadcastPlaybackViewModel: VoiceBroadcastPlaybackViewModelType, Voic
play()
case .pause:
pause()
case .redact:
release()
case .sliderChange(let didChange):
didSliderChanged(didChange)
case .backward:
@@ -468,7 +469,8 @@ extension VoiceBroadcastPlaybackViewModel: VoiceMessageAudioPlayerDelegate {
MXLog.debug("[VoiceBroadcastPlaybackViewModel] audioPlayerDidStopPlaying")
state.playbackState = .stopped
state.playingState.isLive = false
release()
audioPlayer.deregisterDelegate(self)
self.audioPlayer = nil
}
func audioPlayer(_ audioPlayer: VoiceMessageAudioPlayer, didFailWithError error: Error) {
@@ -23,6 +23,7 @@ enum VoiceBroadcastPlaybackViewAction {
case sliderChange(didChange: Bool)
case backward
case forward
case redact
}
enum VoiceBroadcastPlaybackState {
@@ -18,7 +18,7 @@ import Foundation
import SwiftUI
typealias MockVoiceBroadcastPlaybackViewModelType = StateStoreViewModel<VoiceBroadcastPlaybackViewState, VoiceBroadcastPlaybackViewAction>
class MockVoiceBroadcastPlaybackViewModel: MockVoiceBroadcastPlaybackViewModelType, VoiceBroadcastPlaybackViewModelProtocol {
class MockVoiceBroadcastPlaybackViewModel: MockVoiceBroadcastPlaybackViewModelType, VoiceBroadcastPlaybackViewModelProtocol {
}
/// Using an enum for the screen allows you define the different state cases with
@@ -19,5 +19,5 @@ import Foundation
typealias VoiceBroadcastPlaybackViewModelType = StateStoreViewModel<VoiceBroadcastPlaybackViewState, VoiceBroadcastPlaybackViewAction>
protocol VoiceBroadcastPlaybackViewModelProtocol {
var context: VoiceBroadcastPlaybackViewModelType.Context { get }
var context: VoiceBroadcastPlaybackViewModelType.Context { get }
}