Add 'Reply Privately' functionality

Signed-off-by: Marcel Müller <marcel-mueller@gmx.de>
This commit is contained in:
Marcel Müller 2020-11-14 21:00:33 +01:00 коммит произвёл Marcel Müller
Родитель 99a0b59f01
Коммит 783b616356
3 изменённых файлов: 55 добавлений и 1 удалений

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

@ -24,6 +24,8 @@
#import "NCRoom.h"
extern NSString * const NCChatViewControllerJoinChatAndReplyPrivately;
@interface NCChatViewController : SLKTextViewController
@property (nonatomic, strong) NCRoom *room;

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

@ -60,7 +60,8 @@ typedef enum NCChatMessageAction {
kNCChatMessageActionReply = 1,
kNCChatMessageActionCopy,
kNCChatMessageActionResend,
kNCChatMessageActionDelete
kNCChatMessageActionDelete,
kNCChatMessageActionReplyPrivately
} NCChatMessageAction;
@interface NCChatViewController () <UIGestureRecognizerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, ShareConfirmationViewControllerDelegate>
@ -99,6 +100,8 @@ typedef enum NCChatMessageAction {
@implementation NCChatViewController
NSString * const NCChatViewControllerJoinChatAndReplyPrivately = @"NCChatViewControllerJoinChatAndReplyPrivately";
- (instancetype)initForRoom:(NCRoom *)room
{
self = [super initWithTableViewStyle:UITableViewStylePlain];
@ -904,6 +907,12 @@ typedef enum NCChatMessageAction {
FTPopOverMenuModel *replyModel = [[FTPopOverMenuModel alloc] initWithTitle:NSLocalizedString(@"Reply", nil) image:[UIImage imageNamed:@"reply"] userInfo:replyInfo];
[menuArray addObject:replyModel];
}
// Reply-privately option (only to users and only if group- or public-room)
if (message.isReplyable && [message.actorType isEqualToString:@"users"] && (_room.type == kNCRoomTypeGroup || _room.type == kNCRoomTypePublic)) {
NSDictionary *replyPrivatInfo = [NSDictionary dictionaryWithObject:@(kNCChatMessageActionReplyPrivately) forKey:@"action"];
FTPopOverMenuModel *replyPrivatModel = [[FTPopOverMenuModel alloc] initWithTitle:NSLocalizedString(@"Reply Privately", nil) image:[UIImage imageNamed:@"reply"] userInfo:replyPrivatInfo];
[menuArray addObject:replyPrivatModel];
}
// Re-send option
if (message.sendingFailed) {
NSDictionary *replyInfo = [NSDictionary dictionaryWithObject:@(kNCChatMessageActionResend) forKey:@"action"];
@ -939,6 +948,15 @@ typedef enum NCChatMessageAction {
[weakSelf presentKeyboard:YES];
}
break;
case kNCChatMessageActionReplyPrivately:
{
NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init];
[userInfo setObject:message.actorId forKey:@"actorId"];
[[NSNotificationCenter defaultCenter] postNotificationName:NCChatViewControllerJoinChatAndReplyPrivately
object:self
userInfo:userInfo];
}
break;
case kNCChatMessageActionCopy:
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

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

@ -86,6 +86,7 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(acceptCallForRoom:) name:CallKitManagerDidAnswerCallNotification object:nil];
[[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:NCChatViewControllerJoinChatAndReplyPrivately object:nil];
}
return self;
@ -611,6 +612,39 @@ NSString * const NCRoomsManagerDidReceiveChatMessagesNotification = @"ChatMess
[self startChatWithRoomToken:pushNotification.roomToken];
}
- (void)joinOrCreateChat:(NSNotification *)notification
{
NSString *actorId = [notification.userInfo objectForKey:@"actorId"];
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
NSArray *accountRooms = [[NCRoomsManager sharedInstance] roomsForAccountId:activeAccount.accountId witRealm:nil];
for (NCRoom *room in accountRooms) {
NSArray *participantsInRoom = [room.participants valueForKey:@"self"];
if (room.type == kNCRoomTypeOneToOne && [participantsInRoom containsObject:actorId]) {
// Room already exists -> join the room
[self startChatWithRoomToken:room.token];
return;
}
}
// Did not find a one-to-one room for this user -> create a new one
[[NCAPIController sharedInstance] createRoomForAccount:[[NCDatabaseManager sharedInstance] activeAccount] with:actorId
ofType:kNCRoomTypeOneToOne
andName:nil
withCompletionBlock:^(NSString *token, NSError *error) {
if (!error) {
[self startChatWithRoomToken:token];
NSLog(@"Room %@ with %@ created", token, actorId);
} else {
NSLog(@"Failed creating a room with %@", actorId);
}
}];
}
- (void)joinChatWithLocalNotification:(NSNotification *)notification
{
NSString *roomToken = [notification.userInfo objectForKey:@"roomToken"];