Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Render sticker events in the timeline
Browse files Browse the repository at this point in the history
- useMXJSONModelSetXxx helpers to avoid crash because of malformed content.

element-hq/element-ios#1819
  • Loading branch information
giomfo committed Apr 3, 2018
1 parent 0bf99a0 commit b9b0843
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
21 changes: 9 additions & 12 deletions MatrixKit/Models/Room/MXKAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ - (instancetype)initWithEvent:(MXEvent *)mxEvent andMatrixSession:(MXSession*)mx
if (mxEvent.eventType == MXEventTypeSticker)
{
_type = MXKAttachmentTypeSticker;
_thumbnailInfo = eventContent[@"info"][@"thumbnail_info"];
MXJSONModelSetDictionary(_thumbnailInfo, eventContent[@"info"][@"thumbnail_info"]);
}
else
{
Expand All @@ -101,7 +101,7 @@ - (instancetype)initWithEvent:(MXEvent *)mxEvent andMatrixSession:(MXSession*)mx
else if ([msgtype isEqualToString:kMXMessageTypeVideo])
{
_type = MXKAttachmentTypeVideo;
_thumbnailInfo = eventContent[@"info"][@"thumbnail_info"];
MXJSONModelSetDictionary(_thumbnailInfo, eventContent[@"info"][@"thumbnail_info"]);
}
else if ([msgtype isEqualToString:kMXMessageTypeLocation])
{
Expand All @@ -119,24 +119,21 @@ - (instancetype)initWithEvent:(MXEvent *)mxEvent andMatrixSession:(MXSession*)mx
}
}

_originalFileName = [eventContent[@"body"] isKindOfClass:[NSString class]] ? eventContent[@"body"] : nil;

_contentInfo = eventContent[@"info"];

thumbnailFile = _contentInfo[@"thumbnail_file"];

contentFile = eventContent[@"file"];
MXJSONModelSetString(_originalFileName, eventContent[@"body"]);
MXJSONModelSetDictionary(_contentInfo, eventContent[@"info"]);
MXJSONModelSetDictionary(thumbnailFile, _contentInfo[@"thumbnail_file"]);
MXJSONModelSetDictionary(contentFile, eventContent[@"file"]);

// Retrieve the content url by taking into account the potential encryption.
if (contentFile)
{
_isEncrypted = YES;
_contentURL = contentFile[@"url"];
MXJSONModelSetString(_contentURL, contentFile[@"url"]);
}
else
{
_isEncrypted = NO;
_contentURL = eventContent[@"url"];
MXJSONModelSetString(_contentURL, eventContent[@"url"]);
}

// Note: When the attachment uploading is in progress, the upload id is stored in the content url (nasty trick).
Expand All @@ -155,7 +152,7 @@ - (instancetype)initWithEvent:(MXEvent *)mxEvent andMatrixSession:(MXSession*)mx
NSString *mimetype = nil;
if (_contentInfo)
{
mimetype = _contentInfo[@"mimetype"];
MXJSONModelSetString(mimetype, _contentInfo[@"mimetype"]);
}

_cacheFilePath = [MXMediaManager cachePathForMediaWithURL:_actualURL andType:mimetype inFolder:_eventRoomId];
Expand Down
15 changes: 6 additions & 9 deletions MatrixKit/Utils/MXKEventFormatter.m
Original file line number Diff line number Diff line change
Expand Up @@ -850,15 +850,14 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
BOOL isHTML = NO;

// Use the HTML formatted string if provided
if ([event.content[@"format"] isEqualToString:kMXRoomMessageFormatHTML]
&& [event.content[@"formatted_body"] isKindOfClass:[NSString class]])
if ([event.content[@"format"] isEqualToString:kMXRoomMessageFormatHTML])
{
isHTML =YES;
body = event.content[@"formatted_body"];
MXJSONModelSetString(body, event.content[@"formatted_body"]);
}
else if ([event.content[@"body"] isKindOfClass:[NSString class]])
else
{
body = event.content[@"body"];
MXJSONModelSetString(body, event.content[@"body"]);
}

if (body)
Expand Down Expand Up @@ -1024,10 +1023,8 @@ - (NSAttributedString *)attributedStringFromEvent:(MXEvent *)event withRoomState
case MXEventTypeSticker:
{
NSString *body;
if ([event.content[@"body"] isKindOfClass:[NSString class]])
{
body = event.content[@"body"];
}
MXJSONModelSetString(body, event.content[@"body"]);

// Check sticker validity
if (![self isSupportedAttachment:event])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ extern NSString *const kMXKRoomBubbleCellUrl;
/**
Method used during [MXKCellRendering render:] to check the provided `cellData`
and prepare the protected `bubbleData`.
Do not be overridden by a class child.
Do not override it.
@param cellData the data object to render.
*/
Expand Down

0 comments on commit b9b0843

Please sign in to comment.