mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-29 04:36:58 +02:00
Prepare LiveLocationSharingViewerService and handle mock.
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import CoreLocation
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
protocol LiveLocationSharingViewerServiceProtocol {
|
||||
|
||||
var usersLiveLocation: [UserLiveLocation] { get }
|
||||
|
||||
func isCurrentUserId(_ userId: String) -> Bool
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreLocation
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class LiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private(set) var usersLiveLocation: [UserLiveLocation] = []
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let session: MXSession
|
||||
|
||||
// MARK: Public
|
||||
|
||||
func isCurrentUserId(_ userId: String) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(session: MXSession) {
|
||||
self.session = session
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import CoreLocation
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
class MockLiveLocationSharingViewerService: LiveLocationSharingViewerServiceProtocol {
|
||||
|
||||
private(set) var usersLiveLocation: [UserLiveLocation] = []
|
||||
|
||||
func isCurrentUserId(_ userId: String) -> Bool {
|
||||
return "@alice:matrix.org" == userId
|
||||
}
|
||||
|
||||
init(generateRandomUsers: Bool = false) {
|
||||
|
||||
let firstUserLiveLocation = self.createFirstUserLiveLocation()
|
||||
|
||||
let secondUserLiveLocation = self.createSecondUserLiveLocation()
|
||||
|
||||
var usersLiveLocation: [UserLiveLocation] = [firstUserLiveLocation, secondUserLiveLocation]
|
||||
|
||||
|
||||
if generateRandomUsers {
|
||||
for _ in 1...20 {
|
||||
let randomUser = self.createRandomUserLiveLocation()
|
||||
usersLiveLocation.append(randomUser)
|
||||
}
|
||||
}
|
||||
|
||||
self.usersLiveLocation = usersLiveLocation
|
||||
}
|
||||
|
||||
private func createFirstUserLiveLocation() -> UserLiveLocation {
|
||||
let userAvatarData = AvatarInput(mxContentUri: nil, matrixItemId: "@alice:matrix.org", displayName: "Alice")
|
||||
let userCoordinate = CLLocationCoordinate2D(latitude: 51.4932641, longitude: -0.257096)
|
||||
|
||||
let currentTimeInterval = Date().timeIntervalSince1970
|
||||
let timestamp = currentTimeInterval - 300
|
||||
let timeout: TimeInterval = 800
|
||||
let lastUpdate = currentTimeInterval - 100
|
||||
|
||||
return UserLiveLocation(avatarData: userAvatarData, timestamp: timestamp, timeout: timeout, lastUpdate: lastUpdate, coordinate: userCoordinate)
|
||||
}
|
||||
|
||||
private func createSecondUserLiveLocation() -> UserLiveLocation {
|
||||
|
||||
let userAvatarData = AvatarInput(mxContentUri: nil, matrixItemId: "@bob:matrix.org", displayName: "Bob")
|
||||
let coordinate = CLLocationCoordinate2D(latitude: 51.4952641, longitude: -0.259096)
|
||||
|
||||
let currentTimeInterval = Date().timeIntervalSince1970
|
||||
|
||||
let timestamp = currentTimeInterval - 600
|
||||
let timeout: TimeInterval = 1200
|
||||
let lastUpdate = currentTimeInterval - 300
|
||||
|
||||
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)
|
||||
|
||||
let userAvatarData = AvatarInput(mxContentUri: nil, matrixItemId: "@user_\(uuidString):matrix.org", displayName: "User \(uuidString)")
|
||||
let coordinate = CLLocationCoordinate2D(latitude: 51.4952641 + random, longitude: -0.259096 + random)
|
||||
|
||||
let currentTimeInterval = Date().timeIntervalSince1970
|
||||
|
||||
let timestamp = currentTimeInterval - 600
|
||||
let timeout: TimeInterval = 1200
|
||||
let lastUpdate = currentTimeInterval - 300
|
||||
|
||||
return UserLiveLocation(avatarData: userAvatarData, timestamp: timestamp, timeout: timeout, lastUpdate: lastUpdate, coordinate: coordinate)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import CoreLocation
|
||||
|
||||
/// Represents user live location
|
||||
struct UserLiveLocation {
|
||||
|
||||
var userId: String {
|
||||
return avatarData.matrixItemId
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
return avatarData.displayName ?? self.userId
|
||||
}
|
||||
|
||||
let avatarData: AvatarInputProtocol
|
||||
|
||||
/// Location sharing start date
|
||||
let timestamp: TimeInterval
|
||||
|
||||
/// Sharing duration from the start sharing date
|
||||
let timeout: TimeInterval
|
||||
|
||||
/// Last coordinatore update date
|
||||
let lastUpdate: TimeInterval
|
||||
|
||||
let coordinate: CLLocationCoordinate2D
|
||||
}
|
||||
Reference in New Issue
Block a user