Skip to content

Commit

Permalink
Merge pull request #1831 from vector-im/riot_1819
Browse files Browse the repository at this point in the history
Render sticker events in the timeline
  • Loading branch information
giomfo committed Apr 3, 2018
2 parents c057e5e + 9638de3 commit 37754f0
Show file tree
Hide file tree
Showing 7 changed files with 643 additions and 36 deletions.
10 changes: 10 additions & 0 deletions Riot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
02543BAE206E6C59001CDAB2 /* RoomSelectedStickerBubbleCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 02543BAB206E6C58001CDAB2 /* RoomSelectedStickerBubbleCell.m */; };
02543BAF206E6C59001CDAB2 /* RoomSelectedStickerBubbleCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 02543BAC206E6C58001CDAB2 /* RoomSelectedStickerBubbleCell.xib */; };
2435179C1F375B9400D0683E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7551F2F80B800AE27B0 /* Info.plist */; };
2435179F1F375C0F00D0683E /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382C01F276AED00356143 /* Vector.strings */; };
2439DD621F6BBE760090F42D /* RecentRoomTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2439DD611F6BBE760090F42D /* RecentRoomTableViewCell.m */; };
Expand Down Expand Up @@ -656,6 +658,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
02543BAB206E6C58001CDAB2 /* RoomSelectedStickerBubbleCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomSelectedStickerBubbleCell.m; sourceTree = "<group>"; };
02543BAC206E6C58001CDAB2 /* RoomSelectedStickerBubbleCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomSelectedStickerBubbleCell.xib; sourceTree = "<group>"; };
02543BAD206E6C59001CDAB2 /* RoomSelectedStickerBubbleCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomSelectedStickerBubbleCell.h; sourceTree = "<group>"; };
12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.debug.xcconfig"; sourceTree = "<group>"; };
22D76C11C202B6BC5917A049 /* Pods-RiotPods-RiotShareExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotPods-RiotShareExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-RiotPods-RiotShareExtension/Pods-RiotPods-RiotShareExtension.release.xcconfig"; sourceTree = "<group>"; };
23D7292481328A48B8D5D4ED /* Pods_RiotPods_RiotShareExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RiotPods_RiotShareExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -2428,6 +2433,9 @@
F083BCD51E7009EC00A9B29C /* RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.h */,
F083BCD61E7009EC00A9B29C /* RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.m */,
F083BCD71E7009EC00A9B29C /* RoomOutgoingTextMsgWithPaginationTitleWithoutSenderNameBubbleCell.xib */,
02543BAD206E6C59001CDAB2 /* RoomSelectedStickerBubbleCell.h */,
02543BAB206E6C58001CDAB2 /* RoomSelectedStickerBubbleCell.m */,
02543BAC206E6C58001CDAB2 /* RoomSelectedStickerBubbleCell.xib */,
);
path = RoomBubbleList;
sourceTree = "<group>";
Expand Down Expand Up @@ -3217,6 +3225,7 @@
F083BD3A1E7009ED00A9B29C /* call_chat_icon@2x.png in Resources */,
F083BE711E7009ED00A9B29C /* RoomOutgoingTextMsgBubbleCell.xib in Resources */,
F083BD5E1E7009ED00A9B29C /* create_room@3x.png in Resources */,
02543BAF206E6C59001CDAB2 /* RoomSelectedStickerBubbleCell.xib in Resources */,
F083BE6B1E7009ED00A9B29C /* RoomOutgoingAttachmentBubbleCell.xib in Resources */,
F083BD4C1E7009ED00A9B29C /* camera_capture@2x.png in Resources */,
F083BD8F1E7009ED00A9B29C /* file_video_icon.png in Resources */,
Expand Down Expand Up @@ -3635,6 +3644,7 @@
F083BE601E7009ED00A9B29C /* RoomIncomingTextMsgBubbleCell.m in Sources */,
F083BE2F1E7009ED00A9B29C /* ContactTableViewCell.m in Sources */,
F083BE901E7009ED00A9B29C /* RoomTitleView.m in Sources */,
02543BAE206E6C59001CDAB2 /* RoomSelectedStickerBubbleCell.m in Sources */,
F083BE6E1E7009ED00A9B29C /* RoomOutgoingAttachmentWithPaginationTitleBubbleCell.m in Sources */,
3233F7311F31F4BF006ACA81 /* JitsiViewController.m in Sources */,
F083BE2A1E7009ED00A9B29C /* UsersDevicesViewController.m in Sources */,
Expand Down
10 changes: 10 additions & 0 deletions Riot/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2014 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 @@ -1587,6 +1588,15 @@ - (nullable NSString *)notificationBodyForEvent:(MXEvent *)event pushRule:(MXPus
else
notificationBody = [NSString stringWithFormat:NSLocalizedString(@"USER_INVITE_TO_CHAT", nil), eventSenderName];
}
else if (event.eventType == MXEventTypeSticker)
{
NSString *roomDisplayName = room.summary.displayname;

if (roomDisplayName.length && ![roomDisplayName isEqualToString:eventSenderName])
notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER_IN_ROOM", nil), eventSenderName, roomDisplayName];
else
notificationBody = [NSString stringWithFormat:NSLocalizedString(@"MSG_FROM_USER", nil), eventSenderName];
}

