From be1419c0a6ce48d89938f7c4e0f4bf85b7f2b8d0 Mon Sep 17 00:00:00 2001 From: Ming Rui Zhang <mingrui.zhang@savoirfairelinux.com> Date: Tue, 20 Oct 2020 12:11:09 -0400 Subject: [PATCH] wizardview: adapt the added best name and id logic in lrc Note: if the Displayname/alias is the same as the username, it should be the only line shown Gitlab: #129 Change-Id: I2c3dc8d304bd730a2ae114e4686c9ae899087c6b --- src/accountlistmodel.cpp | 7 +- src/calladapter.cpp | 24 ++--- src/conversationsadapter.cpp | 2 +- src/mainview/components/AccountComboBox.qml | 92 +++++++++-------- .../components/AccountComboBoxPopup.qml | 90 +++++++++-------- src/messagesadapter.cpp | 2 +- src/settingsadapter.cpp | 2 +- src/smartlistmodel.cpp | 12 +-- src/utils.cpp | 98 +------------------ src/utils.h | 9 -- src/utilsadapter.cpp | 17 ++-- 11 files changed, 140 insertions(+), 215 deletions(-) diff --git a/src/accountlistmodel.cpp b/src/accountlistmodel.cpp index c397b0f9e..309558da4 100644 --- a/src/accountlistmodel.cpp +++ b/src/accountlistmodel.cpp @@ -63,15 +63,16 @@ AccountListModel::data(const QModelIndex& index, int role) const return QVariant(); } - auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountList.at(index.row())); + auto accountId = accountList.at(index.row()); + auto& accountInfo = LRCInstance::accountModel().getAccountInfo(accountId); // Since we are using image provider right now, image url representation should be unique to // be able to use the image cache, account avatar will only be updated once PictureUid changed switch (role) { case Role::Alias: - return QVariant(Utils::bestNameForAccount(accountInfo)); + return QVariant(LRCInstance::accountModel().bestNameForAccount(accountId)); case Role::Username: - return QVariant(Utils::secondBestNameForAccount(accountInfo)); + return QVariant(LRCInstance::accountModel().bestIdForAccount(accountId)); case Role::Type: return QVariant(static_cast<int>(accountInfo.profileInfo.type)); case Role::Status: diff --git a/src/calladapter.cpp b/src/calladapter.cpp index 2ab9dc775..b2c1d29c3 100644 --- a/src/calladapter.cpp +++ b/src/calladapter.cpp @@ -185,8 +185,8 @@ CallAdapter::slotShowIncomingCallView(const QString& accountId, const conversati if (currentConvHasCall) { auto currentCall = callModel->getCall(currentConvInfo.callId); if ((currentCall.status == lrc::api::call::Status::CONNECTED - || currentCall.status == lrc::api::call::Status::IN_PROGRESS) - && !accountProperties.autoAnswer) { + || currentCall.status == lrc::api::call::Status::IN_PROGRESS) + && !accountProperties.autoAnswer) { showNotification(accountId, convInfo.uid); return; } @@ -271,9 +271,8 @@ CallAdapter::getConferencesInfos() data["isLocal"] = true; } else { try { - auto& contact = LRCInstance::getCurrentAccountInfo() - .contactModel->getContact(participant["uri"]); - bestName = Utils::bestNameForContact(contact); + bestName = LRCInstance::getCurrentAccountInfo() + .contactModel->bestNameForContact(participant["uri"]); } catch (...) { } } @@ -295,10 +294,8 @@ CallAdapter::showNotification(const QString& accountId, const QString& convUid) auto convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId); if (!accountId.isEmpty() && !convInfo.uid.isEmpty()) { auto& accInfo = LRCInstance::getAccountInfo(accountId); - if (!convInfo.participants.isEmpty()) { - auto& contact = accInfo.contactModel->getContact(convInfo.participants[0]); - from = Utils::bestNameForContact(contact); - } + if (!convInfo.participants.isEmpty()) + from = accInfo.contactModel->bestNameForContact(convInfo.participants[0]); } auto onClicked = [this, convInfo]() { @@ -356,7 +353,8 @@ CallAdapter::connectCallModel(const QString& accountId) try { auto& contact = LRCInstance::getCurrentAccountInfo() .contactModel->getContact(participant["uri"]); - bestName = Utils::bestNameForContact(contact); + bestName = LRCInstance::getCurrentAccountInfo() + .contactModel->bestNameForContact(participant["uri"]); if (participant["videoMuted"] == "true") data["avatar"] = contact.profileInfo.avatar; } catch (...) { @@ -480,6 +478,9 @@ CallAdapter::updateCallOverlay(const lrc::api::conversation::Info& convInfo) bool isAudioMuted = call->audioMuted && (call->status != lrc::api::call::Status::PAUSED); bool isVideoMuted = call->videoMuted && !isPaused && !call->isAudioOnly; bool isRecording = isRecordingThisCall(); + auto bestName = convInfo.participants.isEmpty() + ? QString() + : accInfo.contactModel->bestNameForContact(convInfo.participants[0]); emit updateOverlay(isPaused, isAudioOnly, @@ -488,8 +489,7 @@ CallAdapter::updateCallOverlay(const lrc::api::conversation::Info& convInfo) isRecording, accInfo.profileInfo.type == lrc::api::profile::Type::SIP, !convInfo.confId.isEmpty(), - Utils::bestNameForConversation(convInfo, - *LRCInstance::getCurrentConversationModel())); + bestName); } void diff --git a/src/conversationsadapter.cpp b/src/conversationsadapter.cpp index 27d836400..6ab90f462 100644 --- a/src/conversationsadapter.cpp +++ b/src/conversationsadapter.cpp @@ -144,7 +144,7 @@ ConversationsAdapter::onNewUnreadInteraction(const QString& accountId, || convUid != LRCInstance::getCurrentConvUid())) { auto& accInfo = LRCInstance::getAccountInfo(accountId); auto& contact = accInfo.contactModel->getContact(interaction.authorUri); - auto from = Utils::bestNameForContact(contact); + auto from = accInfo.contactModel->bestNameForContact(interaction.authorUri); auto onClicked = [this, accountId, convUid, uri = interaction.authorUri] { #ifdef Q_OS_WINDOWS emit LRCInstance::instance().notificationClicked(); diff --git a/src/mainview/components/AccountComboBox.qml b/src/mainview/components/AccountComboBox.qml index 76f2beb88..9b2a1b779 100644 --- a/src/mainview/components/AccountComboBox.qml +++ b/src/mainview/components/AccountComboBox.qml @@ -69,63 +69,75 @@ ComboBox { AccountListModel.Status) } - Text { - id: textUserAliasRoot - + ColumnLayout { anchors.left: userImageRoot.right anchors.leftMargin: 16 anchors.top: background.top - anchors.topMargin: 16 - text: textMetricsUserAliasRoot.elidedText - font.pointSize: JamiTheme.textFontSize - } + height: root.height - ResponsiveImage { - id: arrowDropDown + spacing: 0 - anchors.left: textUserAliasRoot.right - anchors.verticalCenter: textUserAliasRoot.verticalCenter + RowLayout { + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + Layout.topMargin: textUsernameRoot.visible ? root.height / 2 - implicitHeight : 0 - width: 24 - height: 24 + Text { + id: textUserAliasRoot - source: "qrc:/images/icons/round-arrow_drop_down-24px.svg" - } + Layout.alignment: Qt.AlignLeft - Text { - id: textUsernameRoot + text: textMetricsUserAliasRoot.elidedText + font.pointSize: JamiTheme.textFontSize - anchors.left: userImageRoot.right - anchors.leftMargin: 16 - anchors.top: textUserAliasRoot.bottom + TextMetrics { + id: textMetricsUserAliasRoot - text: textMetricsUsernameRoot.elidedText - font.pointSize: JamiTheme.textFontSize - color: JamiTheme.faddedLastInteractionFontColor - } + font: textUserAliasRoot.font + elide: Text.ElideRight + elideWidth: root.width - userImageRoot.width - settingsButton.width + - arrowDropDown.width - qrCodeGenerateButton.width - 55 - TextMetrics { - id: textMetricsUserAliasRoot + text: accountListModel.data(accountListModel.index(0,0), AccountListModel.Alias) + } + } - font: textUserAliasRoot.font - elide: Text.ElideRight - elideWidth: root.width - userImageRoot.width - settingsButton.width - - arrowDropDown.width - qrCodeGenerateButton.width - 55 + ResponsiveImage { + id: arrowDropDown - text: accountListModel.data(accountListModel.index(0,0), AccountListModel.Alias) - } + Layout.alignment: Qt.AlignRight - TextMetrics { - id: textMetricsUsernameRoot + width: 24 + height: 24 - font: textUsernameRoot.font - elide: Text.ElideRight - elideWidth: root.width - userImageRoot.width - settingsButton.width - - qrCodeGenerateButton.width - 55 + source: "qrc:/images/icons/round-arrow_drop_down-24px.svg" + } + } + + Text { + id: textUsernameRoot + + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + Layout.bottomMargin: root.height / 2 - implicitHeight + + visible: textMetricsUsernameRoot.text.length + + text: textMetricsUsernameRoot.elidedText + font.pointSize: JamiTheme.textFontSize + color: JamiTheme.faddedLastInteractionFontColor - text: accountListModel.data(accountListModel.index(0,0), - AccountListModel.Username) + TextMetrics { + id: textMetricsUsernameRoot + + font: textUsernameRoot.font + elide: Text.ElideRight + elideWidth: root.width - userImageRoot.width - settingsButton.width + - qrCodeGenerateButton.width - 55 + + text: accountListModel.data(accountListModel.index(0,0), + AccountListModel.Username) + } + } } background: Rectangle { diff --git a/src/mainview/components/AccountComboBoxPopup.qml b/src/mainview/components/AccountComboBoxPopup.qml index 70869f91e..25888f920 100644 --- a/src/mainview/components/AccountComboBoxPopup.qml +++ b/src/mainview/components/AccountComboBoxPopup.qml @@ -49,7 +49,14 @@ Popup { clip: true model: accountListModel implicitHeight: contentHeight - delegate: ItemDelegate { + delegate: Rectangle { + id: delegate + + width: root.width + height: accountComboBox.height + + color: JamiTheme.backgroundColor + AvatarImage { id: userImage @@ -71,68 +78,71 @@ Popup { } } - Text { - id: textUserAliasPopup - + ColumnLayout { anchors.left: userImage.right - anchors.leftMargin: 10 - anchors.top: itemComboBackground.top - anchors.topMargin: 15 + anchors.leftMargin: 16 + anchors.top: delegate.top - text: textMetricsUserAliasPopup.elidedText - font.pointSize: JamiTheme.textFontSize - } + height: delegate.height - Text { - id: textUsernamePopup + spacing: 0 - anchors.left: userImage.right - anchors.leftMargin: 10 - anchors.top: textUserAliasPopup.bottom + Text { + id: textUserAliasPopup - text: textMetricsUsernamePopup.elidedText - font.pointSize: JamiTheme.textFontSize - color: JamiTheme.faddedLastInteractionFontColor - } + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + Layout.topMargin: textUsernamePopup.visible ? + delegate.height / 2 - implicitHeight : 0 - TextMetrics { - id: textMetricsUserAliasPopup - elide: Text.ElideRight - elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30 - text: Alias - } + text: textMetricsUserAliasPopup.elidedText + font.pointSize: JamiTheme.textFontSize - TextMetrics { - id: textMetricsUsernamePopup - elide: Text.ElideRight - elideWidth: accountComboBox.width - userImage.width - settingsButton.width - 30 - text: Username - } + TextMetrics { + id: textMetricsUserAliasPopup + elide: Text.ElideRight + elideWidth: delegate.width - userImage.width - 80 + text: Alias + } + } - background: Rectangle { - id: itemComboBackground - color: JamiTheme.backgroundColor - implicitWidth: accountComboBox.width - implicitHeight: accountComboBox.height + Text { + id: textUsernamePopup + + Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter + Layout.bottomMargin: delegate.height / 2 - implicitHeight + + visible: textMetricsUsernamePopup.text.length + + text: textMetricsUsernamePopup.elidedText + font.pointSize: JamiTheme.textFontSize + color: JamiTheme.faddedLastInteractionFontColor + + TextMetrics { + id: textMetricsUsernamePopup + elide: Text.ElideRight + elideWidth: delegate.width - userImage.width - 80 + text: Username + } + } } MouseArea { anchors.fill: parent hoverEnabled: true onPressed: { - itemComboBackground.color = JamiTheme.pressColor + delegate.color = JamiTheme.pressColor } onReleased: { - itemComboBackground.color = JamiTheme.normalButtonColor + delegate.color = JamiTheme.normalButtonColor currentIndex = index root.close() AccountAdapter.accountChanged(index) } onEntered: { - itemComboBackground.color = JamiTheme.hoverColor + delegate.color = JamiTheme.hoverColor } onExited: { - itemComboBackground.color = JamiTheme.backgroundColor + delegate.color = JamiTheme.backgroundColor } } } diff --git a/src/messagesadapter.cpp b/src/messagesadapter.cpp index da93bd504..51849b7d2 100644 --- a/src/messagesadapter.cpp +++ b/src/messagesadapter.cpp @@ -448,7 +448,7 @@ MessagesAdapter::setConversationProfileData(const lrc::api::conversation::Info& } try { auto& contact = accInfo->contactModel->getContact(contactUri); - auto bestName = Utils::bestNameForConversation(convInfo, *convModel); + auto bestName = accInfo->contactModel->bestNameForContact(contactUri); setInvitation(contact.profileInfo.type == lrc::api::profile::Type::PENDING || contact.profileInfo.type == lrc::api::profile::Type::TEMPORARY, bestName, diff --git a/src/settingsadapter.cpp b/src/settingsadapter.cpp index a704512f8..cc91bbf40 100644 --- a/src/settingsadapter.cpp +++ b/src/settingsadapter.cpp @@ -260,7 +260,7 @@ SettingsAdapter::getCurrentAccount_Profile_Info_Type() QString SettingsAdapter::getAccountBestName() { - return Utils::bestNameForAccount(LRCInstance::getCurrentAccountInfo()); + return LRCInstance::accountModel().bestNameForAccount(LRCInstance::getCurrAccId()); } bool diff --git a/src/smartlistmodel.cpp b/src/smartlistmodel.cpp index 439a6c1f8..c1bda7feb 100644 --- a/src/smartlistmodel.cpp +++ b/src/smartlistmodel.cpp @@ -277,17 +277,13 @@ SmartListModel::getConversationItemData(const conversation::Info& item, // be able to use the image cache, account avatar will only be updated once PictureUid changed switch (role) { case Role::DisplayName: { - if (!item.participants.isEmpty()) { - auto& contact = contactModel->getContact(item.participants[0]); - return QVariant(Utils::bestNameForContact(contact)); - } + if (!item.participants.isEmpty()) + return QVariant(contactModel->bestNameForContact(item.participants[0])); return QVariant(""); } case Role::DisplayID: { - if (!item.participants.isEmpty()) { - auto& contact = contactModel->getContact(item.participants[0]); - return QVariant(Utils::bestIdForContact(contact)); - } + if (!item.participants.isEmpty()) + return QVariant(contactModel->bestIdForContact(item.participants[0])); return QVariant(""); } case Role::Presence: { diff --git a/src/utils.cpp b/src/utils.cpp index b2d066418..36cdf4f72 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -256,8 +256,8 @@ Utils::contactPhoto(const QString& contactUri, const QSize& size) auto& accountInfo = LRCInstance::accountModel().getAccountInfo(LRCInstance::getCurrAccId()); auto contactInfo = accountInfo.contactModel->getContact(contactUri); auto contactPhoto = contactInfo.profileInfo.avatar; - auto bestName = Utils::bestNameForContact(contactInfo); - auto bestId = Utils::bestIdForContact(contactInfo); + auto bestName = accountInfo.contactModel->bestNameForContact(contactUri); + auto bestId = accountInfo.contactModel->bestIdForContact(contactUri); if (accountInfo.profileInfo.type == lrc::api::profile::Type::SIP && contactInfo.profileInfo.type == lrc::api::profile::Type::TEMPORARY) { photo = Utils::fallbackAvatar(QString(), QString()); @@ -439,96 +439,6 @@ removeEndlines(const QString& str) return trimmed; } -QString -Utils::bestIdForConversation(const lrc::api::conversation::Info& conv, - const lrc::api::ConversationModel& model) -{ - auto contact = model.owner.contactModel->getContact(conv.participants[0]); - if (!contact.registeredName.isEmpty()) { - return removeEndlines(contact.registeredName); - } - return removeEndlines(contact.profileInfo.uri); -} - -QString -Utils::bestIdForAccount(const lrc::api::account::Info& account) -{ - if (!account.registeredName.isEmpty()) { - return removeEndlines(account.registeredName); - } - return removeEndlines(account.profileInfo.uri); -} - -QString -Utils::bestNameForAccount(const lrc::api::account::Info& account) -{ - if (account.profileInfo.alias.isEmpty()) { - return bestIdForAccount(account); - } - return account.profileInfo.alias; -} - -QString -Utils::bestIdForContact(const lrc::api::contact::Info& contact) -{ - if (!contact.registeredName.isEmpty()) { - return removeEndlines(contact.registeredName); - } - return removeEndlines(contact.profileInfo.uri); -} - -QString -Utils::bestNameForContact(const lrc::api::contact::Info& contact) -{ - auto alias = removeEndlines(contact.profileInfo.alias); - if (alias.length() == 0) { - return bestIdForContact(contact); - } - return alias; -} - -QString -Utils::bestNameForConversation(const lrc::api::conversation::Info& conv, - const lrc::api::ConversationModel& model) -{ - try { - auto contact = model.owner.contactModel->getContact(conv.participants[0]); - auto alias = removeEndlines(contact.profileInfo.alias); - if (alias.length() == 0) { - return bestIdForConversation(conv, model); - } - return alias; - } catch (...) { - } - return {}; -} - -/* - * Returns empty string if only infoHash is available, - * second best identifier otherwise. - */ -QString -Utils::secondBestNameForAccount(const lrc::api::account::Info& account) -{ - auto alias = removeEndlines(account.profileInfo.alias); - auto registeredName = removeEndlines(account.registeredName); - auto infoHash = account.profileInfo.uri; - - if (alias.length() != 0) { - if (registeredName.length() != 0) { - return registeredName; - } else { - return infoHash; - } - } else { - if (registeredName.length() != 0) { - return infoHash; - } else { - return ""; - } - } -} - lrc::api::profile::Type Utils::profileType(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model) @@ -828,8 +738,8 @@ Utils::accountPhoto(const lrc::api::account::Info& accountInfo, const QSize& siz QByteArray ba = accountInfo.profileInfo.avatar.toLocal8Bit(); photo = contactPhotoFromBase64(ba, nullptr); } else { - auto bestId = bestIdForAccount(accountInfo); - auto bestName = bestNameForAccount(accountInfo); + auto bestId = LRCInstance::accountModel().bestIdForAccount(accountInfo.id); + auto bestName = LRCInstance::accountModel().bestNameForAccount(accountInfo.id); QString letterStr = bestId == bestName ? QString() : bestName; QString prefix = accountInfo.profileInfo.type == lrc::api::profile::Type::RING ? "ring:" : "sip:"; diff --git a/src/utils.h b/src/utils.h index 2e74d0315..4a804e587 100644 --- a/src/utils.h +++ b/src/utils.h @@ -80,15 +80,6 @@ void removeOldVersions(); /* * LRC helpers */ -QString bestIdForConversation(const lrc::api::conversation::Info& conv, - const lrc::api::ConversationModel& model); -QString bestIdForAccount(const lrc::api::account::Info& account); -QString bestNameForAccount(const lrc::api::account::Info& account); -QString bestIdForContact(const lrc::api::contact::Info& contact); -QString bestNameForContact(const lrc::api::contact::Info& contact); -QString bestNameForConversation(const lrc::api::conversation::Info& conv, - const lrc::api::ConversationModel& model); -QString secondBestNameForAccount(const lrc::api::account::Info& account); lrc::api::profile::Type profileType(const lrc::api::conversation::Info& conv, const lrc::api::ConversationModel& model); std::string formatTimeString(const std::time_t& timestamp); diff --git a/src/utilsadapter.cpp b/src/utilsadapter.cpp index 137d4dd5e..d6846f34b 100644 --- a/src/utilsadapter.cpp +++ b/src/utilsadapter.cpp @@ -108,8 +108,11 @@ UtilsAdapter::checkStartupLink() const QString UtilsAdapter::getBestName(const QString& accountId, const QString& uid) { - auto* convModel = LRCInstance::getAccountInfo(accountId).conversationModel.get(); - return Utils::bestNameForConversation(convModel->getConversationForUID(uid), *convModel); + auto conv = LRCInstance::getConversationFromConvUid(uid); + if (!conv.participants.isEmpty()) + return LRCInstance::getAccountInfo(accountId).contactModel->bestNameForContact( + conv.participants[0]); + return QString(); } QString @@ -117,15 +120,17 @@ UtilsAdapter::getBestId(const QString& accountId) { if (accountId.isEmpty()) return {}; - auto& accountInfo = LRCInstance::getAccountInfo(accountId); - return Utils::bestIdForAccount(accountInfo); + return LRCInstance::accountModel().bestIdForAccount(accountId); } const QString UtilsAdapter::getBestId(const QString& accountId, const QString& uid) { - auto* convModel = LRCInstance::getAccountInfo(accountId).conversationModel.get(); - return Utils::bestIdForConversation(convModel->getConversationForUID(uid), *convModel); + auto conv = LRCInstance::getConversationFromConvUid(uid); + if (!conv.participants.isEmpty()) + return LRCInstance::getAccountInfo(accountId).contactModel->bestIdForContact( + conv.participants[0]); + return QString(); } int -- GitLab