Skip to content

Commit cd8840e

Browse files
Merge pull request #1428 from matrix-org/maximee/5858_pin_drop_sharing
[Location Sharing]: Pin drop location sharing
2 parents f1f7c6a + 6b27237 commit cd8840e

File tree

10 files changed

+86
-9
lines changed

10 files changed

+86
-9
lines changed

MatrixSDK.xcodeproj/project.pbxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@
13581358
B1E09A492398028D0057C069 /* MXSelfSignedHomeserverTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 32322A471E57264E005DD155 /* MXSelfSignedHomeserverTests.m */; };
13591359
B1F939F526289F2600D0E525 /* MXSpaceChildContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1F939F426289F2600D0E525 /* MXSpaceChildContentTests.swift */; };
13601360
B1F939F626289F2600D0E525 /* MXSpaceChildContentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1F939F426289F2600D0E525 /* MXSpaceChildContentTests.swift */; };
1361+
B2EC7E2327F483DB00F40C26 /* MXEventAssetTypeMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2EC7E2227F483DB00F40C26 /* MXEventAssetTypeMapper.swift */; };
1362+
B2EC7E2427F483DB00F40C26 /* MXEventAssetTypeMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2EC7E2227F483DB00F40C26 /* MXEventAssetTypeMapper.swift */; };
13611363
C60165381E3AA57900B92CFA /* MXSDKOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = F0C34CB91C18C80000C36F09 /* MXSDKOptions.h */; settings = {ATTRIBUTES = (Public, ); }; };
13621364
C602B58C1F2268F700B67D87 /* MXRoom.swift in Sources */ = {isa = PBXBuildFile; fileRef = C602B58B1F2268F700B67D87 /* MXRoom.swift */; };
13631365
C602B58E1F22A8D700B67D87 /* MXImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C602B58D1F22A8D700B67D87 /* MXImage.swift */; };
@@ -2483,6 +2485,7 @@
24832485
B1DDC9D52418098200D208E3 /* MXIncomingSASTransaction_Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MXIncomingSASTransaction_Private.h; sourceTree = "<group>"; };
24842486
B1E09A0E2397FA950057C069 /* MatrixSDKTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MatrixSDKTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
24852487
B1F939F426289F2600D0E525 /* MXSpaceChildContentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXSpaceChildContentTests.swift; sourceTree = "<group>"; };
2488+
B2EC7E2227F483DB00F40C26 /* MXEventAssetTypeMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MXEventAssetTypeMapper.swift; sourceTree = "<group>"; };
24862489
B57EF0A39A7649D55CA1208A /* libPods-MatrixSDK-MatrixSDK-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MatrixSDK-MatrixSDK-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
24872490
BD0431D223F108AED4C70A42 /* Pods-SDK-MatrixSDK-iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDK-MatrixSDK-iOS.debug.xcconfig"; path = "Target Support Files/Pods-SDK-MatrixSDK-iOS/Pods-SDK-MatrixSDK-iOS.debug.xcconfig"; sourceTree = "<group>"; };
24882491
BD96770F88F116285272DB47 /* Pods-MatrixSDKTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MatrixSDKTests.release.xcconfig"; path = "Target Support Files/Pods-MatrixSDKTests/Pods-MatrixSDKTests.release.xcconfig"; sourceTree = "<group>"; };
@@ -2931,7 +2934,6 @@
29312934
B146D46E21A5939000D8C2C6 /* Realm */,
29322935
32322A491E575F65005DD155 /* MXAllowedCertificates.h */,
29332936
32322A4A1E575F65005DD155 /* MXAllowedCertificates.m */,
2934-
ECE3DF9C270C660900FB4C96 /* MXMulticastDelegate.swift */,
29352937
C6FE1EEF1E65C4F7008587E4 /* MXAnalyticsDelegate.h */,
29362938
32B090E1261F709B002924AA /* MXAsyncTaskQueue.swift */,
29372939
32A9E8211EF4026E0081358A /* MXBackgroundModeHandler.h */,
@@ -2941,6 +2943,7 @@
29412943
B1798D0524091A0100308A8F /* MXBase64Tools.m */,
29422944
3283F7761EAF30F700C1688C /* MXBugReportRestClient.h */,
29432945
3283F7771EAF30F700C1688C /* MXBugReportRestClient.m */,
2946+
B2EC7E2227F483DB00F40C26 /* MXEventAssetTypeMapper.swift */,
29442947
322DB456212EB8E600F4EFE9 /* MXHTTPClient_Private.h */,
29452948
320DFDD719DD99B60068622A /* MXHTTPClient.h */,
29462949
320DFDD819DD99B60068622A /* MXHTTPClient.m */,
@@ -2955,6 +2958,7 @@
29552958
F03EF5021DF01596009DF592 /* MXLRUCache.h */,
29562959
F03EF5031DF01596009DF592 /* MXLRUCache.m */,
29572960
324676EB25C15F4600EA855B /* MXMemory.swift */,
2961+
ECE3DF9C270C660900FB4C96 /* MXMulticastDelegate.swift */,
29582962
32A9770221626E5C00919CC0 /* MXServerNotices.h */,
29592963
32A9770321626E5C00919CC0 /* MXServerNotices.m */,
29602964
32A9F8DC244720B10069C65B /* MXThrottler.h */,
@@ -6016,6 +6020,7 @@
60166020
3A59A49F25A7A16F00DDA1FC /* MXOlmOutboundGroupSession.m in Sources */,
60176021
B146D4F221A5AF7F00D8C2C6 /* MXRealmEventScanMapper.m in Sources */,
60186022
B11BD45A22CB58850064D8B0 /* MXReplyEventFormattedBodyParts.m in Sources */,
6023+
B2EC7E2327F483DB00F40C26 /* MXEventAssetTypeMapper.swift in Sources */,
60196024
32CE6FB91A409B1F00317F1E /* MXFileStoreMetaData.m in Sources */,
60206025
3264DB921CEC528D00B99881 /* MXAccountData.m in Sources */,
60216026
3229535325A5F7220012FCF0 /* MXBackgroundCryptoStore.m in Sources */,
@@ -6539,6 +6544,7 @@
65396544
B14EF2322397E90400758AF0 /* MXBugReportRestClient.m in Sources */,
65406545
B14EF2342397E90400758AF0 /* MXCallKitAdapter.m in Sources */,
65416546
327C3E4E23A39D91006183D1 /* MXAggregatedReferencesUpdater.m in Sources */,
6547+
B2EC7E2427F483DB00F40C26 /* MXEventAssetTypeMapper.swift in Sources */,
65426548
B14EF2352397E90400758AF0 /* MXRoomPowerLevels.swift in Sources */,
65436549
32AF9287240EA2430008A0FD /* MXSecretShareRequest.m in Sources */,
65446550
91CC0FCD26A033AE00C2A387 /* MXURLPreview.m in Sources */,