return notificationBody;
}
Expand Down
5 changes: 3 additions & 2 deletions Riot/Model/Search/FilesSearchCellData.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2016 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 @@ -39,7 +40,7 @@ - (instancetype)initWithSearchResult:(MXSearchResult *)searchResult2 andSearchDa
// Check attachment if any
if ([searchDataSource.eventFormatter isSupportedAttachment:event])
{
// Note: event.eventType is equal here to MXEventTypeRoomMessage
// Note: event.eventType may be equal here to MXEventTypeRoomMessage or MXEventTypeSticker
attachment = [[MXKAttachment alloc] initWithEvent:event andMatrixSession:searchDataSource.mxSession];
}

Expand Down Expand Up @@ -101,7 +102,7 @@ - (void)setShouldShowRoomDisplayName:(BOOL)shouldShowRoomDisplayName2

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

- (UIImage*)attachmentIcon
Expand Down
107 changes: 73 additions & 34 deletions Riot/ViewController/RoomViewController.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
Copyright 2014 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 @@ -97,6 +98,8 @@
#import "RoomMembershipExpandedBubbleCell.h"
#import "RoomMembershipExpandedWithPaginationTitleBubbleCell.h"

#import "RoomSelectedStickerBubbleCell.h"

#import "MXKRoomBubbleTableViewCell+Riot.h"

#import "AvatarGenerator.h"
Expand Down Expand Up @@ -310,6 +313,8 @@ - (void)viewDidLoad
[self.bubblesTableView registerClass:RoomMembershipExpandedBubbleCell.class forCellReuseIdentifier:RoomMembershipExpandedBubbleCell.defaultReuseIdentifier];
[self.bubblesTableView registerClass:RoomMembershipExpandedWithPaginationTitleBubbleCell.class forCellReuseIdentifier:RoomMembershipExpandedWithPaginationTitleBubbleCell.defaultReuseIdentifier];

[self.bubblesTableView registerClass:RoomSelectedStickerBubbleCell.class forCellReuseIdentifier:RoomSelectedStickerBubbleCell.defaultReuseIdentifier];

