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
MXKAttachment: support the new `m.sticker` event type

element-hq/element-ios#1819
  • Loading branch information
giomfo committed Mar 30, 2018
1 parent b9a1d49 commit 9f67404
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 83 deletions.
3 changes: 2 additions & 1 deletion MatrixKit/Controllers/MXKAttachmentsViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -655,7 +656,7 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
UIImage* preview = [attachment getCachedThumbnail];

// Check attachment type
if (attachment.type == MXKAttachmentTypeImage && attachmentURL.length)
if ((attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeSticker) && attachmentURL.length)
{
if ([mimeType isEqualToString:@"image/gif"])
{
Expand Down
104 changes: 54 additions & 50 deletions MatrixKit/Controllers/MXKRoomViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2872,67 +2873,70 @@ - (void)dataSource:(MXKDataSource *)dataSource didRecognizeAction:(NSString *)ac
}]];
}

[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"copy"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

typeof(self) self = weakSelf;
self->currentAlert = nil;

[self startActivityIndicator];

[attachment copy:^{
if (attachment.type != MXKAttachmentTypeSticker)
{
[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"copy"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

typeof(self) self = weakSelf;
[self stopActivityIndicator];
self->currentAlert = nil;

} failure:^(NSError *error) {
[self startActivityIndicator];

typeof(self) self = weakSelf;
[self stopActivityIndicator];
[attachment copy:^{

typeof(self) self = weakSelf;
[self stopActivityIndicator];

} failure:^(NSError *error) {

typeof(self) self = weakSelf;
[self stopActivityIndicator];

// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];

}];

// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
// Start animation in case of download during attachment preparing
[roomBubbleTableViewCell startProgressUI];

}];

// Start animation in case of download during attachment preparing
[roomBubbleTableViewCell startProgressUI];

}]];

[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"share"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

typeof(self) self = weakSelf;
self->currentAlert = nil;

[attachment prepareShare:^(NSURL *fileURL) {
}]];

[currentAlert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"share"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

typeof(self) self = weakSelf;
self->documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[self->documentInteractionController setDelegate:self];
self->currentSharedAttachment = attachment;

if (![self->documentInteractionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES])
{
self->documentInteractionController = nil;
[attachment onShareEnded];
self->currentSharedAttachment = nil;
}
self->currentAlert = nil;

} failure:^(NSError *error) {
[attachment prepareShare:^(NSURL *fileURL) {

typeof(self) self = weakSelf;
self->documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[self->documentInteractionController setDelegate:self];
self->currentSharedAttachment = attachment;

if (![self->documentInteractionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES])
{
self->documentInteractionController = nil;
[attachment onShareEnded];
self->currentSharedAttachment = nil;
}

} failure:^(NSError *error) {

// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];

}];

// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
// Start animation in case of download during attachment preparing
[roomBubbleTableViewCell startProgressUI];

}];

// Start animation in case of download during attachment preparing
[roomBubbleTableViewCell startProgressUI];

}]];
}]];
}

