Skip to content

Commit

Permalink
/issues/5009 - Implemented multi-room forwarding and added various tw…
Browse files Browse the repository at this point in the history
…eaks following code review.
  • Loading branch information
stefanceriu committed Oct 18, 2021
1 parent 89f6503 commit 9f7e81b
Show file tree
Hide file tree
Showing 25 changed files with 612 additions and 476 deletions.
6 changes: 3 additions & 3 deletions Riot/Assets/SharedImages.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "radio-button-default.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "radio-button-default@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "radio-button-default@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "radio-button-selected.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "radio-button-selected@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "radio-button-selected@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ internal enum Asset {
internal static let cancel = ImageAsset(name: "cancel")
internal static let e2eVerified = ImageAsset(name: "e2e_verified")
internal static let horizontalLogo = ImageAsset(name: "horizontal_logo")
internal static let radioButtonDefault = ImageAsset(name: "radio-button-default")
internal static let radioButtonSelected = ImageAsset(name: "radio-button-selected")
}
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name
Expand Down
62 changes: 26 additions & 36 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2368,10 +2368,7 @@ - (void)showPreviewHeader:(BOOL)isVisible

// Set a default title view class without handling tap gesture (Let [self refreshRoomTitle] refresh this view correctly).
[self setRoomTitleViewClass:RoomTitleView.class];

// Remove details icon
RoomTitleView *roomTitleView = (RoomTitleView*)self.titleView;


// Remove the shadow image used to hide the bottom border of the navigation bar when the preview header is displayed
[mainNavigationController.navigationBar setShadowImage:nil];
[mainNavigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Expand Down Expand Up @@ -3167,7 +3164,8 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXK
[currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
self.shareManager = [[ShareManager alloc] initWithShareItemProvider:[[SimpleShareItemProvider alloc] initWithTextMessage:selectedComponent.textMessage]];
self.shareManager = [[ShareManager alloc] initWithShareItemProvider:[[SimpleShareItemProvider alloc] initWithTextMessage:selectedComponent.textMessage]
type:ShareManagerTypeForward];

MXWeakify(self);
[self.shareManager setCompletionCallback:^(ShareManagerResult result) {
Expand Down Expand Up @@ -3233,6 +3231,29 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXK
}
else // Add action for attachment
{
if (attachment.type == MXKAttachmentTypeFile ||
attachment.type == MXKAttachmentTypeImage ||
attachment.type == MXKAttachmentTypeVideo ||
attachment.type == MXKAttachmentTypeVoiceMessage) {

[currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
self.shareManager = [[ShareManager alloc] initWithShareItemProvider:[[SimpleShareItemProvider alloc] initWithAttachment:attachment]
type:ShareManagerTypeForward];

MXWeakify(self);
[self.shareManager setCompletionCallback:^(ShareManagerResult result) {
MXStrongifyAndReturnIfNil(self);
[attachment onShareEnded];
[self dismissViewControllerAnimated:YES completion:nil];
self.shareManager = nil;
}];

[self presentViewController:self.shareManager.mainViewController animated:YES completion:nil];
}]];
}

if (BuildSettings.messageDetailsAllowSave)
{
if (attachment.type == MXKAttachmentTypeImage || attachment.type == MXKAttachmentTypeVideo)
Expand Down Expand Up @@ -3359,37 +3380,6 @@ - (void)showAdditionalActionsMenuForEvent:(MXEvent*)selectedEvent inCell:(id<MXK
}]];
}
}

if (attachment.type == MXKAttachmentTypeFile ||
attachment.type == MXKAttachmentTypeImage ||
attachment.type == MXKAttachmentTypeVideo ||
attachment.type == MXKAttachmentTypeVoiceMessage) {

[currentAlert addAction:[UIAlertAction actionWithTitle:[VectorL10n roomEventActionForward]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[self startActivityIndicator];

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

self.shareManager = [[ShareManager alloc] initWithShareItemProvider:[[SimpleShareItemProvider alloc] initWithAttachment:attachment]];

MXWeakify(self);
[self.shareManager setCompletionCallback:^(ShareManagerResult result) {
MXStrongifyAndReturnIfNil(self);
[attachment onShareEnded];
[self dismissViewControllerAnimated:YES completion:nil];
self.shareManager = nil;
}];

[self presentViewController:self.shareManager.mainViewController animated:YES completion:nil];
} failure:^(NSError *error) {
[self showError:error];
[self stopActivityIndicator];
}];
}]];
}
}

// Check status of the selected event
Expand Down
30 changes: 15 additions & 15 deletions RiotShareExtension/Shared/ShareDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@

#import <MatrixKit/MatrixKit.h>

typedef NS_ENUM(NSInteger, ShareDataSourceMode)
{
DataSourceModePeople,
DataSourceModeRooms
};
@class ShareDataSource;

@protocol ShareDataSourceDelegate <NSObject>

- (void)shareDataSourceDidChangeSelectedRoomIdentifiers:(ShareDataSource *)shareDataSource;

@end

@interface ShareDataSource : MXKRecentsDataSource

- (instancetype)initWithMode:(ShareDataSourceMode)dataSourceMode
fileStore:(MXFileStore *)fileStore
credentials:(MXCredentials *)credentials;
@property (nonatomic, weak) id<ShareDataSourceDelegate> shareDelegate;

