From 383441eaf119483f27ab9b86efd0fc4d9f4296c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Vr=C3=A1til?= Date: Mon, 1 Apr 2019 00:35:53 +0200 Subject: [PATCH] Improve user display name detection heuristics Use real_name when display_name is the same as username, fallback to display_name when real_name is empty or to username when even display_name is empty. --- src/slackclient.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/slackclient.cpp b/src/slackclient.cpp index 760cba5..f528f50 100644 --- a/src/slackclient.cpp +++ b/src/slackclient.cpp @@ -592,10 +592,15 @@ void SlackClient::parseUsers(QJsonObject data) { QVariantMap data; data.insert("id", user.value("id").toVariant()); - if (profile.contains("display_name")) { - data.insert("name", profile.value("display_name").toVariant()); + const auto name = user.value("name").toString(); + const auto realName = profile.value("real_name").toString(); + const auto displayName = profile.value("display_name").toString(); + if (displayName == name && !realName.isEmpty()) { + data.insert("name", realName); + } else if (!displayName.isEmpty()) { + data.insert("name", displayName); } else { - data.insert("name", user.value("name").toVariant()); + data.insert("name", name); } data.insert("presence", presence); storage.saveUser(data);