Add "Forward message" functionality using same controllers as with share extension.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2021-07-22 15:46:37 +02:00
Родитель b88de12e76
Коммит 252977d068
7 изменённых файлов: 59 добавлений и 3 удалений

Просмотреть файл

@ -101,6 +101,9 @@
2C4987BD21E640E20060AC27 /* CallKitManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4987BC21E640E20060AC27 /* CallKitManager.m */; };
2C4CDCCC269618240023F403 /* RoomDescriptionTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4CDCCA269618230023F403 /* RoomDescriptionTableViewCell.m */; };
2C4CDCCD269618240023F403 /* RoomDescriptionTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C4CDCCB269618230023F403 /* RoomDescriptionTableViewCell.xib */; };
2C4CDCD026A84AEA0023F403 /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C62AFB824C1A4E6007E460A /* ShareViewController.m */; };
2C4CDCD126A84E500023F403 /* ShareTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C3195C024C5E2100066F221 /* ShareTableViewCell.m */; };
2C4CDCD226A84E550023F403 /* ShareTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C3195C124C5E2100066F221 /* ShareTableViewCell.xib */; };
2C4D7D631F2F7C2C00FF4A0D /* ARDCaptureController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D621F2F7C2C00FF4A0D /* ARDCaptureController.m */; };
2C4D7D691F2F7DBC00FF4A0D /* ARDSettingsModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D651F2F7DBC00FF4A0D /* ARDSettingsModel.m */; };
2C4D7D6A1F2F7DBC00FF4A0D /* ARDSettingsStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C4D7D681F2F7DBC00FF4A0D /* ARDSettingsStore.m */; };
@ -1598,6 +1601,7 @@
2C444707265E59B500DF1DBC /* ShareConfirmationCollectionViewCell.xib in Resources */,
2CC7158920B837140045C789 /* PlaceholderView.xib in Resources */,
2CB6ACEC2641954700D3D641 /* MapViewController.xib in Resources */,
2C4CDCD226A84E550023F403 /* ShareTableViewCell.xib in Resources */,
2C7A12432017872600864818 /* AddParticipantsTableViewController.xib in Resources */,
2C2026A52369F47400DFC89B /* AccountTableViewCell.xib in Resources */,
);
@ -1825,6 +1829,7 @@
1F4DD3EB2571C688007DC98E /* EmojiUtils.swift in Sources */,
2C4D7D731F309DA500FF4A0D /* RTCSessionDescription+JSON.m in Sources */,
2CB3041C2264775E0053078A /* SLKTextView+SLKAdditions.m in Sources */,
2C4CDCD126A84E500023F403 /* ShareTableViewCell.m in Sources */,
2C8CDD0621C2EDE8004E2997 /* AvatarBackgroundImageView.m in Sources */,
2C9B0B9C217F756B00A4752C /* NCNotification.m in Sources */,
2C4CDCCC269618240023F403 /* RoomDescriptionTableViewCell.m in Sources */,
@ -1899,6 +1904,7 @@
2C4DE9F221F732B40096940D /* NCAudioController.m in Sources */,
2C8A2BC9221F094F00DE6D2C /* DirectoryTableViewController.m in Sources */,
2C42ADB420B58E6300296DEA /* NCChatController.m in Sources */,
2C4CDCD026A84AEA0023F403 /* ShareViewController.m in Sources */,
2C4446EC265D25BA00DF1DBC /* NCKeyChainController.m in Sources */,
2C2A788E2359CC8800EEB797 /* NCAppBranding.m in Sources */,
2CA15541208E350300CE8EF0 /* NCChatMessage.m in Sources */,

Просмотреть файл

@ -25,6 +25,7 @@
#import "NCRoom.h"
extern NSString * const NCChatViewControllerReplyPrivatelyNotification;
extern NSString * const NCChatViewControllerForwardNotification;
@interface NCChatViewController : SLKTextViewController

Просмотреть файл

