fix #LINQT-1994 wrong avatars
fix emoji initials for avatar
This commit is contained in:
parent
73358b7a25
commit
23234bafc4
4 changed files with 22 additions and 13 deletions
|
|
@ -117,21 +117,38 @@ QString Utils::getFamilyNameFromFullName(const QString &fullName) {
|
||||||
return nameSplitted.join(" ");
|
return nameSplitted.join(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::string u32_to_ascii(std::u32string const &s) {
|
||||||
|
std::string out;
|
||||||
|
std::transform(begin(s), end(s), back_inserter(out),
|
||||||
|
[](char32_t c) { return c < 128 ? static_cast<char>(c) : '?'; });
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
QString Utils::getInitials(const QString &username) {
|
QString Utils::getInitials(const QString &username) {
|
||||||
if (username.isEmpty()) return "";
|
if (username.isEmpty()) return "";
|
||||||
|
|
||||||
QRegularExpression regex("[\\s\\.]+");
|
QRegularExpression regex("[\\s\\.]+");
|
||||||
QStringList words = username.split(regex); // Qt 5.14: Qt::SkipEmptyParts
|
QStringList words = username.split(regex); // Qt 5.14: Qt::SkipEmptyParts
|
||||||
QStringList initials;
|
|
||||||
auto str32 = words[0].toStdU32String();
|
|
||||||
std::u32string char32;
|
std::u32string char32;
|
||||||
|
auto str32 = words[0].toStdU32String();
|
||||||
char32 += str32[0];
|
char32 += str32[0];
|
||||||
|
|
||||||
|
// if name starts by an emoji, only return this one
|
||||||
|
QVector<uint> utf32_string = username.toUcs4();
|
||||||
|
auto code = utf32_string[0];
|
||||||
|
if (Utils::codepointIsEmoji(code)) return QString::fromStdU32String(char32);
|
||||||
|
|
||||||
|
QStringList initials;
|
||||||
initials << QString::fromStdU32String(char32);
|
initials << QString::fromStdU32String(char32);
|
||||||
for (int i = 1; i < words.size() && initials.size() <= 1; ++i) {
|
for (int i = 1; i < words.size() && initials.size() <= 1; ++i) {
|
||||||
if (words[i].size() > 0) {
|
if (words[i].size() > 0) {
|
||||||
str32 = words[i].toStdU32String();
|
str32 = words[i].toStdU32String();
|
||||||
char32[0] = str32[0];
|
char32[0] = str32[0];
|
||||||
initials << QString::fromStdU32String(char32);
|
initials << QString::fromStdU32String(char32);
|
||||||
|
std::string converted = u32_to_ascii(char32);
|
||||||
|
if (Utils::codepointIsEmoji(atoi(converted.c_str()))) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QLocale().toUpper(initials.join(""));
|
return QLocale().toUpper(initials.join(""));
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ ListView {
|
||||||
property var contactObj: UtilsCpp.findFriendByAddress(
|
property var contactObj: UtilsCpp.findFriendByAddress(
|
||||||
modelData.core.remoteAddress)
|
modelData.core.remoteAddress)
|
||||||
contact: contactObj?.value || null
|
contact: contactObj?.value || null
|
||||||
displayNameVal: modelData.core.displayName
|
_address: modelData.core.remoteAddress
|
||||||
secured: securityLevel === LinphoneEnums.SecurityLevel.EndToEndEncryptedAndVerified
|
secured: securityLevel === LinphoneEnums.SecurityLevel.EndToEndEncryptedAndVerified
|
||||||
width: Math.round(45 * DefaultStyle.dp)
|
width: Math.round(45 * DefaultStyle.dp)
|
||||||
height: Math.round(45 * DefaultStyle.dp)
|
height: Math.round(45 * DefaultStyle.dp)
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,7 @@ MessageInfosLayout {
|
||||||
Avatar {
|
Avatar {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
contact: listDelegate.contact
|
contact: listDelegate.contact
|
||||||
displayNameVal: contact
|
_address: modelData.address
|
||||||
? ""
|
|
||||||
: nameObj
|
|
||||||
? nameObj.value
|
|
||||||
: ""
|
|
||||||
Layout.preferredWidth: Math.round(45 * DefaultStyle.dp)
|
Layout.preferredWidth: Math.round(45 * DefaultStyle.dp)
|
||||||
Layout.preferredHeight: Math.round(45 * DefaultStyle.dp)
|
Layout.preferredHeight: Math.round(45 * DefaultStyle.dp)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,11 +37,7 @@ MessageInfosLayout {
|
||||||
Avatar {
|
Avatar {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
contact: contactObj?.value || null
|
contact: contactObj?.value || null
|
||||||
displayNameVal: contact
|
_address: modelData.address
|
||||||
? ""
|
|
||||||
: nameObj
|
|
||||||
? nameObj.value
|
|
||||||
: ""
|
|
||||||
Layout.preferredWidth: Math.round(45 * DefaultStyle.dp)
|
Layout.preferredWidth: Math.round(45 * DefaultStyle.dp)
|
||||||
Layout.preferredHeight: Math.round(45 * DefaultStyle.dp)
|
Layout.preferredHeight: Math.round(45 * DefaultStyle.dp)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue