From 8585cc01688aa67b89f608968b88c751c68654b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anthony=20L=C3=A9onard?= Date: Thu, 28 Dec 2017 14:03:45 -0500 Subject: [PATCH] deselect conversation when right panel disappear When the back button is pressed, the selected conversation in the list is now deselected. Prior to this patch, it was necessary to select another conversation then the first one to reopen the chat view with a contact. Change-Id: I46a253ecd2161c76bb4d8bab26b7b1389248abc9 Reviewed-by: Kateryna Kostiuk --- src/ConversationVC.h | 4 ++++ src/ConversationVC.mm | 13 +++++++++++++ src/RingWindowController.h | 6 ++++++ src/RingWindowController.mm | 7 ++++++- src/SmartViewVC.h | 5 +++++ src/SmartViewVC.mm | 6 ++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/ConversationVC.h b/src/ConversationVC.h index 887d8fb1..c658882b 100644 --- a/src/ConversationVC.h +++ b/src/ConversationVC.h @@ -21,6 +21,8 @@ #import #import +@class RingWindowController; + @interface ConversationVC : NSViewController -(void) initFrame; @@ -36,4 +38,6 @@ - (void) setConversationUid:(const std::string)convUid model:(lrc::api::ConversationModel*)model; +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil delegate:(RingWindowController*) mainWindow; + @end diff --git a/src/ConversationVC.mm b/src/ConversationVC.mm index 6bece96f..31944f98 100644 --- a/src/ConversationVC.mm +++ b/src/ConversationVC.mm @@ -39,6 +39,7 @@ #import "AvailableAccountModel.h" #import "MessagesVC.h" #import "utils.h" +#import "RingWindowController.h" #import @@ -62,6 +63,8 @@ const lrc::api::conversation::Info* cachedConv_; lrc::api::ConversationModel* convModel_; + RingWindowController* delegate; + // All those connections are needed to invalidate cached conversation as pointer // may not be referencing the same conversation anymore QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_; @@ -73,6 +76,15 @@ @implementation ConversationVC +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil delegate:(RingWindowController*) mainWindow +{ + if (self = [self initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) + { + delegate = mainWindow; + } + return self; +} + -(const lrc::api::conversation::Info*) getCurrentConversation { if (convModel_ == nil || convUid_.empty()) @@ -191,6 +203,7 @@ } - (IBAction)backPressed:(id)sender { + [delegate rightPanelClosed]; [self animateOut]; } diff --git a/src/RingWindowController.h b/src/RingWindowController.h index 3207a2c3..b3500249 100644 --- a/src/RingWindowController.h +++ b/src/RingWindowController.h @@ -49,4 +49,10 @@ namespace lrc { */ - (void) selectAccount:(const lrc::api::account::Info&)accInfo; +/** + * Method triggered when a panel on the right is closed by user action. It triggers any action needed + * on itself or other view controllers to react properly to this event. + */ +-(void) rightPanelClosed; + @end diff --git a/src/RingWindowController.mm b/src/RingWindowController.mm index a0540957..8ba43c4d 100644 --- a/src/RingWindowController.mm +++ b/src/RingWindowController.mm @@ -95,7 +95,7 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde lrc_ = std::make_unique(); currentCallVC = [[CurrentCallVC alloc] initWithNibName:@"CurrentCall" bundle:nil]; - offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil]; + offlineVC = [[ConversationVC alloc] initWithNibName:@"Conversation" bundle:nil delegate:self]; // toolbar items chooseAccountVC = [[ChooseAccountVC alloc] initWithNibName:@"ChooseAccount" bundle:nil model:&(lrc_->getAccountModel()) delegate:self]; contactRequestVC = [[ContactRequestVC alloc] initWithNibName:@"ContactRequest" bundle:nil]; @@ -373,6 +373,11 @@ NSString* const kTrustRequestMenuItemIdentifier = @"TrustRequestMenuItemIde [self updateRingID]; } +-(void)rightPanelClosed +{ + [smartViewVC deselect]; +} + #pragma mark - NSToolbarDelegate - (nullable NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag { diff --git a/src/SmartViewVC.h b/src/SmartViewVC.h index 9c12c0c5..0c9e7145 100644 --- a/src/SmartViewVC.h +++ b/src/SmartViewVC.h @@ -46,4 +46,9 @@ namespace lrc { */ -(void)selectConversation:(const lrc::api::conversation::Info&)conv model:(lrc::api::ConversationModel*)model; +/** + * Deselect any selected conversation + */ +-(void)deselect; + @end diff --git a/src/SmartViewVC.mm b/src/SmartViewVC.mm index 31a0823a..6174038f 100755 --- a/src/SmartViewVC.mm +++ b/src/SmartViewVC.mm @@ -189,6 +189,12 @@ NSInteger const PRESENCE_TAG = 800; } } +-(void)deselect +{ + selectedUid_.clear(); + [smartView deselectAll:nil]; +} + #pragma mark - NSTableViewDelegate methods - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row -- GitLab