From f957600bb3b9709d5c2098494d70aa7d234d568b Mon Sep 17 00:00:00 2001
From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>
Date: Thu, 8 Sep 2016 16:32:54 -0400
Subject: [PATCH] improve RecentModel::getIndex(ContactMethod*) behaviour

ContactMethods which are associated with a Person are not contained
in the RecentModel as items. Thus we amend the getIndex function to
also check if the given ContactMethod is associated with a Person
which is an item in the model, instead of just returning an invalid
QModelIndex in this case.

Change-Id: I996d08bb7d9a550bd3f027348b350b3b0bc631b9
Tuleap: #956
---
 src/recentmodel.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/recentmodel.cpp b/src/recentmodel.cpp
index c4c2d02f..9e9a70fd 100644
--- a/src/recentmodel.cpp
+++ b/src/recentmodel.cpp
@@ -400,11 +400,16 @@ RecentModel::getIndex(Person *p) const
 QModelIndex
 RecentModel::getIndex(ContactMethod *cm) const
 {
+    // check if the CM is an item the RecentModel
     if (d_ptr->m_hCMsToNodes.contains(cm)) {
         if (auto node = d_ptr->m_hCMsToNodes.value(cm))
             return index(node->m_Index, 0);
     }
 
+    // otherwise, its possible the CM is contained within a Person item
+    if (auto person = cm->contact())
+        return getIndex(person);
+
     return {};
 }
 
-- 
GitLab