mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
5982: Clean code and add tests
This commit is contained in:
@@ -35,38 +35,12 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(mapStyleURL: URL, avatarData: AvatarInputProtocol, location: CLLocationCoordinate2D? = nil, coordinateType: LocationSharingCoordinateType, isLiveLocationSharingEnabled: Bool = false) {
|
||||
|
||||
var sharedAnnotation: LocationAnnotation?
|
||||
var annotations: [LocationAnnotation] = []
|
||||
var highlightedAnnotation: LocationAnnotation?
|
||||
var showsUserLocation: Bool = false
|
||||
|
||||
// Displaying an existing location
|
||||
if let sharedCoordinate = location {
|
||||
let sharedLocationAnnotation: LocationAnnotation
|
||||
switch coordinateType {
|
||||
case .user:
|
||||
sharedLocationAnnotation = UserLocationAnnotation(avatarData: avatarData, coordinate: sharedCoordinate)
|
||||
case .pin:
|
||||
sharedLocationAnnotation = PinLocationAnnotation(coordinate: sharedCoordinate)
|
||||
}
|
||||
|
||||
annotations.append(sharedLocationAnnotation)
|
||||
highlightedAnnotation = sharedLocationAnnotation
|
||||
|
||||
sharedAnnotation = sharedLocationAnnotation
|
||||
} else {
|
||||
// Share current location
|
||||
showsUserLocation = true
|
||||
}
|
||||
|
||||
init(mapStyleURL: URL, avatarData: AvatarInputProtocol, isLiveLocationSharingEnabled: Bool = false) {
|
||||
let viewState = LocationSharingViewState(mapStyleURL: mapStyleURL,
|
||||
userAvatarData: avatarData,
|
||||
sharedAnnotation: sharedAnnotation,
|
||||
annotations: annotations,
|
||||
highlightedAnnotation: highlightedAnnotation,
|
||||
showsUserLocation: showsUserLocation,
|
||||
annotations: [],
|
||||
highlightedAnnotation: nil,
|
||||
showsUserLocation: true,
|
||||
isLiveLocationSharingEnabled: isLiveLocationSharingEnabled)
|
||||
|
||||
super.init(initialViewState: viewState)
|
||||
@@ -84,12 +58,6 @@ class LocationSharingViewModel: LocationSharingViewModelType, LocationSharingVie
|
||||
case .cancel:
|
||||
completion?(.cancel)
|
||||
case .share:
|
||||
// Share existing location
|
||||
if let location = state.sharedAnnotation?.coordinate {
|
||||
completion?(.share(latitude: location.latitude, longitude: location.longitude, coordinateType: .user))
|
||||
return
|
||||
}
|
||||
|
||||
// Share current user location
|
||||
guard let location = state.bindings.userLocation else {
|
||||
processError(.failedLocatingUser)
|
||||
|
||||
Reference in New Issue
Block a user