@ -66,6 +66,7 @@
#import "QuotedMessageView.h"
#import "ReplyMessageView.h"
#import "RoomInfoTableViewController.h"
#import "ShareViewController.h"
#import "ShareConfirmationViewController.h"
#import "ShareItem.h"
#import "SystemMessageTableViewCell.h"
@ -137,6 +138,7 @@ typedef enum NCChatMessageAction {
@implementation NCChatViewController
NSString * const NCChatViewControllerReplyPrivatelyNotification = @"NCChatViewControllerReplyPrivatelyNotification";
NSString * const NCChatViewControllerForwardNotification = @"NCChatViewControllerForwardNotification";
- (instancetype)initForRoom:(NCRoom *)room
{
@ -1170,7 +1172,9 @@ NSString * const NCChatViewControllerReplyPrivatelyNotification = @"NCChatViewCo
}
- (void)didPressForward:(NCChatMessage *)message {
// Forward message
ShareViewController *shareViewController = [[ShareViewController alloc] initToForwardMessage:message.parsedMessage.string fromChatViewController:self];
NCNavigationController *forwardMessageNC = [[NCNavigationController alloc] initWithRootViewController:shareViewController];
[self presentViewController:forwardMessageNC animated:YES completion:nil];
}
- (void)didPressResend:(NCChatMessage *)message {
@ -1304,11 +1308,24 @@ NSString * const NCChatViewControllerReplyPrivatelyNotification = @"NCChatViewCo
- (void)shareConfirmationViewControllerDidFailed:(ShareConfirmationViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
if (viewController.forwardingMessage) {
// Show error
}
}
- (void)shareConfirmationViewControllerDidFinish:(ShareConfirmationViewController *)viewController
{
[self dismissViewControllerAnimated:YES completion:nil];
if (viewController.forwardingMessage) {
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
[userInfo setObject:viewController.room.token forKey:@"token"];
[userInfo setObject:viewController.account.accountId forKey:@"accountId"];
[[NSNotificationCenter defaultCenter] postNotificationName:NCChatViewControllerForwardNotification
object:self
userInfo:userInfo];
}
}
#pragma mark - ShareLocationViewController Delegate

Просмотреть файл

@ -89,6 +89,7 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startCallForRoom:) name:CallKitManagerDidStartCallNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkForCallUpgrades:) name:CallKitManagerDidEndCallNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinOrCreateChat:) name:NCChatViewControllerReplyPrivatelyNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(joinChatOfForwardedMessage:) name:NCChatViewControllerForwardNotification object:nil];
}
return self;
@ -791,6 +792,14 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
}
- (void)joinChatOfForwardedMessage:(NSNotification *)notification
{
NSString *accountId = [notification.userInfo objectForKey:@"accountId"];
NSString *token = [notification.userInfo objectForKey:@"token"];
[self checkForAccountChange:accountId];
[self startChatWithRoomToken:token];
}
- (void)joinChatWithLocalNotification:(NSNotification *)notification
{
NSString *roomToken = [notification.userInfo objectForKey:@"roomToken"];

Просмотреть файл

@ -53,6 +53,7 @@ typedef enum ShareConfirmationType {
@property (strong, nonatomic) ServerCapabilities *serverCapabilities;
@property (assign, nonatomic) ShareConfirmationType type;
@property (assign, nonatomic) BOOL isModal;
@property (assign, nonatomic) BOOL forwardingMessage;
@property (strong, nonatomic) ShareItemController *shareItemController;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomSpacer;

Просмотреть файл

@ -26,6 +26,11 @@ NS_ASSUME_NONNULL_BEGIN
@interface ShareViewController : UITableViewController
@property (strong, nonatomic) UIViewController *chatViewController;
@property (strong, nonatomic) NSString *forwardMessage;
- (id)initToForwardMessage:(NSString *)message fromChatViewController:(UIViewController *)chatViewController;
@end
NS_ASSUME_NONNULL_END

Просмотреть файл

@ -51,6 +51,17 @@
@implementation ShareViewController
- (id)initToForwardMessage:(NSString *)message fromChatViewController:(UIViewController *)chatViewController
{
self = [super init];
if (self) {
self.chatViewController = chatViewController;
self.forwardMessage = message;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
@ -122,7 +133,7 @@
[_searchController.searchBar sizeToFit];
// Configure navigation bar
self.navigationItem.title = NSLocalizedString(@"Share with", nil);
self.navigationItem.title = _forwardMessage ? NSLocalizedString(@"Forward to", nil) : NSLocalizedString(@"Share with", nil);
[self.navigationController.navigationBar setTitleTextAttributes:
@{NSForegroundColorAttributeName:[NCAppBranding themeTextColor]}];
self.navigationController.navigationBar.tintColor = [NCAppBranding themeTextColor];
@ -552,7 +563,13 @@
ShareConfirmationViewController *shareConfirmationVC = [[ShareConfirmationViewController alloc] initWithRoom:room account:_shareAccount serverCapabilities:_serverCapabilities];
shareConfirmationVC.delegate = self;
[self setSharedItemToShareConfirmationViewController:shareConfirmationVC];
if (_forwardMessage) {
shareConfirmationVC.delegate = (id<ShareConfirmationViewControllerDelegate>)_chatViewController;
shareConfirmationVC.forwardingMessage = YES;
[shareConfirmationVC shareText:_forwardMessage];
} else {
[self setSharedItemToShareConfirmationViewController:shareConfirmationVC];
}
[self.navigationController pushViewController:shareConfirmationVC animated:YES];
}