Move completions around

This commit is contained in:
Alfonso Grillo 2022-10-11 17:18:05 +02:00
parent 6831a00ad2
commit ec746fbb87

View file

@ -103,8 +103,10 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
self.completion?() self.completion?()
case .share(let latitude, let longitude, let coordinateType): case .share(let latitude, let longitude, let coordinateType):
self.shareStaticLocation(latitude: latitude, longitude: longitude, coordinateType: coordinateType) self.shareStaticLocation(latitude: latitude, longitude: longitude, coordinateType: coordinateType)
self.completion?()
case .shareLiveLocation(let timeout): case .shareLiveLocation(let timeout):
self.startLiveLocationSharing(with: timeout) self.startLiveLocationSharing(with: timeout)
self.completion?()
case .checkLiveLocationCanBeStarted(let completion): case .checkLiveLocationCanBeStarted(let completion):
self.checkLiveLocationCanBeStarted(completion: completion) self.checkLiveLocationCanBeStarted(completion: completion)
} }
@ -129,29 +131,20 @@ final class LocationSharingCoordinator: Coordinator, Presentable {
} failure: { error in } failure: { error in
MXLog.error("[LocationSharingCoordinator] Failed sharing location", context: error) MXLog.error("[LocationSharingCoordinator] Failed sharing location", context: error)
} }
self.completion?()
} }
private func startLiveLocationSharing(with timeout: TimeInterval) { private func startLiveLocationSharing(with timeout: TimeInterval) {
guard let locationService = parameters.roomDataSource.mxSession.locationService, let roomId = parameters.roomDataSource.roomId else { guard let locationService = parameters.roomDataSource.mxSession.locationService, let roomId = parameters.roomDataSource.roomId else {
locationSharingViewModel.stopLoading(error: .locationSharingError)
return return
} }
locationService.startUserLocationSharing(withRoomId: roomId, description: nil, timeout: timeout) { [weak self] response in locationService.startUserLocationSharing(withRoomId: roomId, description: nil, timeout: timeout) { response in
guard let self = self else { return }
switch response { switch response {
case .success: case .success:
break break
case .failure(let error): case .failure(let error):
MXLog.error("[LocationSharingCoordinator] Failed to start live location sharing", context: error) MXLog.error("[LocationSharingCoordinator] Failed to start live location sharing", context: error)
} }
DispatchQueue.main.async {
self.completion?()
}
} }
} }