From caf23094b065f2e07e5760c3ad641e1f0dc175f1 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Tue, 4 Jul 2023 08:39:32 +0200 Subject: [PATCH] Update SDK to 1.0.94-alpha (#1232) * Update SDK * Map new location fields * Add LocationRoomTimelineItemContent.AssetType --- ElementX.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/swiftpm/Package.resolved | 4 +-- .../RoomFlowCoordinator.swift | 10 +++++-- .../Mocks/Generated/GeneratedMocks.swift | 28 +++++++++---------- .../RoomScreen/RoomScreenCoordinator.swift | 6 ++-- .../Screens/RoomScreen/RoomScreenModels.swift | 2 +- .../RoomScreen/RoomScreenViewModel.swift | 4 +-- .../View/Replies/TimelineReplyView.swift | 2 +- .../Timeline/LocationRoomTimelineView.swift | 5 ++-- .../Sources/Services/Room/RoomProxy.swift | 13 +++++++-- .../Services/Room/RoomProxyProtocol.swift | 6 +++- .../RoomTimelineController.swift | 2 +- .../RoomTimelineControllerProtocol.swift | 2 +- .../LocationRoomTimelineItemContent.swift | 20 +++++++++++++ .../RoomTimelineItemFactory.swift | 17 ++++++++++- project.yml | 2 +- 16 files changed, 89 insertions(+), 36 deletions(-) diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 71c4fdd58..a2b43b177 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -5147,7 +5147,7 @@ repositoryURL = "https://github.com/matrix-org/matrix-rust-components-swift"; requirement = { kind = exactVersion; - version = "1.0.93-alpha"; + version = "1.0.94-alpha"; }; }; 96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = { diff --git a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index a2c39843c..39830ac13 100644 --- a/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -111,8 +111,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/matrix-org/matrix-rust-components-swift", "state" : { - "revision" : "40645a27fd55bbe0fa2065a90496fc823f45ff6e", - "version" : "1.0.93-alpha" + "revision" : "6d6c13bcf3bf900932599a62e2a157224d762630", + "version" : "1.0.94-alpha" } }, { diff --git a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift index f3e5fccda..5bd30dc4a 100644 --- a/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift +++ b/ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift @@ -308,8 +308,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { stateMachine.tryEvent(.presentEmojiPicker(itemID: itemID)) case .presentLocationPicker: stateMachine.tryEvent(.presentMapNavigator(interactionMode: .picker)) - case .presentLocationViewer(_, let geoURI): - stateMachine.tryEvent(.presentMapNavigator(interactionMode: .viewOnly(geoURI: geoURI))) + case .presentLocationViewer(_, let geoURI, let description): + stateMachine.tryEvent(.presentMapNavigator(interactionMode: .viewOnly(geoURI: geoURI, description: description))) case .presentRoomMemberDetails(member: let member): stateMachine.tryEvent(.presentRoomMemberDetails(member: .init(value: member))) case .presentMessageForwarding(let itemID): @@ -513,7 +513,11 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol { switch action { case .selectedLocation(let geoURI): Task { - _ = await self.roomProxy?.sendLocation(body: geoURI.bodyMessage, geoURI: geoURI) + _ = await self.roomProxy?.sendLocation(body: geoURI.bodyMessage, + geoURI: geoURI, + description: nil, + zoomLevel: nil, + assetType: .pin) self.navigationSplitCoordinator.setSheetCoordinator(nil) } case .close: diff --git a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift index 3dedd21af..27f4fe2a2 100644 --- a/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift +++ b/ElementX/Sources/Mocks/Generated/GeneratedMocks.swift @@ -705,23 +705,23 @@ class RoomProxyMock: RoomProxyProtocol { } //MARK: - sendLocation - var sendLocationBodyGeoURICallsCount = 0 - var sendLocationBodyGeoURICalled: Bool { - return sendLocationBodyGeoURICallsCount > 0 + var sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeCallsCount = 0 + var sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeCalled: Bool { + return sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeCallsCount > 0 } - var sendLocationBodyGeoURIReceivedArguments: (body: String, geoURI: GeoURI)? - var sendLocationBodyGeoURIReceivedInvocations: [(body: String, geoURI: GeoURI)] = [] - var sendLocationBodyGeoURIReturnValue: Result! - var sendLocationBodyGeoURIClosure: ((String, GeoURI) async -> Result)? + var sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeReceivedArguments: (body: String, geoURI: GeoURI, description: String?, zoomLevel: UInt8?, assetType: AssetType?)? + var sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeReceivedInvocations: [(body: String, geoURI: GeoURI, description: String?, zoomLevel: UInt8?, assetType: AssetType?)] = [] + var sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeReturnValue: Result! + var sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeClosure: ((String, GeoURI, String?, UInt8?, AssetType?) async -> Result)? - func sendLocation(body: String, geoURI: GeoURI) async -> Result { - sendLocationBodyGeoURICallsCount += 1 - sendLocationBodyGeoURIReceivedArguments = (body: body, geoURI: geoURI) - sendLocationBodyGeoURIReceivedInvocations.append((body: body, geoURI: geoURI)) - if let sendLocationBodyGeoURIClosure = sendLocationBodyGeoURIClosure { - return await sendLocationBodyGeoURIClosure(body, geoURI) + func sendLocation(body: String, geoURI: GeoURI, description: String?, zoomLevel: UInt8?, assetType: AssetType?) async -> Result { + sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeCallsCount += 1 + sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeReceivedArguments = (body: body, geoURI: geoURI, description: description, zoomLevel: zoomLevel, assetType: assetType) + sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeReceivedInvocations.append((body: body, geoURI: geoURI, description: description, zoomLevel: zoomLevel, assetType: assetType)) + if let sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeClosure = sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeClosure { + return await sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeClosure(body, geoURI, description, zoomLevel, assetType) } else { - return sendLocationBodyGeoURIReturnValue + return sendLocationBodyGeoURIDescriptionZoomLevelAssetTypeReturnValue } } //MARK: - retrySend diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift index d6a9aedb9..e1c9269d3 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift @@ -30,7 +30,7 @@ enum RoomScreenCoordinatorAction { case presentMediaUploadPreviewScreen(URL) case presentRoomDetails case presentLocationPicker - case presentLocationViewer(body: String, geoURI: GeoURI) + case presentLocationViewer(body: String, geoURI: GeoURI, description: String?) case presentEmojiPicker(itemID: String) case presentRoomMemberDetails(member: RoomMemberProxyProtocol) case presentMessageForwarding(itemID: String) @@ -85,8 +85,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol { actionsSubject.send(.presentRoomMemberDetails(member: member)) case .displayMessageForwarding(let itemID): actionsSubject.send(.presentMessageForwarding(itemID: itemID)) - case .displayLocation(let body, let geoURI): - actionsSubject.send(.presentLocationViewer(body: body, geoURI: geoURI)) + case .displayLocation(let body, let geoURI, let description): + actionsSubject.send(.presentLocationViewer(body: body, geoURI: geoURI, description: description)) } } } diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index d04de1308..c2b4a2dcc 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -29,7 +29,7 @@ enum RoomScreenViewModelAction { case displayMediaUploadPreviewScreen(url: URL) case displayRoomMemberDetails(member: RoomMemberProxyProtocol) case displayMessageForwarding(itemID: String) - case displayLocation(body: String, geoURI: GeoURI) + case displayLocation(body: String, geoURI: GeoURI, description: String?) } enum RoomScreenComposerMode: Equatable { diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 9a628d0c4..2607d1652 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -223,8 +223,8 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol switch action { case .displayMediaFile(let file, let title): state.bindings.mediaPreviewItem = MediaPreviewItem(file: file, title: title) - case .displayLocation(let body, let geoURI): - callback?(.displayLocation(body: body, geoURI: geoURI)) + case .displayLocation(let body, let geoURI, let description): + callback?(.displayLocation(body: body, geoURI: geoURI, description: description)) case .none: break } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Replies/TimelineReplyView.swift b/ElementX/Sources/Screens/RoomScreen/View/Replies/TimelineReplyView.swift index 1ce992c17..c5e545f8c 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Replies/TimelineReplyView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Replies/TimelineReplyView.swift @@ -229,7 +229,7 @@ struct TimelineReplyView_Previews: PreviewProvider { thumbnailSource: imageSource)))) TimelineReplyView(placement: .timeline, timelineItemReplyDetails: .loaded(sender: .init(id: "", displayName: "Alice"), - contentType: .location(.init(body: "", geoURI: nil)))) + contentType: .location(.init(body: "")))) } .environmentObject(viewModel.context) } diff --git a/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift b/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift index 6f3434054..d3dbfd250 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/Timeline/LocationRoomTimelineView.swift @@ -65,13 +65,14 @@ struct LocationRoomTimelineView_Previews: PreviewProvider { isOutgoing: false, isEditable: false, sender: .init(id: "Bob"), - content: .init(body: "Fallback geo uri description", geoURI: nil))) + content: .init(body: "Fallback geo uri description"))) LocationRoomTimelineView(timelineItem: .init(id: UUID().uuidString, timestamp: "Now", isOutgoing: false, isEditable: false, sender: .init(id: "Bob"), - content: .init(body: "Fallback geo uri description", geoURI: .init(latitude: 41.902782, longitude: 12.496366)))) + content: .init(body: "Fallback geo uri description", + geoURI: .init(latitude: 41.902782, longitude: 12.496366)))) } } diff --git a/ElementX/Sources/Services/Room/RoomProxy.swift b/ElementX/Sources/Services/Room/RoomProxy.swift index 8fda6f92c..8dace4ced 100644 --- a/ElementX/Sources/Services/Room/RoomProxy.swift +++ b/ElementX/Sources/Services/Room/RoomProxy.swift @@ -372,7 +372,11 @@ class RoomProxy: RoomProxyProtocol { return .success(()) } - func sendLocation(body: String, geoURI: GeoURI) async -> Result { + func sendLocation(body: String, + geoURI: GeoURI, + description: String?, + zoomLevel: UInt8?, + assetType: AssetType?) async -> Result { sendMessageBackgroundTask = backgroundTaskService.startBackgroundTask(withName: backgroundTaskName, isReusable: true) defer { sendMessageBackgroundTask?.stop() @@ -381,7 +385,12 @@ class RoomProxy: RoomProxyProtocol { let transactionId = genTransactionId() return await Task.dispatch(on: userInitiatedDispatchQueue) { - .success(self.room.sendLocation(body: body, geoUri: geoURI.string, txnId: transactionId)) + .success(self.room.sendLocation(body: body, + geoUri: geoURI.string, + description: description, + zoomLevel: zoomLevel, + assetType: assetType, + txnId: transactionId)) } } diff --git a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift index 8bbd637cd..d321e8baf 100644 --- a/ElementX/Sources/Services/Room/RoomProxyProtocol.swift +++ b/ElementX/Sources/Services/Room/RoomProxyProtocol.swift @@ -115,7 +115,11 @@ protocol RoomProxyProtocol { progressSubject: CurrentValueSubject?, requestHandle: (SendAttachmentJoinHandleProtocol) -> Void) async -> Result - func sendLocation(body: String, geoURI: GeoURI) async -> Result + func sendLocation(body: String, + geoURI: GeoURI, + description: String?, + zoomLevel: UInt8?, + assetType: AssetType?) async -> Result /// Retries sending a failed message given its transaction ID func retrySend(transactionID: String) async diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift index 52237f39c..2200716a2 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineController.swift @@ -118,7 +118,7 @@ class RoomTimelineController: RoomTimelineControllerProtocol { switch timelineItem { case let item as LocationRoomTimelineItem: guard let geoURI = item.content.geoURI else { return .none } - return .displayLocation(body: item.content.body, geoURI: geoURI) + return .displayLocation(body: item.content.body, geoURI: geoURI, description: item.content.description) default: return await displayMediaActionIfPossible(timelineItem: timelineItem) } diff --git a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift index 4bfefdd16..813471ea1 100644 --- a/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift +++ b/ElementX/Sources/Services/Timeline/TimelineController/RoomTimelineControllerProtocol.swift @@ -26,7 +26,7 @@ enum RoomTimelineControllerCallback { enum RoomTimelineControllerAction { case displayMediaFile(file: MediaFileHandleProxy, title: String?) - case displayLocation(body: String, geoURI: GeoURI) + case displayLocation(body: String, geoURI: GeoURI, description: String?) case none } diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/LocationRoomTimelineItemContent.swift b/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/LocationRoomTimelineItemContent.swift index 8c1e317e9..b46e31f3e 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/LocationRoomTimelineItemContent.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/LocationRoomTimelineItemContent.swift @@ -17,4 +17,24 @@ struct LocationRoomTimelineItemContent: Hashable { let body: String let geoURI: GeoURI? + let description: String? + let zoomLevel: UInt8? + let asset: AssetType? + + enum AssetType { + case sender + case pin + } + + init(body: String, + geoURI: GeoURI? = nil, + description: String? = nil, + zoomLevel: UInt8? = nil, + asset: AssetType? = nil) { + self.body = body + self.geoURI = geoURI + self.description = description + self.zoomLevel = zoomLevel + self.asset = asset + } } diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift index cc9c958f7..1a2b04933 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/RoomTimelineItemFactory.swift @@ -399,7 +399,11 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol { } private func buildLocationTimelineItemContent(_ locationContent: LocationContent) -> LocationRoomTimelineItemContent { - LocationRoomTimelineItemContent(body: locationContent.body, geoURI: .init(string: locationContent.geoUri)) + LocationRoomTimelineItemContent(body: locationContent.body, + geoURI: .init(string: locationContent.geoUri), + description: locationContent.description, + zoomLevel: locationContent.zoomLevel, + asset: locationContent.asset.map { .init(assetType: $0) }) } private func buildFileTimelineItemContent(_ messageContent: FileMessageContent) -> FileRoomTimelineItemContent { @@ -528,3 +532,14 @@ struct RoomTimelineItemFactory: RoomTimelineItemFactoryProtocol { } } } + +private extension LocationRoomTimelineItemContent.AssetType { + init(assetType: MatrixRustSDK.AssetType) { + switch assetType { + case .sender: + self = .sender + case .pin: + self = .pin + } + } +} diff --git a/project.yml b/project.yml index 191cff2c9..9f4e02c9c 100644 --- a/project.yml +++ b/project.yml @@ -44,7 +44,7 @@ include: packages: MatrixRustSDK: url: https://github.com/matrix-org/matrix-rust-components-swift - exactVersion: 1.0.93-alpha + exactVersion: 1.0.94-alpha # path: ../matrix-rust-sdk DesignKit: path: DesignKit