Skip to content

Commit

Permalink
element-hq/element-ios/issues/5298 - Added MXRoom location sharing me…
Browse files Browse the repository at this point in the history
…thod.
  • Loading branch information
stefanceriu committed Dec 16, 2021
1 parent 4e01e8d commit 3bd6cb3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions MatrixSDK/Data/MXRoom.h
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,15 @@ FOUNDATION_EXPORT NSInteger const kMXRoomAlreadyJoinedErrorCode;
success:(void (^)(NSString *eventId))success
failure:(void (^)(NSError *error))failure;

#pragma mark - Location sharing

- (MXHTTPOperation *)sendLocationWithLatitude:(double)latitude
longitude:(double)longitude
description:(NSString *)description
localEcho:(MXEvent **)localEcho
success:(void (^)(NSString *))success
failure:(void (^)(NSError *))failure;

#pragma mark - Events listeners on the live timeline
/**
Register a listener to events of the room live timeline.
Expand Down
36 changes: 36 additions & 0 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,42 @@ - (MXHTTPOperation *)sendPollEndForEvent:(MXEvent *)pollStartEvent
return [self sendEventOfType:[MXTools eventTypeString:MXEventTypePollEnd] content:content localEcho:localEcho success:success failure:failure];
}

#pragma mark - Location sharing

- (MXHTTPOperation *)sendLocationWithLatitude:(double)latitude
longitude:(double)longitude
description:(NSString *)description
localEcho:(MXEvent **)localEcho
success:(void (^)(NSString *))success
failure:(void (^)(NSError *))failure
{
NSMutableDictionary *content = [NSMutableDictionary dictionary];
content[kMXMessageTypeKey] = kMXMessageTypeLocation;

NSString *geoURI = [NSString stringWithFormat:@"geo:%@,%@", @(latitude), @(longitude)];

content[kMXMessageGeoURIKey] = geoURI;

content[kMXMessageContentKeyExtensibleLocation] = [NSMutableDictionary dictionary];
content[kMXMessageContentKeyExtensibleLocation][kMXMessageContentKeyExtensibleLocationURI] = geoURI;

if (description.length > 0) {
content[kMXMessageBodyKey] = description;
content[kMXMessageContentKeyExtensibleText] = description;
content[kMXMessageContentKeyExtensibleLocation][kMXMessageContentKeyExtensibleLocationDescription] = description;
} else {
NSString *fallbackText = [NSString stringWithFormat:@"%@ @ %@", self.mxSession.myUser.displayname, geoURI];

content[kMXMessageBodyKey] = fallbackText;
content[kMXMessageContentKeyExtensibleText] = fallbackText;
}

return [self sendMessageWithContent:content
localEcho:localEcho
success:success
failure:failure];
}

#pragma mark - Message order preserving
/**
Make sure that `block` will be called in the order expected by the end user.
Expand Down

0 comments on commit 3bd6cb3

Please sign in to comment.