Skip to content

Commit

Permalink
Merge pull request #1525 from matrix-org/steve/6423_lls_reply
Browse files Browse the repository at this point in the history
MXRoom: Support reply to beacon info event (PSG-4)
  • Loading branch information
SBiOSoftWhare committed Jul 13, 2022
2 parents 2c0830c + 65ba5b1 commit a0616be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
59 changes: 26 additions & 33 deletions MatrixSDK/Data/MXRoom.m
Original file line number Diff line number Diff line change
Expand Up @@ -2158,45 +2158,32 @@ - (void)getReplyContentBodiesWithEventToReply:(MXEvent*)eventToReply
replyContentFormattedBody:(NSString**)replyContentFormattedBody
stringLocalizer:(id<MXSendReplyEventStringLocalizerProtocol>)stringLocalizer
{
if (eventToReply.eventType == MXEventTypePollStart)
{
NSString *question = [MXEventContentPollStart modelFromJSON:eventToReply.content].question;

*replyContentBody = [self replyMessageBodyFromSender:eventToReply.sender
senderMessageBody:question
isSenderMessageAnEmote:NO
isSenderMessageAReplyTo:eventToReply.isReplyEvent
replyMessage:textMessage];

// As formatted body is mandatory for a reply message, use non formatted to build it
NSString *finalFormattedTextMessage = formattedTextMessage ?: textMessage;

*replyContentFormattedBody = [self replyMessageFormattedBodyFromEventToReply:eventToReply
senderMessageFormattedBody:question
isSenderMessageAnEmote:NO
replyFormattedMessage:finalFormattedTextMessage
stringLocalizer:stringLocalizer];
return;
}

NSString *msgtype;
MXJSONModelSetString(msgtype, eventToReply.content[kMXMessageTypeKey]);

if (!msgtype)
{
return;
}

BOOL eventToReplyIsAlreadyAReply = eventToReply.isReplyEvent;
BOOL isSenderMessageAnEmote = [msgtype isEqualToString:kMXMessageTypeEmote];

NSString *senderMessageBody;
NSString *senderMessageFormattedBody;

if (eventToReply.location)
if (eventToReply.eventType == MXEventTypePollStart)
{
NSString *question = [MXEventContentPollStart modelFromJSON:eventToReply.content].question;

senderMessageBody = question;
}
else if (eventToReply.eventType == MXEventTypeBeaconInfo)
{
senderMessageBody = stringLocalizer.senderSentTheirLiveLocation;
}
else if (eventToReply.location)
{
senderMessageBody = stringLocalizer.senderSentTheirLocation;
senderMessageFormattedBody = senderMessageBody;
}
else if (eventToReply.eventType == MXEventTypeBeaconInfo)
{
senderMessageBody = stringLocalizer.senderSentTheirLiveLocation;
}
else if ([msgtype isEqualToString:kMXMessageTypeText]
|| [msgtype isEqualToString:kMXMessageTypeNotice]
Expand All @@ -2217,34 +2204,35 @@ - (void)getReplyContentBodiesWithEventToReply:(MXEvent*)eventToReply
else if ([msgtype isEqualToString:kMXMessageTypeImage])
{
senderMessageBody = stringLocalizer.senderSentAnImage;
senderMessageFormattedBody = senderMessageBody;
}
else if ([msgtype isEqualToString:kMXMessageTypeVideo])
{
senderMessageBody = stringLocalizer.senderSentAVideo;
senderMessageFormattedBody = senderMessageBody;
}
else if (eventToReply.isVoiceMessage)
{
senderMessageBody = stringLocalizer.senderSentAVoiceMessage;
senderMessageFormattedBody = senderMessageBody;
}
else if ([msgtype isEqualToString:kMXMessageTypeAudio])
{
senderMessageBody = stringLocalizer.senderSentAnAudioFile;
senderMessageFormattedBody = senderMessageBody;
}
else if ([msgtype isEqualToString:kMXMessageTypeFile])
{
senderMessageBody = stringLocalizer.senderSentAFile;
senderMessageFormattedBody = senderMessageBody;
}
else
{
// Other message types are not supported
MXLogDebug(@"[MXRoom] Reply to message type %@ is not supported", msgtype);
}

if (!senderMessageFormattedBody)
{
// As formatted body is mandatory for a reply message, if no formatted body has been defined use non formatted body
senderMessageFormattedBody = senderMessageBody;
}

if (senderMessageBody && senderMessageFormattedBody)
{
*replyContentBody = [self replyMessageBodyFromSender:eventToReply.sender
Expand Down Expand Up @@ -2435,6 +2423,11 @@ - (BOOL)canReplyToEvent:(MXEvent *)eventToReply
return YES;
}

if(eventToReply.eventType == MXEventTypeBeaconInfo)
{
return YES;
}

if (eventToReply.eventType != MXEventTypeRoomMessage)
{
return NO;
Expand Down
2 changes: 2 additions & 0 deletions MatrixSDK/Data/MXSendReplyEventDefaultStringLocalizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ @interface MXSendReplyEventDefaultStringLocalizer ()
@property (nonatomic, strong) NSString *senderSentAVoiceMessage;
@property (nonatomic, strong) NSString *senderSentAFile;
@property (nonatomic, strong) NSString *senderSentTheirLocation;
@property (nonatomic, strong) NSString *senderSentTheirLiveLocation;
@property (nonatomic, strong) NSString *messageToReplyToPrefix;

@end
Expand All @@ -40,6 +41,7 @@ - (instancetype)init
_senderSentAVoiceMessage = @"sent a voice message.";
_senderSentAFile = @"sent a file.";
_senderSentTheirLocation = @"has shared their location.";
_senderSentTheirLiveLocation = @"Live location.";
_messageToReplyToPrefix = @"In reply to";
}
return self;
Expand Down
1 change: 1 addition & 0 deletions MatrixSDK/Data/MXSendReplyEventStringLocalizerProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
- (NSString *)senderSentAVoiceMessage;
- (NSString *)senderSentAFile;
- (NSString *)senderSentTheirLocation;
- (NSString *)senderSentTheirLiveLocation;
- (NSString *)messageToReplyToPrefix;

@end
Expand Down
1 change: 1 addition & 0 deletions changelog.d/6423.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MXRoom: Support reply to beacon info event.

0 comments on commit a0616be

Please sign in to comment.