Skip to content

Commit

Permalink
Improve user display name detection heuristics
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danvratil committed Mar 31, 2019
1 parent 63d1af0 commit 383441e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/slackclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 383441e

Please sign in to comment.