// Prepare expanded header
expandedHeader = [ExpandedRoomTitleView roomTitleView];
expandedHeader.delegate = self;
Expand Down Expand Up @@ -1760,7 +1765,12 @@ - (void)displayRoomPreview:(RoomPreviewData *)previewData
{
if (bubbleData.isAttachmentWithThumbnail)
{
if (bubbleData.isPaginationFirstBubble)
// Check whether the provided celldata corresponds to a selected sticker
if (customizedRoomDataSource.selectedEventId && (bubbleData.attachment.type == MXKAttachmentTypeSticker) && [bubbleData.attachment.eventId isEqualToString:customizedRoomDataSource.selectedEventId])
{
cellViewClass = RoomSelectedStickerBubbleCell.class;
}
else if (bubbleData.isPaginationFirstBubble)
{
cellViewClass = isEncryptedRoom ? RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.class : RoomIncomingAttachmentWithPaginationTitleBubbleCell.class;
}
Expand Down Expand Up @@ -1805,7 +1815,12 @@ - (void)displayRoomPreview:(RoomPreviewData *)previewData
// Handle here outgoing bubbles
if (bubbleData.isAttachmentWithThumbnail)
{
if (bubbleData.isPaginationFirstBubble)
// Check whether the provided celldata corresponds to a selected sticker
if (customizedRoomDataSource.selectedEventId && (bubbleData.attachment.type == MXKAttachmentTypeSticker) && [bubbleData.attachment.eventId isEqualToString:customizedRoomDataSource.selectedEventId])
{
cellViewClass = RoomSelectedStickerBubbleCell.class;
}
else if (bubbleData.isPaginationFirstBubble)
{
cellViewClass = isEncryptedRoom ? RoomOutgoingEncryptedAttachmentWithPaginationTitleBubbleCell.class :RoomOutgoingAttachmentWithPaginationTitleBubbleCell.class;
}
Expand Down Expand Up @@ -1909,12 +1924,33 @@ - (void)dataSource:(MXKDataSource *)dataSource didRecognizeAction:(NSString *)ac
[self showEditButtonAlertMenuForEvent:selectedEvent inCell:cell level:0];
}
}
else if ([actionIdentifier isEqualToString:kMXKRoomBubbleCellTapOnAttachmentView]
&& ((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventSentState == MXEventSentStateFailed)
else if ([actionIdentifier isEqualToString:kMXKRoomBubbleCellTapOnAttachmentView])
{
// Shortcut: when clicking on an unsent media, show the action sheet to resend it
MXEvent *selectedEvent = [self.roomDataSource eventWithEventId:((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId];
[self dataSource:dataSource didRecognizeAction:kMXKRoomBubbleCellRiotEditButtonPressed inCell:cell userInfo:@{kMXKRoomBubbleCellEventKey:selectedEvent}];
if (((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventSentState == MXEventSentStateFailed)
{
// Shortcut: when clicking on an unsent media, show the action sheet to resend it
MXEvent *selectedEvent = [self.roomDataSource eventWithEventId:((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId];
[self dataSource:dataSource didRecognizeAction:kMXKRoomBubbleCellRiotEditButtonPressed inCell:cell userInfo:@{kMXKRoomBubbleCellEventKey:selectedEvent}];
}
else if (((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.type == MXKAttachmentTypeSticker)
{
// We don't open the attachments viewer when the user taps on a sticker.
// We consider this tap like a selection.

// Check whether a selection already exist or not
if (customizedRoomDataSource.selectedEventId)
{
[self cancelEventSelection];
}
else
{
// Highlight this event in displayed message
customizedRoomDataSource.selectedEventId = ((MXKRoomBubbleTableViewCell*)cell).bubbleData.attachment.eventId;
}

// Force table refresh
[self dataSource:self.roomDataSource didCellChange:nil];
}
}
else if ([actionIdentifier isEqualToString:kRoomEncryptedDataBubbleCellTapOnEncryptionIcon])
{
Expand Down Expand Up @@ -2156,38 +2192,41 @@ - (void)showEditButtonAlertMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXKCe
}]];
}

[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_event_action_copy", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

if (weakSelf)
{
typeof(self) self = weakSelf;

[self cancelEventSelection];

[self startActivityIndicator];
if (attachment.type != MXKAttachmentTypeSticker)
{
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_event_action_copy", @"Vector", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {

[attachment copy:^{

__strong __typeof(weakSelf)self = weakSelf;
[self stopActivityIndicator];
if (weakSelf)
{
typeof(self) self = weakSelf;

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

__strong __typeof(weakSelf)self = weakSelf;
[self stopActivityIndicator];
[self startActivityIndicator];

//Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
[attachment copy:^{

__strong __typeof(weakSelf)self = weakSelf;
[self stopActivityIndicator];

} failure:^(NSError *error) {

__strong __typeof(weakSelf)self = weakSelf;
[self stopActivityIndicator];

//Alert user
[[AppDelegate theDelegate] showErrorAsAlert: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 Expand Up @@ -2234,7 +2273,7 @@ - (void)showEditButtonAlertMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXKCe
}
}

if (level == 1)
if (level == 1 && (attachment.type != MXKAttachmentTypeSticker))
{
[currentAlert addAction:[UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"room_event_action_share", @"Vector", nil)
style:UIAlertActionStyleDefault
Expand Down
33 changes: 33 additions & 0 deletions Riot/Views/RoomBubbleList/RoomSelectedStickerBubbleCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell.h"

/**
`RoomSelectedStickerBubbleCell` is used to display the current selected sticker if any
*/
@interface RoomSelectedStickerBubbleCell : RoomIncomingEncryptedAttachmentWithPaginationTitleBubbleCell

@property (weak, nonatomic) IBOutlet UIView *descriptionContainerView;
@property (weak, nonatomic) IBOutlet UIView *arrowView;
@property (weak, nonatomic) IBOutlet UIView *descriptionView;
@property (weak, nonatomic) IBOutlet UILabel *descriptionLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *userNameLabelTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *attachViewLeadingConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *descriptionContainerViewBottomConstraint;

@end
Loading

0 comments on commit 37754f0

Please sign in to comment.