pr suggestions
This commit is contained in:
@@ -10414,17 +10414,17 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol, @unchecked Sendable {
|
||||
return clearDraftThreadRootEventIDReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - getLiveLocationSharesService
|
||||
//MARK: - makeLiveLocationService
|
||||
|
||||
var getLiveLocationSharesServiceUnderlyingCallsCount = 0
|
||||
var getLiveLocationSharesServiceCallsCount: Int {
|
||||
var makeLiveLocationServiceUnderlyingCallsCount = 0
|
||||
var makeLiveLocationServiceCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return getLiveLocationSharesServiceUnderlyingCallsCount
|
||||
return makeLiveLocationServiceUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = getLiveLocationSharesServiceUnderlyingCallsCount
|
||||
returnValue = makeLiveLocationServiceUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
@@ -10432,27 +10432,27 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol, @unchecked Sendable {
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
getLiveLocationSharesServiceUnderlyingCallsCount = newValue
|
||||
makeLiveLocationServiceUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
getLiveLocationSharesServiceUnderlyingCallsCount = newValue
|
||||
makeLiveLocationServiceUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var getLiveLocationSharesServiceCalled: Bool {
|
||||
return getLiveLocationSharesServiceCallsCount > 0
|
||||
var makeLiveLocationServiceCalled: Bool {
|
||||
return makeLiveLocationServiceCallsCount > 0
|
||||
}
|
||||
|
||||
var getLiveLocationSharesServiceUnderlyingReturnValue: LiveLocationSharesServiceProtocol!
|
||||
var getLiveLocationSharesServiceReturnValue: LiveLocationSharesServiceProtocol! {
|
||||
var makeLiveLocationServiceUnderlyingReturnValue: RoomLiveLocationServiceProtocol!
|
||||
var makeLiveLocationServiceReturnValue: RoomLiveLocationServiceProtocol! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return getLiveLocationSharesServiceUnderlyingReturnValue
|
||||
return makeLiveLocationServiceUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: LiveLocationSharesServiceProtocol? = nil
|
||||
var returnValue: RoomLiveLocationServiceProtocol? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = getLiveLocationSharesServiceUnderlyingReturnValue
|
||||
returnValue = makeLiveLocationServiceUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
@@ -10460,22 +10460,22 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol, @unchecked Sendable {
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
getLiveLocationSharesServiceUnderlyingReturnValue = newValue
|
||||
makeLiveLocationServiceUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
getLiveLocationSharesServiceUnderlyingReturnValue = newValue
|
||||
makeLiveLocationServiceUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var getLiveLocationSharesServiceClosure: (() async -> LiveLocationSharesServiceProtocol)?
|
||||
var makeLiveLocationServiceClosure: (() async -> RoomLiveLocationServiceProtocol)?
|
||||
|
||||
func getLiveLocationSharesService() async -> LiveLocationSharesServiceProtocol {
|
||||
getLiveLocationSharesServiceCallsCount += 1
|
||||
if let getLiveLocationSharesServiceClosure = getLiveLocationSharesServiceClosure {
|
||||
return await getLiveLocationSharesServiceClosure()
|
||||
func makeLiveLocationService() async -> RoomLiveLocationServiceProtocol {
|
||||
makeLiveLocationServiceCallsCount += 1
|
||||
if let makeLiveLocationServiceClosure = makeLiveLocationServiceClosure {
|
||||
return await makeLiveLocationServiceClosure()
|
||||
} else {
|
||||
return getLiveLocationSharesServiceReturnValue
|
||||
return makeLiveLocationServiceReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - startLiveLocationShare
|
||||
@@ -11968,14 +11968,6 @@ class LiveLocationManagerMock: LiveLocationManagerProtocol, @unchecked Sendable
|
||||
await stopLiveLocationRoomIDClosure?(roomID)
|
||||
}
|
||||
}
|
||||
class LiveLocationSharesServiceMock: LiveLocationSharesServiceProtocol, @unchecked Sendable {
|
||||
var liveLocationSharesPublisher: AnyPublisher<[LiveLocationShareProxy], Never> {
|
||||
get { return underlyingLiveLocationSharesPublisher }
|
||||
set(value) { underlyingLiveLocationSharesPublisher = value }
|
||||
}
|
||||
var underlyingLiveLocationSharesPublisher: AnyPublisher<[LiveLocationShareProxy], Never>!
|
||||
|
||||
}
|
||||
class MediaLoaderMock: MediaLoaderProtocol, @unchecked Sendable {
|
||||
|
||||
//MARK: - loadMediaContentForSource
|
||||
@@ -15111,6 +15103,14 @@ class RoomInfoProxyMock: RoomInfoProxyProtocol, @unchecked Sendable {
|
||||
var successor: SuccessorRoom?
|
||||
var heroes: [RoomHero] = []
|
||||
|
||||
}
|
||||
class RoomLiveLocationServiceMock: RoomLiveLocationServiceProtocol, @unchecked Sendable {
|
||||
var liveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never> {
|
||||
get { return underlyingLiveLocationsPublisher }
|
||||
set(value) { underlyingLiveLocationsPublisher = value }
|
||||
}
|
||||
var underlyingLiveLocationsPublisher: AnyPublisher<[LiveLocationShare], Never>!
|
||||
|
||||
}
|
||||
class RoomMemberProxyMock: RoomMemberProxyProtocol, @unchecked Sendable {
|
||||
var userID: String {
|
||||
|
||||
@@ -68,7 +68,7 @@ extension JoinedRoomProxyMock {
|
||||
typingMembersPublisher = CurrentValueSubject([]).asCurrentValuePublisher()
|
||||
identityStatusChangesPublisher = CurrentValueSubject([]).asCurrentValuePublisher()
|
||||
|
||||
getLiveLocationSharesServiceReturnValue = LiveLocationSharesServiceMock(.init())
|
||||
makeLiveLocationServiceReturnValue = RoomLiveLocationServiceMock(.init())
|
||||
|
||||
updateMembersClosure = { }
|
||||
setNameClosure = { _ in .success(()) }
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
struct LiveLocationSharesServiceMockConfiguration {
|
||||
var shares: [LiveLocationShareProxy] = []
|
||||
}
|
||||
|
||||
extension LiveLocationSharesServiceMock {
|
||||
convenience init(_ configuration: LiveLocationSharesServiceMockConfiguration = .init()) {
|
||||
self.init()
|
||||
liveLocationSharesPublisher = CurrentValueSubject(configuration.shares).eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
20
ElementX/Sources/Mocks/RoomLiveLocationServiceMock.swift
Normal file
20
ElementX/Sources/Mocks/RoomLiveLocationServiceMock.swift
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Copyright 2026 Element Creations Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
struct RoomLiveLocationServiceMockConfiguration {
|
||||
var shares: [LiveLocationShare] = []
|
||||
}
|
||||
|
||||
extension RoomLiveLocationServiceMock {
|
||||
convenience init(_ configuration: RoomLiveLocationServiceMockConfiguration = .init()) {
|
||||
self.init()
|
||||
liveLocationsPublisher = CurrentValueSubject(configuration.shares).eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
@@ -754,8 +754,8 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
|
||||
// MARK: - Live Location
|
||||
|
||||
func getLiveLocationSharesService() async -> LiveLocationSharesServiceProtocol {
|
||||
await LiveLocationSharesService(liveLocationShares: room.liveLocationShares())
|
||||
func makeLiveLocationService() async -> RoomLiveLocationServiceProtocol {
|
||||
await RoomLiveLocationService(liveLocationShares: room.liveLocationShares())
|
||||
}
|
||||
|
||||
func startLiveLocationShare(duration: Duration) async -> Result<Void, RoomProxyError> {
|
||||
|
||||
@@ -197,7 +197,7 @@ protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
|
||||
|
||||
// MARK: - Live Location
|
||||
|
||||
func getLiveLocationSharesService() async -> LiveLocationSharesServiceProtocol
|
||||
func makeLiveLocationService() async -> RoomLiveLocationServiceProtocol
|
||||
|
||||
func startLiveLocationShare(duration: Duration) async -> Result<Void, RoomProxyError>
|
||||
func sendLiveLocation(geoURI: GeoURI) async -> Result<Void, RoomProxyError>
|
||||
|
||||
Reference in New Issue
Block a user