mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-04 23:17:43 +02:00
Configured and applied SwiftFormat
This commit is contained in:
committed by
Stefan Ceriu
parent
ff2e6ddfa7
commit
43c28d23b7
+2
-3
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,12 +14,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
protocol LiveLocationSharingViewerServiceProtocol {
|
||||
|
||||
/// All shared users live location
|
||||
var usersLiveLocation: [UserLiveLocation] { get }
|
||||
|
||||
|
||||
+17
-19
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,12 +14,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
import MatrixSDK
|
||||
|
||||
class LiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private(set) var usersLiveLocation: [UserLiveLocation] = []
|
||||
@@ -40,17 +39,17 @@ class LiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol
|
||||
self.session = session
|
||||
self.roomId = roomId
|
||||
|
||||
self.updateUsersLiveLocation(notifyUpdate: false)
|
||||
updateUsersLiveLocation(notifyUpdate: false)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func isCurrentUserId(_ userId: String) -> Bool {
|
||||
return self.session.myUserId == userId
|
||||
session.myUserId == userId
|
||||
}
|
||||
|
||||
func startListeningLiveLocationUpdates() {
|
||||
self.beaconInfoSummaryListener = self.session.aggregations.beaconAggregations.listenToBeaconInfoSummaryUpdateInRoom(withId: self.roomId) { [weak self] _ in
|
||||
beaconInfoSummaryListener = session.aggregations.beaconAggregations.listenToBeaconInfoSummaryUpdateInRoom(withId: roomId) { [weak self] _ in
|
||||
|
||||
self?.updateUsersLiveLocation(notifyUpdate: true)
|
||||
}
|
||||
@@ -58,17 +57,17 @@ class LiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol
|
||||
|
||||
func stopListeningLiveLocationUpdates() {
|
||||
if let listener = beaconInfoSummaryListener {
|
||||
self.session.aggregations.removeListener(listener)
|
||||
self.beaconInfoSummaryListener = nil
|
||||
session.aggregations.removeListener(listener)
|
||||
beaconInfoSummaryListener = nil
|
||||
}
|
||||
}
|
||||
|
||||
func stopUserLiveLocationSharing(completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
self.session.locationService.stopUserLocationSharing(inRoomWithId: roomId) { response in
|
||||
session.locationService.stopUserLocationSharing(inRoomWithId: roomId) { response in
|
||||
|
||||
switch response {
|
||||
case .success:
|
||||
completion(.success(Void()))
|
||||
completion(.success(()))
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
@@ -78,17 +77,16 @@ class LiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol
|
||||
// MARK: - Private
|
||||
|
||||
private func updateUsersLiveLocation(notifyUpdate: Bool) {
|
||||
let beaconInfoSummaries = self.session.locationService.getDisplayableBeaconInfoSummaries(inRoomWithId: roomId)
|
||||
self.usersLiveLocation = Self.usersLiveLocation(fromBeaconInfoSummaries: beaconInfoSummaries, session: session)
|
||||
let beaconInfoSummaries = session.locationService.getDisplayableBeaconInfoSummaries(inRoomWithId: roomId)
|
||||
usersLiveLocation = Self.usersLiveLocation(fromBeaconInfoSummaries: beaconInfoSummaries, session: session)
|
||||
|
||||
if notifyUpdate {
|
||||
self.didUpdateUsersLiveLocation?(self.usersLiveLocation)
|
||||
didUpdateUsersLiveLocation?(usersLiveLocation)
|
||||
}
|
||||
}
|
||||
|
||||
class private func usersLiveLocation(fromBeaconInfoSummaries beaconInfoSummaries: [MXBeaconInfoSummaryProtocol], session: MXSession) -> [UserLiveLocation] {
|
||||
|
||||
return beaconInfoSummaries.compactMap { beaconInfoSummary in
|
||||
private class func usersLiveLocation(fromBeaconInfoSummaries beaconInfoSummaries: [MXBeaconInfoSummaryProtocol], session: MXSession) -> [UserLiveLocation] {
|
||||
beaconInfoSummaries.compactMap { beaconInfoSummary in
|
||||
|
||||
let beaconInfo = beaconInfoSummary.beaconInfo
|
||||
|
||||
@@ -98,9 +96,9 @@ class LiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol
|
||||
|
||||
let avatarData = session.avatarInput(for: beaconInfoSummary.userId)
|
||||
|
||||
let timestamp = TimeInterval(beaconInfo.timestamp/1000)
|
||||
let timeout = TimeInterval(beaconInfo.timeout/1000)
|
||||
let lastUpdate = TimeInterval(lastBeacon.timestamp/1000)
|
||||
let timestamp = TimeInterval(beaconInfo.timestamp / 1000)
|
||||
let timeout = TimeInterval(beaconInfo.timeout / 1000)
|
||||
let lastUpdate = TimeInterval(lastBeacon.timestamp / 1000)
|
||||
|
||||
let coordinate = CLLocationCoordinate2D(latitude: lastBeacon.location.latitude, longitude: lastBeacon.location.longitude)
|
||||
|
||||
|
||||
+9
-21
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,12 +14,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
class MockLiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private(set) var usersLiveLocation: [UserLiveLocation] = []
|
||||
@@ -29,17 +28,15 @@ class MockLiveLocationSharingViewerService: LiveLocationSharingViewerServiceProt
|
||||
// MARK: Setup
|
||||
|
||||
init(generateRandomUsers: Bool = false) {
|
||||
let firstUserLiveLocation = createFirstUserLiveLocation()
|
||||
|
||||
let firstUserLiveLocation = self.createFirstUserLiveLocation()
|
||||
|
||||
let secondUserLiveLocation = self.createSecondUserLiveLocation()
|
||||
let secondUserLiveLocation = createSecondUserLiveLocation()
|
||||
|
||||
var usersLiveLocation: [UserLiveLocation] = [firstUserLiveLocation, secondUserLiveLocation]
|
||||
|
||||
|
||||
if generateRandomUsers {
|
||||
for _ in 1...20 {
|
||||
let randomUser = self.createRandomUserLiveLocation()
|
||||
let randomUser = createRandomUserLiveLocation()
|
||||
usersLiveLocation.append(randomUser)
|
||||
}
|
||||
}
|
||||
@@ -50,20 +47,14 @@ class MockLiveLocationSharingViewerService: LiveLocationSharingViewerServiceProt
|
||||
// MARK: Public
|
||||
|
||||
func isCurrentUserId(_ userId: String) -> Bool {
|
||||
return "@alice:matrix.org" == userId
|
||||
userId == "@alice:matrix.org"
|
||||
}
|
||||
|
||||
func startListeningLiveLocationUpdates() {
|
||||
|
||||
}
|
||||
func startListeningLiveLocationUpdates() { }
|
||||
|
||||
func stopListeningLiveLocationUpdates() {
|
||||
|
||||
}
|
||||
func stopListeningLiveLocationUpdates() { }
|
||||
|
||||
func stopUserLiveLocationSharing(completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
|
||||
}
|
||||
func stopUserLiveLocationSharing(completion: @escaping (Result<Void, Error>) -> Void) { }
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@@ -80,7 +71,6 @@ class MockLiveLocationSharingViewerService: LiveLocationSharingViewerServiceProt
|
||||
}
|
||||
|
||||
private func createSecondUserLiveLocation() -> UserLiveLocation {
|
||||
|
||||
let userAvatarData = AvatarInput(mxContentUri: nil, matrixItemId: "@bob:matrix.org", displayName: "Bob")
|
||||
let coordinate = CLLocationCoordinate2D(latitude: 51.4952641, longitude: -0.259096)
|
||||
|
||||
@@ -93,9 +83,7 @@ class MockLiveLocationSharingViewerService: LiveLocationSharingViewerServiceProt
|
||||
return UserLiveLocation(avatarData: userAvatarData, timestamp: timestamp, timeout: timeout, lastUpdate: lastUpdate, coordinate: coordinate)
|
||||
}
|
||||
|
||||
|
||||
private func createRandomUserLiveLocation() -> UserLiveLocation {
|
||||
|
||||
let uuidString = UUID().uuidString.suffix(8)
|
||||
|
||||
let random = Double.random(in: 0.005...0.010)
|
||||
|
||||
+4
-5
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,18 +14,17 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreLocation
|
||||
import Foundation
|
||||
|
||||
/// Represents user live location
|
||||
struct UserLiveLocation {
|
||||
|
||||
var userId: String {
|
||||
return avatarData.matrixItemId
|
||||
avatarData.matrixItemId
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
return avatarData.displayName ?? self.userId
|
||||
avatarData.displayName ?? userId
|
||||
}
|
||||
|
||||
let avatarData: AvatarInputProtocol
|
||||
|
||||
Reference in New Issue
Block a user