// Check status of the selected event
if (selectedEvent.sentState == MXEventSentStatePreparing ||
Expand Down
1 change: 1 addition & 0 deletions MatrixKit/Models/MXKAppSettings.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
4 changes: 3 additions & 1 deletion MatrixKit/Models/Room/MXKAttachment.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +29,8 @@ typedef enum : NSUInteger {
MXKAttachmentTypeAudio,
MXKAttachmentTypeVideo,
MXKAttachmentTypeLocation,
MXKAttachmentTypeFile
MXKAttachmentTypeFile,
MXKAttachmentTypeSticker

} MXKAttachmentType;

Expand Down
65 changes: 37 additions & 28 deletions MatrixKit/Models/Room/MXKAttachment.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,34 +81,42 @@ - (instancetype)initWithEvent:(MXEvent *)mxEvent andMatrixSession:(MXSession*)mx
// Set default thumbnail orientation
_thumbnailOrientation = UIImageOrientationUp;

NSString *msgtype = eventContent[@"msgtype"];
if ([msgtype isEqualToString:kMXMessageTypeImage])
if (mxEvent.eventType == MXEventTypeSticker)
{
_type = MXKAttachmentTypeImage;
}
else if ([msgtype isEqualToString:kMXMessageTypeAudio])
{
_type = MXKAttachmentTypeAudio;
}
else if ([msgtype isEqualToString:kMXMessageTypeVideo])
{
_type = MXKAttachmentTypeVideo;

_type = MXKAttachmentTypeSticker;
_thumbnailInfo = eventContent[@"info"][@"thumbnail_info"];
}
else if ([msgtype isEqualToString:kMXMessageTypeLocation])
{
// Not supported yet
// _type = MXKAttachmentTypeLocation;
return nil;
}
else if ([msgtype isEqualToString:kMXMessageTypeFile])
{
_type = MXKAttachmentTypeFile;
}
else
{
return nil;
// Note: mxEvent.eventType is supposed to be MXEventTypeRoomMessage here.
NSString *msgtype = eventContent[@"msgtype"];
if ([msgtype isEqualToString:kMXMessageTypeImage])
{
_type = MXKAttachmentTypeImage;
}
else if ([msgtype isEqualToString:kMXMessageTypeAudio])
{
_type = MXKAttachmentTypeAudio;
}
else if ([msgtype isEqualToString:kMXMessageTypeVideo])
{
_type = MXKAttachmentTypeVideo;
_thumbnailInfo = eventContent[@"info"][@"thumbnail_info"];
}
else if ([msgtype isEqualToString:kMXMessageTypeLocation])
{
// Not supported yet
// _type = MXKAttachmentTypeLocation;
return nil;
}
else if ([msgtype isEqualToString:kMXMessageTypeFile])
{
_type = MXKAttachmentTypeFile;
}
else
{
return nil;
}
}

_originalFileName = [eventContent[@"body"] isKindOfClass:[NSString class]] ? eventContent[@"body"] : nil;
Expand Down Expand Up @@ -204,21 +213,21 @@ - (NSString *)getThumbnailUrlForSize:(CGSize)size
return thumbnailFile[@"url"];
}

if (_type == MXKAttachmentTypeVideo)
if (_type == MXKAttachmentTypeVideo || _type == MXKAttachmentTypeSticker)
{
if (_contentInfo)
{
// Look for a clear video thumbnail url
NSString *unencrypted_video_thumb_url = _contentInfo[@"thumbnail_url"];
NSString *unencrypted_thumb_url = _contentInfo[@"thumbnail_url"];

// Note: When the uploading is in progress, the upload id is stored in the content url (nasty trick).
// Prepare the absolute URL from the mxc: content URL, only if the thumbnail is not currently uploading.
if (![unencrypted_video_thumb_url hasPrefix:kMXMediaUploadIdPrefix])
if (![unencrypted_thumb_url hasPrefix:kMXMediaUploadIdPrefix])
{
unencrypted_video_thumb_url = [self.sess.matrixRestClient urlOfContent:unencrypted_video_thumb_url];
unencrypted_thumb_url = [self.sess.matrixRestClient urlOfContent:unencrypted_thumb_url];
}

return unencrypted_video_thumb_url;
return unencrypted_thumb_url;
}
}

Expand Down
5 changes: 3 additions & 2 deletions MatrixKit/Models/Room/MXKRoomBubbleCellData.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +58,7 @@ - (instancetype)initWithEvent:(MXEvent *)event andRoomState:(MXRoomState *)roomS
// Check attachment if any
if ([roomDataSource.eventFormatter isSupportedAttachment:event])
{
// Note: event.eventType is equal here to MXEventTypeRoomMessage
// Note: event.eventType is equal here to MXEventTypeRoomMessage or MXEventTypeSticker
attachment = [[MXKAttachment alloc] initWithEvent:event andMatrixSession:roomDataSource.mxSession];
if (attachment && attachment.type == MXKAttachmentTypeImage)
{
Expand Down Expand Up @@ -639,7 +640,7 @@ - (BOOL)hasNoDisplay

- (BOOL)isAttachmentWithThumbnail
{
return (attachment && (attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeVideo));
return (attachment && (attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeVideo || attachment.type == MXKAttachmentTypeSticker));
}

- (BOOL)isAttachmentWithIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ - (BOOL)addEvent:(MXEvent*)event andRoomState:(MXRoomState*)roomState
// We group together text messages from the same user (attachments are not merged).
if ([event.sender isEqualToString:self.senderId] && (self.attachment == nil) && (self.bubbleComponents.count < self.maxComponentCount))
{
// Attachments (image, video ...) cannot be added here
// Attachments (image, video, sticker ...) cannot be added here
if ([roomDataSource.eventFormatter isSupportedAttachment:event])
{
return NO;
Expand Down
1 change: 1 addition & 0 deletions MatrixKit/Models/Room/MXKRoomDataSource.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2015 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2018 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 9f67404

Please sign in to comment.