From eafb33e6b83f329b8f16a001c5ba69a0aa6c119e Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Fri, 9 Jun 2023 11:53:49 +0200 Subject: [PATCH] Optimizations: - Caching of displayname computation. - Optimize call logs access when building timelines. - Avoid building QTextSpeech if not needed. - Avoid loading emojis of picker on chat creation. Load them only on demand. --- .../chat-events/ChatMessageModel.cpp | 22 +++++-- .../chat-events/ChatMessageModel.hpp | 7 ++- .../components/chat-room/ChatRoomModel.cpp | 49 ++++++--------- .../components/chat-room/ChatRoomModel.hpp | 4 +- .../components/contacts/ContactsListModel.cpp | 27 ++++++-- .../components/contacts/ContactsListModel.hpp | 5 ++ .../other/text-to-speech/TextToSpeech.cpp | 11 +++- .../components/timeline/TimelineListModel.cpp | 35 +++++++++-- .../components/timeline/TimelineListModel.hpp | 1 + .../src/components/timeline/TimelineModel.cpp | 14 +++-- .../src/components/timeline/TimelineModel.hpp | 5 +- linphone-app/src/utils/Utils.cpp | 63 ++++++++++--------- linphone-app/src/utils/Utils.hpp | 1 + .../ui/modules/Linphone/Chat/Chat.qml | 2 +- .../ui/modules/Linphone/Chat/ChatEmojis.qml | 4 +- .../ui/views/App/Main/Conversation.qml | 1 + 16 files changed, 159 insertions(+), 92 deletions(-) diff --git a/linphone-app/src/components/chat-events/ChatMessageModel.cpp b/linphone-app/src/components/chat-events/ChatMessageModel.cpp index 14be8ca85..1f9a34636 100644 --- a/linphone-app/src/components/chat-events/ChatMessageModel.cpp +++ b/linphone-app/src/components/chat-events/ChatMessageModel.cpp @@ -116,14 +116,24 @@ QSharedPointer ChatMessageModel::getContentModel(std::shared_ptrgetFromAddress()) : ""; +QString ChatMessageModel::getFromDisplayName(){ + if(!mFromDisplayNameCache.isEmpty()) + return mFromDisplayNameCache; + if(!mChatMessage) + return ""; + mFromDisplayNameCache = Utils::getDisplayName(mChatMessage->getFromAddress()); + return mFromDisplayNameCache; } -QString ChatMessageModel::getFromDisplayNameReplyMessage() const{ - if( isReply()) - return Utils::getDisplayName(mChatMessage->getReplyMessageSenderAddress()); - else +QString ChatMessageModel::getFromDisplayNameReplyMessage(){ + if( isReply()){ + if(!fromDisplayNameReplyMessage.isEmpty()) + return fromDisplayNameReplyMessage; + if(!mChatMessage) + return ""; + fromDisplayNameReplyMessage = Utils::getDisplayName(mChatMessage->getReplyMessageSenderAddress()); + return fromDisplayNameReplyMessage; + }else return ""; } diff --git a/linphone-app/src/components/chat-events/ChatMessageModel.hpp b/linphone-app/src/components/chat-events/ChatMessageModel.hpp index 3f8a557d9..88a61c1d0 100644 --- a/linphone-app/src/components/chat-events/ChatMessageModel.hpp +++ b/linphone-app/src/components/chat-events/ChatMessageModel.hpp @@ -79,8 +79,8 @@ public: //---------------------------------------------------------------------------- - QString getFromDisplayName() const; - QString getFromDisplayNameReplyMessage() const; + QString getFromDisplayName(); + QString getFromDisplayNameReplyMessage(); QString getFromSipAddress() const; QString getToDisplayName() const; QString getToSipAddress() const; @@ -152,6 +152,9 @@ private: QSharedPointer mFileTransfertContent; QSharedPointer mParticipantImdnStateListModel; QSharedPointer mReplyChatMessageModel; + + QString mFromDisplayNameCache; + QString fromDisplayNameReplyMessage; }; Q_DECLARE_METATYPE(ChatMessageModel*) Q_DECLARE_METATYPE(QSharedPointer) diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.cpp b/linphone-app/src/components/chat-room/ChatRoomModel.cpp index a8911eaf9..038d9f097 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.cpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.cpp @@ -103,8 +103,8 @@ void ChatRoomModel::connectTo(ChatRoomListener * listener){ } // ----------------------------------------------------------------------------- -QSharedPointer ChatRoomModel::create(const std::shared_ptr& chatRoom, const std::list>& callLogs){ - QSharedPointer model = QSharedPointer::create(chatRoom, callLogs); +QSharedPointer ChatRoomModel::create(const std::shared_ptr& chatRoom, const QMap>>& lastCalls){ + QSharedPointer model = QSharedPointer::create(chatRoom, lastCalls); if(model){ model->mSelf = model; //chatRoom->addListener(model); @@ -113,7 +113,7 @@ QSharedPointer ChatRoomModel::create(const std::shared_ptr& chatRoom, const std::list>& callLogs, QObject * parent) : ProxyListModel(parent){ +ChatRoomModel::ChatRoomModel (const std::shared_ptr& chatRoom, const QMap>>& lastCalls, QObject * parent) : ProxyListModel(parent){ App::getInstance()->getEngine()->setObjectOwnership(this, QQmlEngine::CppOwnership);// Avoid QML to destroy it when passing by Q_INVOKABLE CoreManager *coreManager = CoreManager::getInstance(); mCoreHandlers = coreManager->getHandlers(); @@ -157,34 +157,23 @@ ChatRoomModel::ChatRoomModel (const std::shared_ptr& chatRoo connect(contact.get(), &ContactModel::contactUpdated, this, &ChatRoomModel::fullPeerAddressChanged); } } - - std::shared_ptr lastCall = nullptr; - QString peerAddress = getParticipantAddress(); - std::shared_ptr lLocalAddress = mChatRoom->getLocalAddress(); - QString localAddress = Utils::coreStringToAppString(lLocalAddress->asStringUriOnly()); - - if(callLogs.size() == 0) { - auto callHistory = CallsListModel::getCallHistory(peerAddress, localAddress); - if(callHistory.size() > 0) - lastCall = callHistory.front(); - }else{// Find the last call in list - std::shared_ptr lPeerAddress = Utils::interpretUrl(peerAddress); - if( lPeerAddress && lLocalAddress){ - auto itCallLog = std::find_if(callLogs.begin(), callLogs.end(), [lPeerAddress, lLocalAddress](std::shared_ptr c){ - return c->getLocalAddress()->weakEqual(lLocalAddress) && c->getRemoteAddress()->weakEqual(lPeerAddress); - }); - if( itCallLog != callLogs.end()) - lastCall = *itCallLog; + time_t callDate = 0; + if(lastCalls.size() > 0){ + QString peerAddress = getParticipantAddress(); + QString localAddress = Utils::coreStringToAppString(mChatRoom->getLocalAddress()->asStringUriOnly()); + + auto itLocal = lastCalls.find(localAddress); + if(itLocal != lastCalls.end()){ + auto itPeer = itLocal->find(peerAddress); + if(itPeer != itLocal->end()) { + callDate = itPeer.value()->getStartDate(); + if( itPeer.value()->getStatus() == linphone::Call::Status::Success ) + callDate += itPeer.value()->getDuration(); } + } } - - if(lastCall){ - auto callDate = lastCall->getStartDate(); - if( lastCall->getStatus() == linphone::Call::Status::Success ) - callDate += lastCall->getDuration(); - setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(std::max(mChatRoom->getLastUpdateTime(), callDate )*1000)); - }else - setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(mChatRoom->getLastUpdateTime()*1000)); + setLastUpdateTime(QDateTime::fromMSecsSinceEpoch(std::max(mChatRoom->getLastUpdateTime(), callDate )*1000)); + }else mParticipantListModel = nullptr; } @@ -986,7 +975,7 @@ void ChatRoomModel::initEntries(){ if( e->mType == ChatRoomModel::EntryType::MessageEntry){ connect(e.objectCast().get(), &ChatMessageModel::remove, this, &ChatRoomModel::removeEntry); auto model = e.objectCast().get(); - qDebug() << "Adding" << model->getReceivedTimestamp().toString("yyyy/MM/dd hh:mm:ss.zzz") << model->getTimestamp().toString("yyyy/MM/dd hh:mm:ss.zzz") << QString(model->getChatMessage()->getUtf8Text().c_str()).left(5); + qDebug() << "Adding" << model->getReceivedTimestamp().toString("yyyy/MM/dd hh:mm:ss.zzz") << model->getTimestamp().toString("yyyy/MM/dd hh:mm:ss.zzz") << (CoreManager::getInstance()->getSettingsModel()->isDeveloperSettingsAvailable() ? QString(model->getChatMessage()->getUtf8Text().c_str()).left(5) : ""); } mList.push_back(e); } diff --git a/linphone-app/src/components/chat-room/ChatRoomModel.hpp b/linphone-app/src/components/chat-room/ChatRoomModel.hpp index d07ad096e..c24f0a96c 100644 --- a/linphone-app/src/components/chat-room/ChatRoomModel.hpp +++ b/linphone-app/src/components/chat-room/ChatRoomModel.hpp @@ -98,8 +98,8 @@ public: Q_PROPERTY(bool entriesLoading READ isEntriesLoading WRITE setEntriesLoading NOTIFY entriesLoadingChanged) - static QSharedPointer create(const std::shared_ptr& chatRoom, const std::list>& callLogs = std::list>()); - ChatRoomModel (const std::shared_ptr& chatRoom, const std::list>& callLogs = std::list>(), QObject * parent = nullptr); + static QSharedPointer create(const std::shared_ptr& chatRoom, const QMap>>& lastCalls = QMap>>()); + ChatRoomModel (const std::shared_ptr& chatRoom, const QMap>>& lastCalls = QMap>>(), QObject * parent = nullptr); ~ChatRoomModel (); diff --git a/linphone-app/src/components/contacts/ContactsListModel.cpp b/linphone-app/src/components/contacts/ContactsListModel.cpp index 101e3934d..155149f4b 100644 --- a/linphone-app/src/components/contacts/ContactsListModel.cpp +++ b/linphone-app/src/components/contacts/ContactsListModel.cpp @@ -25,6 +25,7 @@ #include "components/contact/VcardModel.hpp" #include "components/core/CoreManager.hpp" #include "components/friend/FriendListListener.hpp" +#include "utils/Utils.hpp" #include "ContactsListModel.hpp" @@ -69,7 +70,9 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren for (int i = 0; i < count; ++i) { QSharedPointer contact = mList.takeAt(row).objectCast(); for(auto address : contact->getVcardModel()->getSipAddresses()){ - mOptimizedSearch.remove(address.toString()); + auto addressStr = address.toString(); + mOptimizedSearch.remove(addressStr); + mDisplayNameCache.remove(addressStr); } for(auto l : friendsList) @@ -86,8 +89,9 @@ bool ContactsListModel::removeRows (int row, int count, const QModelIndex &paren // ----------------------------------------------------------------------------- QSharedPointer ContactsListModel::findContactModelFromSipAddress (const QString &sipAddress) const { - if(mOptimizedSearch.contains(sipAddress)) - return mOptimizedSearch[sipAddress]; + auto result = mOptimizedSearch.find(sipAddress); + if(result != mOptimizedSearch.end()) + return result.value(); else return nullptr; } @@ -170,17 +174,32 @@ void ContactsListModel::addContact (QSharedPointer contact) { }); QObject::connect(contact.get(), &ContactModel::sipAddressAdded, this, [this, contact](const QString &sipAddress) { mOptimizedSearch[sipAddress] = contact; + mDisplayNameCache.remove(sipAddress); emit sipAddressAdded(contact, sipAddress); }); QObject::connect(contact.get(), &ContactModel::sipAddressRemoved, this, [this, contact](const QString &sipAddress) { mOptimizedSearch.remove(sipAddress); + mDisplayNameCache.remove(sipAddress); emit sipAddressRemoved(contact, sipAddress); }); add(contact); for(auto address : contact->getVcardModel()->getSipAddresses()){ - mOptimizedSearch[address.toString()] = contact; + auto addressStr = address.toString(); + mOptimizedSearch[addressStr] = contact; + mDisplayNameCache.remove(addressStr); } } +QString ContactsListModel::findDisplayNameFromCache(const QString& address) const{ + auto cached = mDisplayNameCache.find(address); + if(cached != mDisplayNameCache.end()) + return cached.value(); + else + return ""; +} + +void ContactsListModel::addDisplayNameToCache(const QString& address, const QString& displayName){ + mDisplayNameCache[address] = displayName; +} void ContactsListModel::update(){ beginResetModel(); diff --git a/linphone-app/src/components/contacts/ContactsListModel.hpp b/linphone-app/src/components/contacts/ContactsListModel.hpp index 93768a758..cd24e1b4b 100644 --- a/linphone-app/src/components/contacts/ContactsListModel.hpp +++ b/linphone-app/src/components/contacts/ContactsListModel.hpp @@ -48,11 +48,14 @@ public: QSharedPointer findContactModelFromSipAddress (const QString &sipAddress) const; QSharedPointer findContactModelFromUsername (const QString &username) const; + QString findDisplayNameFromCache(const QString& address)const; Q_INVOKABLE ContactModel *getContactModelFromAddress (const QString& address) const; Q_INVOKABLE ContactModel *addContact (VcardModel *vcardModel); Q_INVOKABLE void removeContact (ContactModel *contact); + void addDisplayNameToCache(const QString& address, const QString& displayName); + Q_INVOKABLE void cleanAvatars (); Q_INVOKABLE void update (); @@ -79,6 +82,8 @@ private: QMap> mOptimizedSearch; std::list> mLinphoneFriends; std::shared_ptr mFriendListListener; + + QMap mDisplayNameCache; }; #endif // CONTACTS_LIST_MODEL_H_ diff --git a/linphone-app/src/components/other/text-to-speech/TextToSpeech.cpp b/linphone-app/src/components/other/text-to-speech/TextToSpeech.cpp index b38c58629..e589bc433 100644 --- a/linphone-app/src/components/other/text-to-speech/TextToSpeech.cpp +++ b/linphone-app/src/components/other/text-to-speech/TextToSpeech.cpp @@ -31,14 +31,19 @@ #ifdef TEXTTOSPEECH_ENABLED TextToSpeech::TextToSpeech (QObject *parent) : QObject(parent) { - mQtTextToSpeech = new QTextToSpeech(this); - connect(mQtTextToSpeech, &QTextToSpeech::stateChanged, this, &TextToSpeech::onStateChanged); + } TextToSpeech::~TextToSpeech(){ - mQtTextToSpeech->deleteLater(); + if(mQtTextToSpeech) + mQtTextToSpeech->deleteLater(); } void TextToSpeech::say (const QString &text) { + if(!mQtTextToSpeech){ + mQtTextToSpeech = new QTextToSpeech(this); + connect(mQtTextToSpeech, &QTextToSpeech::stateChanged, this, &TextToSpeech::onStateChanged); + } + if(mQtTextToSpeech->volume() == 0.0) mQtTextToSpeech->setVolume(1.0); QStringList names; diff --git a/linphone-app/src/components/timeline/TimelineListModel.cpp b/linphone-app/src/components/timeline/TimelineListModel.cpp index 83027e8e8..96ec24ea7 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.cpp +++ b/linphone-app/src/components/timeline/TimelineListModel.cpp @@ -137,7 +137,7 @@ QSharedPointer TimelineListModel::getTimeline(std::shared_ptr model = TimelineModel::create(this, chatRoom); if(model){ connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool))); @@ -294,18 +294,32 @@ void TimelineListModel::updateTimelines () { // Add new. // Call logs optimization : store all the list and check on it for each chat room instead of loading call logs on each chat room. See TimelineModel() std::list> callLogs = coreManager->getCore()->getCallLogs(); -// + QList> models; + QMap>> optimizedCallLogs; + for(auto callLog : callLogs){ + QString localAddress = Utils::coreStringToAppString(callLog->getLocalAddress()->asStringUriOnly()); + QString peerAddress = Utils::coreStringToAppString(callLog->getRemoteAddress()->asStringUriOnly()); + auto itLocal = optimizedCallLogs.find(localAddress); + if(itLocal == optimizedCallLogs.end()){ + optimizedCallLogs[localAddress][peerAddress] = callLog; + }else{ + auto itPeer = itLocal->find(peerAddress); + if(itPeer == itLocal->end()) + optimizedCallLogs[localAddress][peerAddress] = callLog; + } + } + for(auto dbChatRoom : allChatRooms){ auto haveTimeline = getTimeline(dbChatRoom, false); if(!haveTimeline && dbChatRoom){// Create a new Timeline if needed - - QSharedPointer model = TimelineModel::create(this, dbChatRoom, callLogs); + QSharedPointer model = TimelineModel::create(this, dbChatRoom, optimizedCallLogs); if( model){ connect(model.get(), SIGNAL(selectedChanged(bool)), this, SLOT(onSelectedHasChanged(bool))); - add(model); + models << model; } } } + add(models); CoreManager::getInstance()->updateUnreadMessageCount(); } @@ -318,6 +332,17 @@ void TimelineListModel::add (QSharedPointer timeline){ emit countChanged(); } +void TimelineListModel::add (QList> timelines){ + for(auto timeline : timelines){ + auto chatRoomModel = timeline->getChatRoomModel(); + auto chatRoom = chatRoomModel->getChatRoom(); + connect(timeline.get(), &TimelineModel::chatRoomDeleted, this, &TimelineListModel::onChatRoomDeleted); + connect(chatRoomModel, &ChatRoomModel::lastUpdateTimeChanged, this, &TimelineListModel::updated); + } + ProxyListModel::add(timelines); + emit countChanged(); +} + void TimelineListModel::removeChatRoomModel(QSharedPointer model){ if(!model || (model->getChatRoom()->isEmpty() && (model->isReadOnly() || !model->isGroupEnabled()))){ auto itTimeline = mList.begin(); diff --git a/linphone-app/src/components/timeline/TimelineListModel.hpp b/linphone-app/src/components/timeline/TimelineListModel.hpp index 7e560c62f..0fa8b490e 100644 --- a/linphone-app/src/components/timeline/TimelineListModel.hpp +++ b/linphone-app/src/components/timeline/TimelineListModel.hpp @@ -51,6 +51,7 @@ public: QSharedPointer getChatRoomModel(ChatRoomModel * chatRoom); void add (QSharedPointer timeline); // Use to add a timeline that is not in Linphone list (like empty chat rooms that were hide by configuration) + void add (QList> timelines); Q_INVOKABLE void select(ChatRoomModel * chatRoomModel); void setSelectedCount(int selectedCount); diff --git a/linphone-app/src/components/timeline/TimelineModel.cpp b/linphone-app/src/components/timeline/TimelineModel.cpp index 57f6823c2..15ad1230a 100644 --- a/linphone-app/src/components/timeline/TimelineModel.cpp +++ b/linphone-app/src/components/timeline/TimelineModel.cpp @@ -66,9 +66,9 @@ void TimelineModel::connectTo(ChatRoomListener * listener){ } // ============================================================================= -QSharedPointer TimelineModel::create(TimelineListModel * mainList, std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent){ +QSharedPointer TimelineModel::create(TimelineListModel * mainList, std::shared_ptr chatRoom, const QMap>>& lastCalls, QObject *parent){ if((!chatRoom || chatRoom->getState() != linphone::ChatRoom::State::Deleted) && (!mainList || !mainList->getTimeline(chatRoom, false)) ) { - QSharedPointer model = QSharedPointer::create(chatRoom,callLogs, parent); + QSharedPointer model = QSharedPointer::create(chatRoom,lastCalls, parent); if(model && model->getChatRoomModel()){ return model; } @@ -77,11 +77,11 @@ QSharedPointer TimelineModel::create(TimelineListModel * mainList } TimelineModel::TimelineModel (std::shared_ptr chatRoom, QObject *parent) : QObject(parent) { - TimelineModel(chatRoom, std::list>(), parent); + TimelineModel(chatRoom, QMap>>(), parent); } -TimelineModel::TimelineModel (std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent) : QObject(parent) { +TimelineModel::TimelineModel (std::shared_ptr chatRoom, const QMap>>& lastCalls, QObject *parent) : QObject(parent) { App::getInstance()->getEngine()->setObjectOwnership(this, QQmlEngine::CppOwnership);// Avoid QML to destroy it when passing by Q_INVOKABLE - mChatRoomModel = ChatRoomModel::create(chatRoom, callLogs); + mChatRoomModel = ChatRoomModel::create(chatRoom, lastCalls); if( mChatRoomModel ){ CoreManager::getInstance()->handleChatRoomCreated(mChatRoomModel); QObject::connect(this, &TimelineModel::selectedChanged, this, &TimelineModel::updateUnreadCount); @@ -168,6 +168,8 @@ void TimelineModel::setSelected(const bool& selected){ << ", canHandleParticipants:"<< mChatRoomModel->canHandleParticipants() << ", isReadOnly:" << mChatRoomModel->isReadOnly() << ", state:" << mChatRoomModel->getState(); + }else{ + qInfo() << "Unselect "<< mChatRoomModel->getSubject(); } emit selectedChanged(mSelected); } @@ -254,4 +256,4 @@ void TimelineModel::onChatRoomStateChanged(){ mDelaySelection = false; setSelected(true); } -} \ No newline at end of file +} diff --git a/linphone-app/src/components/timeline/TimelineModel.hpp b/linphone-app/src/components/timeline/TimelineModel.hpp index 34cc2a044..551c91792 100644 --- a/linphone-app/src/components/timeline/TimelineModel.hpp +++ b/linphone-app/src/components/timeline/TimelineModel.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -39,9 +40,9 @@ class TimelineModel : public QObject { Q_OBJECT public: - static QSharedPointer create(TimelineListModel * mainList, std::shared_ptr chatRoom, const std::list>& callLogs = std::list>(), QObject *parent = Q_NULLPTR); + static QSharedPointer create(TimelineListModel * mainList, std::shared_ptr chatRoom, const QMap>>& lastCalls = QMap>>(), QObject *parent = Q_NULLPTR); TimelineModel (std::shared_ptr chatRoom, QObject *parent = Q_NULLPTR); - TimelineModel (std::shared_ptr chatRoom, const std::list>& callLogs, QObject *parent = Q_NULLPTR); + TimelineModel (std::shared_ptr chatRoom, const QMap>>& lastCalls, QObject *parent = Q_NULLPTR); TimelineModel(const TimelineModel * model); virtual ~TimelineModel(); diff --git a/linphone-app/src/utils/Utils.cpp b/linphone-app/src/utils/Utils.cpp index 2cb97c785..a0d3cee16 100644 --- a/linphone-app/src/utils/Utils.cpp +++ b/linphone-app/src/utils/Utils.cpp @@ -545,37 +545,42 @@ QString Utils::getDisplayName(const std::shared_ptr& ad std::shared_ptr cleanAddress = address->clone(); cleanAddress->clean(); QString qtAddress = Utils::coreStringToAppString(cleanAddress->asStringUriOnly()); - auto model = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(qtAddress); - if(model && model->getVcardModel()) - displayName = model->getVcardModel()->getUsername(); - else{ - // Try to get display from full address - displayName = QString::fromStdString(address->getDisplayName()); - if( displayName == ""){ - // Try to get display name from proxies - auto accounts = CoreManager::getInstance()->getCore()->getAccountList(); - for(auto accountIt = accounts.begin() ; displayName=="" && accountIt != accounts.end() ; ++accountIt){ - auto params = accountIt->get()->getParams(); - if(params){ - auto accountAddress = params->getIdentityAddress(); - if(accountAddress && accountAddress->weakEqual(address)){ - displayName = Utils::coreStringToAppString(accountAddress->getDisplayName()); + displayName = CoreManager::getInstance()->getContactsListModel()->findDisplayNameFromCache(qtAddress); + + if(displayName.isEmpty()){ + auto model = CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(qtAddress); + if(model && model->getVcardModel()) + displayName = model->getVcardModel()->getUsername(); + else{ + // Try to get display from full address + displayName = QString::fromStdString(address->getDisplayName()); + if( displayName == ""){ + // Try to get display name from proxies + auto accounts = CoreManager::getInstance()->getCore()->getAccountList(); + for(auto accountIt = accounts.begin() ; displayName=="" && accountIt != accounts.end() ; ++accountIt){ + auto params = accountIt->get()->getParams(); + if(params){ + auto accountAddress = params->getIdentityAddress(); + if(accountAddress && accountAddress->weakEqual(address)){ + displayName = Utils::coreStringToAppString(accountAddress->getDisplayName()); + } } } + if(displayName == ""){ + // Try to get display name from logs + auto callHistory = CoreManager::getInstance()->getCore()->getCallLogs(); + auto callLog = std::find_if(callHistory.begin(), callHistory.end(), [address](std::shared_ptr& cl){ + return cl->getRemoteAddress()->weakEqual(address); + }); + if(callLog != callHistory.end()) + displayName = QString::fromStdString((*callLog)->getRemoteAddress()->getDisplayName()); + if(displayName == "") + displayName = QString::fromStdString(address->getDisplayName()); + if(displayName == "") + displayName = Utils::coreStringToAppString(address->getUsername()); + } } - if(displayName == ""){ - // Try to get display name from logs - auto callHistory = CoreManager::getInstance()->getCore()->getCallLogs(); - auto callLog = std::find_if(callHistory.begin(), callHistory.end(), [address](std::shared_ptr& cl){ - return cl->getRemoteAddress()->weakEqual(address); - }); - if(callLog != callHistory.end()) - displayName = QString::fromStdString((*callLog)->getRemoteAddress()->getDisplayName()); - if(displayName == "") - displayName = QString::fromStdString(address->getDisplayName()); - if(displayName == "") - displayName = Utils::coreStringToAppString(address->getUsername()); - } + CoreManager::getInstance()->getContactsListModel()->addDisplayNameToCache(qtAddress, displayName); } } } @@ -872,4 +877,4 @@ QPixmap Utils::getMaskedPixmap(const QString& name, const QColor& color){ pxr.fill( color ); pxr.setMask( img.createMaskFromColor( Qt::transparent ) ); return pxr; -} \ No newline at end of file +} diff --git a/linphone-app/src/utils/Utils.hpp b/linphone-app/src/utils/Utils.hpp index 5d285c1c7..1242a37ac 100644 --- a/linphone-app/src/utils/Utils.hpp +++ b/linphone-app/src/utils/Utils.hpp @@ -62,6 +62,7 @@ public: Q_INVOKABLE static QString toDateTimeString(QDateTime date); Q_INVOKABLE static QString toTimeString(QDateTime date, const QString& format = "hh:mm:ss"); Q_INVOKABLE static QString toDateString(QDateTime date, const QString& format = ""); + static void cleanDisplayNameCache(const QString& address = "");// if "", clean all cache Q_INVOKABLE static QString getDisplayName(const QString& address); Q_INVOKABLE static QString getInitials(const QString& username); // Support UTF32 Q_INVOKABLE static QString toString(const LinphoneEnums::TunnelMode& mode); diff --git a/linphone-app/ui/modules/Linphone/Chat/Chat.qml b/linphone-app/ui/modules/Linphone/Chat/Chat.qml index f4dd2a1d1..7f19d6f81 100644 --- a/linphone-app/ui/modules/Linphone/Chat/Chat.qml +++ b/linphone-app/ui/modules/Linphone/Chat/Chat.qml @@ -103,7 +103,7 @@ Rectangle { if(!chat.isMoving && chat.atYBeginning && !chat.loadingEntries){// Moving has stopped. Check if we are at beginning chat.displaying = true console.log("Trying to load more entries") - Qt.callLater(container.proxyModel.loadMoreEntriesAsync()) + Qt.callLater(container.proxyModel.loadMoreEntriesAsync) } } // ----------------------------------------------------------------------- diff --git a/linphone-app/ui/modules/Linphone/Chat/ChatEmojis.qml b/linphone-app/ui/modules/Linphone/Chat/ChatEmojis.qml index 4609aa976..e7e8010ba 100644 --- a/linphone-app/ui/modules/Linphone/Chat/ChatEmojis.qml +++ b/linphone-app/ui/modules/Linphone/Chat/ChatEmojis.qml @@ -27,7 +27,7 @@ Item{ id: loader property bool toLoad : false anchors.fill: parent - active: true + active: false asynchronous: true //visible: status == Loader.Ready sourceComponent: @@ -49,4 +49,4 @@ Item{ } } } -} \ No newline at end of file +} diff --git a/linphone-app/ui/views/App/Main/Conversation.qml b/linphone-app/ui/views/App/Main/Conversation.qml index e3a41ec66..c537c83d5 100644 --- a/linphone-app/ui/views/App/Main/Conversation.qml +++ b/linphone-app/ui/views/App/Main/Conversation.qml @@ -584,6 +584,7 @@ ColumnLayout { anchors.verticalCenter: parent.verticalCenter color: BusyIndicatorStyle.alternateColor.color running: chatArea.tryingToLoadMoreEntries + onRunningChanged: console.log("Chat is busy: " +running) } // -------------------------------------------------------------------------