Skip to content

Commit

Permalink
/issues/5298 - Added body message content keys and replaced plain str…
Browse files Browse the repository at this point in the history
…ing usages.
  • Loading branch information
stefanceriu committed Dec 13, 2021
1 parent 372e97e commit 228600d
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ - (instancetype)initWithSearchResult:(MXSearchResult *)searchResult2 andSearchDa
roomId = event.roomId;

// Title is here the file name stored in event body
title = [event.content[@"body"] isKindOfClass:[NSString class]] ? event.content[@"body"] : nil;
title = [event.content[kMXMessageBodyKey] isKindOfClass:[NSString class]] ? event.content[kMXMessageBodyKey] : nil;

// Check attachment if any
if ([searchDataSource.eventFormatter isSupportedAttachment:event])
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/MatrixKit/Controllers/MXKRoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ - (void)promptUserToResendEvent:(NSString *)eventId
NSString* textMessage;
if ([msgtype isEqualToString:kMXMessageTypeText])
{
textMessage = event.content[@"body"];
textMessage = event.content[kMXMessageBodyKey];
}

// Show a confirmation popup to the end user
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/MatrixKit/Models/Room/MXKAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ - (instancetype)initWithEvent:(MXEvent*)event andMediaManager:(MXMediaManager*)m
}
}

MXJSONModelSetString(_originalFileName, eventContent[@"body"]);
MXJSONModelSetString(_originalFileName, eventContent[kMXMessageBodyKey]);
MXJSONModelSetDictionary(_contentInfo, eventContent[@"info"]);
MXJSONModelSetMXJSONModel(contentFile, MXEncryptedContentFile, eventContent[@"file"]);

Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -3992,7 +3992,7 @@ - (NSString*)editableTextMessageForEvent:(MXEvent*)event
}
else
{
editableTextMessage = event.content[@"body"];
editableTextMessage = event.content[kMXMessageBodyKey];
}

return editableTextMessage;
Expand Down Expand Up @@ -4109,7 +4109,7 @@ - (void)replaceTextMessageForEventWithId:(NSString*)eventId
NSString *sanitizedText = [self sanitizedMessageText:text];
NSString *formattedText = [self htmlMessageFromSanitizedText:sanitizedText];

NSString *eventBody = event.content[@"body"];
NSString *eventBody = event.content[kMXMessageBodyKey];
NSString *eventFormattedBody = event.content[@"formatted_body"];

if (![sanitizedText isEqualToString:eventBody] && (!eventFormattedBody || ![formattedText isEqualToString:eventFormattedBody]))
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/MatrixKit/Models/Search/MXKSearchCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ - (instancetype)initWithSearchResult:(MXSearchResult *)searchResult2 andSearchDa
date = [searchDataSource.eventFormatter dateStringFromEvent:searchResult.result withTime:YES];

// Code from [MXEventFormatter stringFromEvent] for the particular case of a text message
message = [searchResult.result.content[@"body"] isKindOfClass:[NSString class]] ? searchResult.result.content[@"body"] : nil;
message = [searchResult.result.content[kMXMessageBodyKey] isKindOfClass:[NSString class]] ? searchResult.result.content[kMXMessageBodyKey] : nil;
}
return self;
}
Expand Down
12 changes: 6 additions & 6 deletions Riot/Modules/MatrixKit/Utils/EventFormatter/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ - (BOOL)isSupportedAttachment:(MXEvent*)event
if (event.eventType == MXEventTypeRoomMessage)
{
NSString *msgtype;
MXJSONModelSetString(msgtype, event.content[kMXMessageTypeKey]);
MXJSONModelSetString(msgtype, event.content[@"msgtype"]);

NSString *urlField;
NSDictionary *fileField;
Expand Down Expand Up @@ -1263,12 +1263,12 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
else if (eventThreadIdentifier)
{
isHTML = YES;
MXJSONModelSetString(body, event.content[@"body"]);
MXJSONModelSetString(body, event.content[kMXMessageBodyKey]);
MXEvent *threadRootEvent = [mxSession.store eventWithEventId:eventThreadIdentifier
inRoom:event.roomId];

NSString *threadRootEventContent;
MXJSONModelSetString(threadRootEventContent, threadRootEvent.content[@"body"]);
MXJSONModelSetString(threadRootEventContent, threadRootEvent.content[kMXMessageBodyKey]);
body = [NSString stringWithFormat:@"<mx-reply><blockquote><a href=\"%@\">In reply to</a> <a href=\"%@\">%@</a><br>%@</blockquote></mx-reply>%@",
[MXTools permalinkToEvent:eventThreadIdentifier inRoom:event.roomId],
[MXTools permalinkToUserWithUserId:threadRootEvent.sender],
Expand All @@ -1279,7 +1279,7 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
}
else
{
MXJSONModelSetString(body, event.content[@"body"]);
MXJSONModelSetString(body, event.content[kMXMessageBodyKey]);
}

if (body)
Expand Down Expand Up @@ -1561,7 +1561,7 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
else
{
NSString *body;
MXJSONModelSetString(body, event.content[@"body"]);
MXJSONModelSetString(body, event.content[kMXMessageBodyKey]);

// Check sticker validity
if (![self isSupportedAttachment:event])
Expand Down Expand Up @@ -2100,7 +2100,7 @@ - (UIFont*)fontForEvent:(MXEvent*)event
else if (!_isForSubtitle && event.eventType == MXEventTypeRoomMessage && (_emojiOnlyTextFont || _singleEmojiTextFont))
{
NSString *message;
MXJSONModelSetString(message, event.content[@"body"]);
MXJSONModelSetString(message, event.content[kMXMessageBodyKey]);

if (_emojiOnlyTextFont && [MXKTools isEmojiOnlyString:message])
{
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Room/CellData/RoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ - (NSString *)accessibilityLabel
{
NSString *mediaName = [self accessibilityLabelForAttachmentType:self.attachment.type];

MXJSONModelSetString(accessibilityLabel, self.events.firstObject.content[@"body"]);
MXJSONModelSetString(accessibilityLabel, self.events.firstObject.content[kMXMessageBodyKey]);
if (accessibilityLabel)
{
accessibilityLabel = [NSString stringWithFormat:@"%@ %@", mediaName, accessibilityLabel];
Expand Down
2 changes: 1 addition & 1 deletion RiotNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class NotificationService: UNNotificationServiceExtension {
}

let msgType = event.content[kMXMessageTypeKey] as? String
let messageContent = event.content["body"] as? String
let messageContent = event.content[kMXMessageBodyKey] as? String
let isReply = event.isReply()

if isReply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class TemplateRoomChatService: TemplateRoomChatServiceProtocol {
})
.compactMap({ event -> TemplateRoomChatMessage? in
guard let eventId = event.eventId,
let body = event.content["body"] as? String,
let body = event.content[kMXMessageBodyKey] as? String,
let sender = senderForMessage(event: event)
else { return nil }

Expand Down
2 changes: 1 addition & 1 deletion RiotTests/MatrixKitTests/MXKEventFormatterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ - (void)setUp
anEvent.wireType = kMXEventTypeStringRoomMessage;
anEvent.originServerTs = (uint64_t) ([[NSDate date] timeIntervalSince1970] * 1000);
anEvent.wireContent = @{ kMXMessageTypeKey: kMXMessageTypeText,
@"body": @"deded" };
kMXMessageBodyKey: @"deded" };

maxHeaderSize = ceil(eventFormatter.defaultTextFont.pointSize * 1.2);
}
Expand Down

0 comments on commit 228600d

Please sign in to comment.