fix: prevent confetti smartlist selection when updating contacts

- needs https://gerrit-ring.savoirfairelinux.com/#/c/9195/

Change-Id: I9befd3c88c05d51a705843c4f32108ec8dc374a3
Reviewed-by: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
diff --git a/src/SmartViewVC.mm b/src/SmartViewVC.mm
index 726dad3..c0bdcb7 100755
--- a/src/SmartViewVC.mm
+++ b/src/SmartViewVC.mm
@@ -56,7 +56,7 @@
     __strong IBOutlet NSSegmentedControl *listTypeSelector;
     bool selectorIsPresent;
 
-    QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_, interactionStatusUpdatedConnection_, conversationClearedConnection;
+    QMetaObject::Connection modelSortedConnection_, modelUpdatedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_, interactionStatusUpdatedConnection_, conversationClearedConnection;
     NSTimer* statusUpdateDebounceTimer;
 
     lrc::api::ConversationModel* model_;
@@ -128,6 +128,7 @@
 
 -(void) reloadData
 {
+    NSLog(@"reload");
     [smartView deselectAll:nil];
 
     if (!model_->owner.contactModel->hasPendingRequests()) {
@@ -176,6 +177,18 @@
     [smartView scrollToBeginningOfDocument:nil];
 }
 
+-(void) reloadConversationWithUid:(NSString *)uid
+{
+    if (model_ != nil) {
+        auto it = getConversationFromUid(std::string([uid UTF8String]), *model_);
+        if (it != model_->allFilteredConversations().end()) {
+            NSIndexSet* indexSet = [NSIndexSet indexSetWithIndex:(it - model_->allFilteredConversations().begin())];
+            NSLog(@"reloadConversationWithUid: %@", uid);
+            [smartView reloadDataForRowIndexes:indexSet
+                                 columnIndexes:[NSIndexSet indexSetWithIndex:0]];
+        }
+    }
+}
 
 - (BOOL)setConversationModel:(lrc::api::ConversationModel *)conversationModel
 {
@@ -183,6 +196,7 @@
         model_ = conversationModel;
         selectedUid_.clear(); // Clear selected conversation as the selected account is being changed
         QObject::disconnect(modelSortedConnection_);
+        QObject::disconnect(modelUpdatedConnection_);
         QObject::disconnect(filterChangedConnection_);
         QObject::disconnect(newConversationConnection_);
         QObject::disconnect(conversationRemovedConnection_);
@@ -194,6 +208,10 @@
                                                       [self] (){
                                                           [self reloadData];
                                                       });
+            modelUpdatedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::conversationUpdated,
+                                                       [self] (const std::string& uid){
+                                                           [self reloadConversationWithUid: [NSString stringWithUTF8String:uid.c_str()]];
+                                                       });
             filterChangedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::filterChanged,
                                                         [self] (){
                                                             [self reloadData];
@@ -353,13 +371,13 @@
     [((ContextualTableCellView*) result) setContextualsControls:controls];
     [((ContextualTableCellView*) result) setShouldBlurParentView:YES];
 
-//    if (auto call = RecentModel::instance().getActiveCall(qIdx)) {
-//        [details setStringValue:call->roleData((int)Ring::Role::FormattedState).toString().toNSString()];
-//        [((ContextualTableCellView*) result) setActiveState:YES];
-//    } else {
-//        [details setStringValue:qIdx.data((int)Ring::Role::FormattedLastUsed).toString().toNSString()];
-//        [((ContextualTableCellView*) result) setActiveState:NO];
-//    }
+    //    if (auto call = RecentModel::instance().getActiveCall(qIdx)) {
+    //        [details setStringValue:call->roleData((int)Ring::Role::FormattedState).toString().toNSString()];
+    //        [((ContextualTableCellView*) result) setActiveState:YES];
+    //    } else {
+    //        [details setStringValue:qIdx.data((int)Ring::Role::FormattedLastUsed).toString().toNSString()];
+    //        [((ContextualTableCellView*) result) setActiveState:NO];
+    //    }
 
     NSTextField* unreadCount = [result viewWithTag:TXT_BUTTON_TAG];
     [unreadCount setHidden:(conversation.unreadMessages == 0)];
diff --git a/src/views/ContextualTableCellView.h b/src/views/ContextualTableCellView.h
index 38a962a..e5fcf03 100644
--- a/src/views/ContextualTableCellView.h
+++ b/src/views/ContextualTableCellView.h
@@ -27,6 +27,11 @@
 @property (nonatomic) NSMutableArray* contextualsControls;
 
 /**
+ * BOOL tracking if the mouse is hovering over the cell
+ */
+@property (nonatomic) BOOL isMouseOver;
+
+/**
  * BOOL specifying if controls should be presented when mouse is hover
  */
 @property (nonatomic) BOOL activeState;
diff --git a/src/views/ContextualTableCellView.mm b/src/views/ContextualTableCellView.mm
index cf5aa03..de2dfe4 100644
--- a/src/views/ContextualTableCellView.mm
+++ b/src/views/ContextualTableCellView.mm
@@ -31,7 +31,6 @@
 
 @implementation ContextualTableCellView
 
-
 - (void)updateTrackingAreas {
     [super updateTrackingAreas];
     [self ensureTrackingArea];
@@ -51,6 +50,10 @@
 
 - (void)prepareForReuse
 {
+    if (self.isMouseOver) {
+        return;
+    }
+
     for (NSView* item in self.contextualsControls) {
         [item setHidden:YES];
         if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView)
@@ -60,6 +63,8 @@
 
 - (void)mouseEntered:(NSEvent *)theEvent
 {
+    self.isMouseOver = true;
+
     if (self.activeState)
         return;
 
@@ -94,6 +99,8 @@
 
 - (void)mouseExited:(NSEvent *)theEvent
 {
+    self.isMouseOver = false;
+
     for (NSView* item in self.contextualsControls) {
         [item setHidden:YES];
         if(self.shouldBlurParentView && [item respondsToSelector:@selector(vibrantView)] && item.vibrantView) {