From 2309eda866fa4e8a4ed37830fbc47e7fc0bc6e8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Thu, 27 Jul 2017 09:20:12 -0400
Subject: [PATCH] pixbufmanipulator: fix crash when CM has no name

If the contactmethod doesn't have a name, we should use the id and don't
try to get the first letter.

Change-Id: I748dd89a1580e3ea7e416f50d88b2e04cfc750e0
Reviewed-by: Philippe Gorley <philippe.gorley@savoirfairelinux.com>
---
 src/native/pixbufmanipulator.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/native/pixbufmanipulator.cpp b/src/native/pixbufmanipulator.cpp
index 1d9553b0..8559ce2d 100644
--- a/src/native/pixbufmanipulator.cpp
+++ b/src/native/pixbufmanipulator.cpp
@@ -44,7 +44,16 @@ PixbufManipulator::generateAvatar(const ContactMethod* cm) const
         if (hashName.size() > 0) {
             cm_number = hashName.at(0);
         }
-        letter = cm->bestName().toUpper().at(0);
+        // Get the letter to draw
+        if (!cm->bestName().isEmpty()) {
+            // Prioritize the name
+            letter = cm->bestName().toUpper().at(0);
+        } else if (!cm->bestId().isEmpty()) {
+            // If the contact has no name, use the id
+            letter = cm->bestId().toUpper().at(0);
+        } else {
+            // R for ring is used
+        }
     }
 
     bool ok;
-- 
GitLab