mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
pr suggestions
This commit is contained in:
@@ -8,21 +8,22 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
struct LiveLocationShareProxy: Hashable {
|
||||
struct LiveLocationShare: Hashable {
|
||||
let userID: String
|
||||
let geoURI: GeoURI?
|
||||
let timestamp: Date
|
||||
let timeoutDate: Date
|
||||
}
|
||||
|
||||
extension LiveLocationShareProxy {
|
||||
init(liveLocationShare: LiveLocationShare) {
|
||||
|
||||
init(userID: String, geoURI: GeoURI?, timestamp: Date, timeoutDate: Date) {
|
||||
self.userID = userID
|
||||
self.geoURI = geoURI
|
||||
self.timestamp = timestamp
|
||||
self.timeoutDate = timeoutDate
|
||||
}
|
||||
|
||||
init(liveLocationShare: MatrixRustSDK.LiveLocationShare) {
|
||||
userID = liveLocationShare.userId
|
||||
if let geoURI = liveLocationShare.lastLocation?.location.geoUri {
|
||||
self.geoURI = GeoURI(string: geoURI)
|
||||
} else {
|
||||
geoURI = nil
|
||||
}
|
||||
geoURI = (liveLocationShare.lastLocation?.location.geoUri).flatMap(GeoURI.init(string:))
|
||||
timestamp = Date(timeIntervalSince1970: Double(liveLocationShare.startTs))
|
||||
timeoutDate = timestamp.addingTimeInterval(Double(liveLocationShare.timeout) / 1000)
|
||||
}
|
||||
|
||||
+13
-13
@@ -9,18 +9,18 @@ import Combine
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
final class LiveLocationSharesService: LiveLocationSharesServiceProtocol {
|
||||
final class RoomLiveLocationService: RoomLiveLocationServiceProtocol {
|
||||
// periphery:ignore - required for instance retention in the rust codebase
|
||||
private let liveLocationShares: LiveLocationShares
|
||||
// periphery:ignore - required for instance retention in the rust codebase
|
||||
private var observationToken: TaskHandle?
|
||||
|
||||
private let liveLocationSharesSubject = PassthroughSubject<[LiveLocationShareProxy], Never>()
|
||||
var liveLocationSharesPublisher: AnyPublisher<[LiveLocationShareProxy], Never> {
|
||||
liveLocationSharesSubject.eraseToAnyPublisher()
|
||||
private let liveLocationsSubject = PassthroughSubject<[LiveLocationShare], Never>()
|
||||
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> {
|
||||
liveLocationsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
private var previousLiveLocationShares: [LiveLocationShareProxy] = []
|
||||
private var previousLiveLocationShares: [LiveLocationShare] = []
|
||||
|
||||
init(liveLocationShares: LiveLocationShares) {
|
||||
self.liveLocationShares = liveLocationShares
|
||||
@@ -30,39 +30,39 @@ final class LiveLocationSharesService: LiveLocationSharesServiceProtocol {
|
||||
|
||||
MXLog.info("Received live location shares update")
|
||||
let updatedShares = handleLiveLocationShareUpdates(updates)
|
||||
liveLocationSharesSubject.send(updatedShares)
|
||||
liveLocationsSubject.send(updatedShares)
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func handleLiveLocationShareUpdates(_ updates: [LiveLocationShareUpdate]) -> [LiveLocationShareProxy] {
|
||||
private func handleLiveLocationShareUpdates(_ updates: [LiveLocationShareUpdate]) -> [LiveLocationShare] {
|
||||
var shares = previousLiveLocationShares
|
||||
|
||||
for update in updates {
|
||||
switch update {
|
||||
case .append(let values):
|
||||
shares.append(contentsOf: values.map(LiveLocationShareProxy.init))
|
||||
shares.append(contentsOf: values.map(LiveLocationShare.init))
|
||||
case .clear:
|
||||
shares.removeAll()
|
||||
case .pushFront(let value):
|
||||
shares.insert(LiveLocationShareProxy(liveLocationShare: value), at: 0)
|
||||
shares.insert(LiveLocationShare(liveLocationShare: value), at: 0)
|
||||
case .pushBack(let value):
|
||||
shares.append(LiveLocationShareProxy(liveLocationShare: value))
|
||||
shares.append(LiveLocationShare(liveLocationShare: value))
|
||||
case .popFront:
|
||||
shares.removeFirst()
|
||||
case .popBack:
|
||||
shares.removeLast()
|
||||
case .insert(let index, let value):
|
||||
shares.insert(LiveLocationShareProxy(liveLocationShare: value), at: Int(index))
|
||||
shares.insert(LiveLocationShare(liveLocationShare: value), at: Int(index))
|
||||
case .set(let index, let value):
|
||||
shares[Int(index)] = LiveLocationShareProxy(liveLocationShare: value)
|
||||
shares[Int(index)] = LiveLocationShare(liveLocationShare: value)
|
||||
case .remove(let index):
|
||||
shares.remove(at: Int(index))
|
||||
case .truncate(let length):
|
||||
shares.removeSubrange(Int(length)..<shares.count)
|
||||
case .reset(let values):
|
||||
shares = values.map(LiveLocationShareProxy.init)
|
||||
shares = values.map(LiveLocationShare.init)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,6 +9,6 @@ import Combine
|
||||
import Foundation
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol LiveLocationSharesServiceProtocol {
|
||||
var liveLocationSharesPublisher: AnyPublisher<[LiveLocationShareProxy], Never> { get }
|
||||
protocol RoomLiveLocationServiceProtocol {
|
||||
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> { get }
|
||||
}
|
||||
Reference in New Issue
Block a user