/**
Returns the cell data at the index path
@param indexPath the index of the cell
@return the MXKRecentCellData instance if it exists
*/
- (MXKRecentCellData *)cellDataAtIndexPath:(NSIndexPath *)indexPath;
@property (nonatomic, strong, readonly) NSSet<NSString *> *selectedRoomIdentifiers;

- (instancetype)initWithFileStore:(MXFileStore *)fileStore
credentials:(MXCredentials *)credentials;

- (void)selectRoomWithIdentifier:(NSString *)roomIdentifier animated:(BOOL)animated;

- (void)deselectRoomWithIdentifier:(NSString *)roomIdentifier animated:(BOOL)animated;

@end
39 changes: 32 additions & 7 deletions RiotShareExtension/Shared/ShareDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,28 @@

@interface ShareDataSource ()

@property (nonatomic, assign, readonly) ShareDataSourceMode dataSourceMode;
@property (nonatomic, strong, readonly) MXFileStore *fileStore;
@property (nonatomic, strong, readonly) MXCredentials *credentials;

@property NSArray <MXKRecentCellData *> *recentCellDatas;
@property NSMutableArray <MXKRecentCellData *> *visibleRoomCellDatas;

@property (nonatomic, strong) NSMutableSet<NSString *> *internalSelectedRoomIdentifiers;

@end

@implementation ShareDataSource

- (instancetype)initWithMode:(ShareDataSourceMode)dataSourceMode
fileStore:(MXFileStore *)fileStore
credentials:(MXCredentials *)credentials
- (instancetype)initWithFileStore:(MXFileStore *)fileStore
credentials:(MXCredentials *)credentials
{
if (self = [super init])
{
_dataSourceMode = dataSourceMode;
_fileStore = fileStore;
_credentials = credentials;

_internalSelectedRoomIdentifiers = [NSMutableSet set];

[self loadCellData];
}
return self;
Expand All @@ -53,6 +54,25 @@ - (void)destroy
_visibleRoomCellDatas = nil;
}

- (NSSet<NSString *> *)selectedRoomIdentifiers
{
return self.internalSelectedRoomIdentifiers.copy;
}

- (void)selectRoomWithIdentifier:(NSString *)roomIdentifier animated:(BOOL)animated
{
[self.internalSelectedRoomIdentifiers addObject:roomIdentifier];

[self.shareDelegate shareDataSourceDidChangeSelectedRoomIdentifiers:self];
}

- (void)deselectRoomWithIdentifier:(NSString *)roomIdentifier animated:(BOOL)animated
{
[self.internalSelectedRoomIdentifiers removeObject:roomIdentifier];

[self.shareDelegate shareDataSourceDidChangeSelectedRoomIdentifiers:self];
}

#pragma mark - Private

- (void)loadCellData
Expand All @@ -66,7 +86,7 @@ - (void)loadCellData

for (MXRoomSummary *roomSummary in roomsSummaries)
{
if (!roomSummary.hiddenFromUser && ((self.dataSourceMode == DataSourceModeRooms) ^ roomSummary.isDirect))
if (!roomSummary.hiddenFromUser)
{
[roomSummary setMatrixSession:session];

Expand Down Expand Up @@ -137,6 +157,7 @@ - (void)searchWithPatterns:(NSArray *)patternsList
{
self.visibleRoomCellDatas = nil;
}

[self.delegate dataSource:self didCellChange:nil];
}

Expand All @@ -160,7 +181,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
{
RecentRoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[RecentRoomTableViewCell defaultReuseIdentifier]];

[cell render:[self cellDataAtIndexPath:indexPath]];
MXKRecentCellData *data = [self cellDataAtIndexPath:indexPath];

[cell render:data];

[cell setCustomSelected:[self.selectedRoomIdentifiers containsObject:data.roomSummary.roomId] animated:NO];

return cell;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ private class SimpleShareItem: ShareItemProtocol {

let items: [ShareItemProtocol]

private override init() {
attachment = nil
textMessage = nil
self.items = []
}

@objc public init(withAttachment attachment: MXKAttachment) {
self.attachment = attachment
self.items = [SimpleShareItem(withAttachment: attachment)];
Expand All @@ -78,10 +84,18 @@ private class SimpleShareItem: ShareItemProtocol {
return
}

attachment?.prepareShare({ url in
completion(url, nil)
guard let attachment = attachment else {
fatalError("[SimpleShareItemProvider] Invalid item provider state.")
}

attachment.prepareShare({ url in
DispatchQueue.main.async {
completion(url, nil)
}
}, failure: { error in
completion(nil, error)
DispatchQueue.main.async {
completion(nil, error)
}
})
}

Expand Down
14 changes: 7 additions & 7 deletions RiotShareExtension/Shared/ShareManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, ShareManagerType) {
ShareManagerTypeSend,
ShareManagerTypeForward,
};

typedef NS_ENUM(NSUInteger, ShareManagerResult) {
ShareManagerResultFinished,
ShareManagerResultCancelled,
Expand All @@ -30,17 +35,12 @@ typedef NS_ENUM(NSUInteger, ShareManagerResult) {

@property (nonatomic, copy) void (^completionCallback)(ShareManagerResult);

- (instancetype)initWithShareItemProvider:(id<ShareItemProviderProtocol>)shareItemProvider;
- (instancetype)initWithShareItemProvider:(id<ShareItemProviderProtocol>)shareItemProvider
type:(ShareManagerType)type;

- (UIViewController *)mainViewController;

@end


@interface NSItemProvider (ShareManager)

@property BOOL isLoaded;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit 9f7e81b

Please sign in to comment.