MatrixSDK/Data/MXRoom.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#import "MXCall.h"
4040
#import "MXEventTimeline.h"
4141
#import "MXEventsEnumerator.h"
42+
#import "MXEventContentLocation.h"
4243
#import "MXCryptoConstants.h"
4344
#import "MXSendReplyEventStringLocalizerProtocol.h"
4445

@@ -1026,6 +1027,7 @@ FOUNDATION_EXPORT NSInteger const kMXRoomInvalidInviteSenderErrorCode;
10261027
description:(NSString *)description
10271028
threadId:(NSString*)threadId
10281029
localEcho:(MXEvent **)localEcho
1030+
assetType:(MXEventAssetType)assetType
10291031
success:(void (^)(NSString *))success
10301032
failure:(void (^)(NSError *))failure;
10311033

MatrixSDK/Data/MXRoom.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,10 +2535,11 @@ - (MXHTTPOperation *)sendLocationWithLatitude:(double)latitude
25352535
description:(NSString *)description
25362536
threadId:(NSString*)threadId
25372537
localEcho:(MXEvent **)localEcho
2538+
assetType:(MXEventAssetType)assetType
25382539
success:(void (^)(NSString *))success
25392540
failure:(void (^)(NSError *))failure
25402541
{
2541-
MXEventContentLocation *locationContent = [[MXEventContentLocation alloc] initWithAssetType:MXEventAssetTypeUser
2542+
MXEventContentLocation *locationContent = [[MXEventContentLocation alloc] initWithAssetType:assetType
25422543
latitude:latitude
25432544
longitude:longitude
25442545
description:description];
@@ -2547,7 +2548,7 @@ - (MXHTTPOperation *)sendLocationWithLatitude:(double)latitude
25472548

25482549
[content addEntriesFromDictionary:locationContent.JSONDictionary];
25492550

2550-
NSString *fallbackText = [NSString stringWithFormat:@"%@ was at %@ as of %@", self.mxSession.myUser.displayname, locationContent.geoURI, NSDate.date];
2551+
NSString *fallbackText = [NSString stringWithFormat:@"Location was shared at %@ as of %@", locationContent.geoURI, NSDate.date];
25512552
content[kMXMessageBodyKey] = fallbackText;
25522553
content[kMXMessageContentKeyExtensibleTextMSC1767] = fallbackText;
25532554

MatrixSDK/JSONModels/Event/Content/MXEventContentLocation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
2323
typedef NS_ENUM(NSUInteger, MXEventAssetType)
2424
{
2525
MXEventAssetTypeUser,
26+
MXEventAssetTypePin,
2627
MXEventAssetTypeGeneric
2728
};
2829

MatrixSDK/JSONModels/Event/Content/MXEventContentLocation.m

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
#import "MXEventContentLocation.h"
1818
#import "MXEvent.h"
1919

20+
#import "MatrixSDKSwiftHeader.h"
21+
22+
@interface MXEventContentLocation()
23+
24+
@property (nonatomic) MXEventAssetTypeMapper *eventAssetTypeMapper;
25+
26+
@end
27+
2028
@implementation MXEventContentLocation
2129

2230
- (instancetype)initWithAssetType:(MXEventAssetType)assetType
@@ -31,6 +39,7 @@ - (instancetype)initWithAssetType:(MXEventAssetType)assetType
3139
_longitude = longitude;
3240
_locationDescription = description;
3341
_geoURI = [NSString stringWithFormat:@"geo:%@,%@", @(self.latitude), @(self.longitude)];
42+
_eventAssetTypeMapper = [[MXEventAssetTypeMapper alloc] init];
3443
}
3544

3645
return self;
@@ -40,7 +49,7 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
4049
{
4150
NSString *description;
4251
NSString *geoURIString;
43-
MXEventAssetType assetType = MXEventAssetTypeUser;
52+
MXEventAssetType assetType;
4453

4554
NSDictionary *locationDictionary = JSONDictionary[kMXMessageContentKeyExtensibleLocationMSC3488];
4655
if (locationDictionary == nil)
@@ -67,12 +76,12 @@ + (instancetype)modelFromJSON:(NSDictionary *)JSONDictionary
6776
{
6877
assetDictionary = JSONDictionary[kMXMessageContentKeyExtensibleAsset];
6978
}
70-
7179
if (assetDictionary)
7280
{
73-
if (![assetDictionary[kMXMessageContentKeyExtensibleAssetType] isEqualToString:kMXMessageContentKeyExtensibleAssetTypeUser]) {
74-
assetType = MXEventAssetTypeGeneric;
75-
}
81+
assetType = [[[MXEventAssetTypeMapper alloc] init] eventAssetTypeFrom:assetDictionary[kMXMessageContentKeyExtensibleAssetType]];
82+
} else {
83+
// Should behave like m.self if assetType is nil
84+
assetType = MXEventAssetTypeUser;
7685
}
7786

7887
NSString *locationString = [[geoURIString componentsSeparatedByString:@":"].lastObject componentsSeparatedByString:@";"].firstObject;
@@ -101,7 +110,7 @@ - (NSDictionary *)JSONDictionary
101110
locationContent[kMXMessageContentKeyExtensibleLocationDescription] = self.locationDescription;
102111
content[kMXMessageContentKeyExtensibleLocationMSC3488] = locationContent;
103112

104-
content[kMXMessageContentKeyExtensibleAssetMSC3488] = @{ kMXMessageContentKeyExtensibleAssetType: kMXMessageContentKeyExtensibleAssetTypeUser };
113+
content[kMXMessageContentKeyExtensibleAssetMSC3488] = @{ kMXMessageContentKeyExtensibleAssetType: [_eventAssetTypeMapper eventKeyFrom:self.assetType] };
105114

106115
content[kMXMessageTypeKey] = kMXMessageTypeLocation;
107116
content[kMXMessageGeoURIKey] = self.geoURI;

MatrixSDK/JSONModels/MXEvent.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensibleAsset;
281281
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensibleAssetMSC3488;
282282
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensibleAssetType;
283283
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensibleAssetTypeUser;
284+
FOUNDATION_EXPORT NSString *const kMXMessageContentKeyExtensibleAssetTypePin;
284285

285286
// Join Rules
286287

MatrixSDK/JSONModels/MXEvent.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
NSString *const kMXMessageContentKeyExtensibleAssetMSC3488 = @"org.matrix.msc3488.asset";
190190
NSString *const kMXMessageContentKeyExtensibleAssetType = @"type";
191191
NSString *const kMXMessageContentKeyExtensibleAssetTypeUser = @"m.self";
192+
NSString *const kMXMessageContentKeyExtensibleAssetTypePin = @"m.pin";
192193

193194
// Join Rules
194195

MatrixSDK/MatrixSDK.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ FOUNDATION_EXPORT NSString *MatrixSDKVersion;
105105
#import "MXEventReplace.h"
106106
#import "MXInReplyTo.h"
107107
#import "MXEventRelationThread.h"
108+
#import "MXEventContentLocation.h"
108109

109110
#import "MXReplyEventParser.h"
110111

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Copyright 2022 The Matrix.org Foundation C.I.C
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
import Foundation
18+
19+
/// MXEventAssetTypeMapper enables to get the corresponding MXEventAssetType from event key String and the other way around.
20+
@objcMembers
21+
public class MXEventAssetTypeMapper: NSObject {
22+
23+
// MARK: - Public
24+
25+
/// Return event key String associate to the MXEventAssetType given
26+
public func eventKey(from eventAssetType: MXEventAssetType) -> String {
27+
let eventKey: String
28+
switch eventAssetType {
29+
case .user:
30+
eventKey = kMXMessageContentKeyExtensibleAssetTypeUser
31+
case .pin:
32+
eventKey = kMXMessageContentKeyExtensibleAssetTypePin
33+
case .generic:
34+
eventKey = ""
35+
@unknown default:
36+
eventKey = ""
37+
}
38+
return eventKey
39+
}
40+
41+
/// Return MXEventAssetType associate to the event key String given
42+
public func eventAssetType(from eventKey: String) -> MXEventAssetType {
43+
let eventAssetType: MXEventAssetType
44+
switch eventKey {
45+
case kMXMessageContentKeyExtensibleAssetTypeUser:
46+
eventAssetType = .user
47+
case kMXMessageContentKeyExtensibleAssetTypePin:
48+
eventAssetType = .pin
49+
default:
50+
eventAssetType = .generic
51+
}
52+
return eventAssetType
53+
}
54+
}

changelog.d/5858.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Location sharing: Add new event asset type for pin drop location sharing

0 commit comments

Comments
 (0)