Skip to content

Commit

Permalink
/issues/5298 - Replaced "msgtype" strings with new kMXMessageTypeKey.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Dec 16, 2021
1 parent bb2c332 commit c4ddb82
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ - (UIImage*)attachmentIcon
{
MXEvent *event = searchResult.result;
NSString *msgtype;
MXJSONModelSetString(msgtype, event.content[@"msgtype"]);
MXJSONModelSetString(msgtype, event.content[kMXMessageTypeKey]);

if ([msgtype isEqualToString:kMXMessageTypeImage])
{
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 @@ -2179,7 +2179,7 @@ - (void)promptUserToResendEvent:(NSString *)eventId

if (event && event.eventType == MXEventTypeRoomMessage)
{
NSString *msgtype = event.content[@"msgtype"];
NSString *msgtype = event.content[kMXMessageTypeKey];

NSString* textMessage;
if ([msgtype isEqualToString:kMXMessageTypeText])
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 @@ -91,7 +91,7 @@ - (instancetype)initWithEvent:(MXEvent*)event andMediaManager:(MXMediaManager*)m
else
{
// Note: mxEvent.eventType is supposed to be MXEventTypeRoomMessage here.
NSString *msgtype = eventContent[@"msgtype"];
NSString *msgtype = eventContent[kMXMessageTypeKey];
if ([msgtype isEqualToString:kMXMessageTypeImage])
{
_type = MXKAttachmentTypeImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ - (void)updateLinkWithRoomState:(MXRoomState*)roomState
return;
}

NSString *messageType = self.event.content[@"msgtype"];
NSString *messageType = self.event.content[kMXMessageTypeKey];

if (!messageType || !([messageType isEqualToString:kMXMessageTypeText] || [messageType isEqualToString:kMXMessageTypeNotice] || [messageType isEqualToString:kMXMessageTypeEmote]))
{
Expand Down
8 changes: 4 additions & 4 deletions Riot/Modules/MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ - (void)resendEventWithEventId:(NSString *)eventId success:(void (^)(NSString *)
else if ([event.type isEqualToString:kMXEventTypeStringRoomMessage])
{
// And retry the send the message according to its type
NSString *msgType = event.content[@"msgtype"];
NSString *msgType = event.content[kMXMessageTypeKey];
if ([msgType isEqualToString:kMXMessageTypeText] || [msgType isEqualToString:kMXMessageTypeEmote])
{
// Resend the Matrix event by reusing the existing echo
Expand Down Expand Up @@ -2712,7 +2712,7 @@ - (BOOL)canPerformActionOnEvent:(MXEvent*)event
return NO;
}

NSString *messageType = event.content[@"msgtype"];
NSString *messageType = event.content[kMXMessageTypeKey];
if (messageType == nil || [messageType isEqualToString:@"m.bad.encrypted"]) {
return NO;
}
Expand Down Expand Up @@ -3928,7 +3928,7 @@ - (BOOL)canReactToEventWithId:(NSString*)eventId

if ([self canPerformActionOnEvent:event])
{
NSString *messageType = event.content[@"msgtype"];
NSString *messageType = event.content[kMXMessageTypeKey];

if ([messageType isEqualToString:kMXMessageTypeKeyVerificationRequest])
{
Expand Down Expand Up @@ -3971,7 +3971,7 @@ - (BOOL)canEditEventWithId:(NSString*)eventId
{
MXEvent *event = [self eventWithEventId:eventId];
BOOL isRoomMessage = event.eventType == MXEventTypeRoomMessage;
NSString *messageType = event.content[@"msgtype"];
NSString *messageType = event.content[kMXMessageTypeKey];

return isRoomMessage
&& ([messageType isEqualToString:kMXMessageTypeText] || [messageType isEqualToString:kMXMessageTypeEmote])
Expand Down
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[@"msgtype"]);
MXJSONModelSetString(msgtype, event.content[kMXMessageTypeKey]);

NSString *urlField;
NSDictionary *fileField;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
else
{
NSString *msgtype;
MXJSONModelSetString(msgtype, event.content[@"msgtype"]);
MXJSONModelSetString(msgtype, event.content[kMXMessageTypeKey]);

NSString *body;
BOOL isHTML = NO;
Expand Down Expand Up @@ -1979,7 +1979,7 @@ - (BOOL)session:(MXSession *)session updateRoomSummary:(MXRoomSummary *)summary

if (event.eventType == MXEventTypeRoomMessage)
{
NSString *msgtype = event.content[@"msgtype"];
NSString *msgtype = event.content[kMXMessageTypeKey];
if ([msgtype isEqualToString:kMXMessageTypeEmote] == NO)
{
NSString *senderDisplayName = [self senderDisplayNameForEvent:event withRoomState:roomState];
Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/Room/CellData/RoomBubbleCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ - (BOOL)addEvent:(MXEvent*)event andRoomState:(MXRoomState*)roomState
break;
}

NSString *messageType = event.content[@"msgtype"];
NSString *messageType = event.content[kMXMessageTypeKey];

if ([messageType isEqualToString:kMXMessageTypeKeyVerificationRequest])
{
Expand Down Expand Up @@ -1013,7 +1013,7 @@ - (void)keyVerificationDidUpdate
break;
case MXEventTypeRoomMessage:
{
NSString *msgType = event.content[@"msgtype"];
NSString *msgType = event.content[kMXMessageTypeKey];

if ([msgType isEqualToString:kMXMessageTypeKeyVerificationRequest])
{
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Room/DataSources/RoomDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ - (BOOL)shouldFetchKeyVerificationForEvent:(MXEvent*)event
break;
case MXEventTypeRoomMessage:
{
NSString *msgType = event.content[@"msgtype"];
NSString *msgType = event.content[kMXMessageTypeKey];

if ([msgType isEqualToString:kMXMessageTypeKeyVerificationRequest])
{
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -6115,7 +6115,7 @@ - (RoomContextualMenuItem *)copyMenuItemWithEvent:(MXEvent*)event andCell:(id<MX
switch (event.eventType) {
case MXEventTypeRoomMessage:
{
NSString *messageType = event.content[@"msgtype"];
NSString *messageType = event.content[kMXMessageTypeKey];

if ([messageType isEqualToString:kMXMessageTypeKeyVerificationRequest])
{
Expand Down
2 changes: 1 addition & 1 deletion RiotNSE/NotificationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class NotificationService: UNNotificationServiceExtension {
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class TemplateRoomChatService: TemplateRoomChatServiceProtocol {
return events
.filter({ event in
event.type == kMXEventTypeStringRoomMessage
&& event.content["msgtype"] as? String == kMXMessageTypeText
&& event.content[kMXMessageTypeKey] as? String == kMXMessageTypeText

// TODO: New to our SwiftUI Template? Why not implement another message type like image?

Expand Down
6 changes: 2 additions & 4 deletions RiotTests/MatrixKitTests/MXKEventFormatterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ - (void)setUp
anEvent.eventId = @"anEventId";
anEvent.wireType = kMXEventTypeStringRoomMessage;
anEvent.originServerTs = (uint64_t) ([[NSDate date] timeIntervalSince1970] * 1000);
anEvent.wireContent = @{
@"msgtype": kMXMessageTypeText,
@"body": @"deded",
};
anEvent.wireContent = @{ kMXMessageTypeKey: kMXMessageTypeText,
@"body": @"deded" };

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

0 comments on commit c4ddb82

Please sign in to comment.