From 728a5c3f6aa385c2fa18de9d1c6a888ba14bd5fa Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Tue, 10 Mar 2026 14:53:06 +0100 Subject: [PATCH] update call history list when new call incoming (somehow if juste the new call log is added, it ends at the end of the list when updating the whole list) fix #LINQT-2444 --- .../core/call-history/CallHistoryCore.cpp | 16 +++--- .../core/call-history/CallHistoryCore.hpp | 14 ++++-- .../core/call-history/CallHistoryList.cpp | 50 +++++++++++-------- .../core/call-history/CallHistoryList.hpp | 2 +- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/Linphone/core/call-history/CallHistoryCore.cpp b/Linphone/core/call-history/CallHistoryCore.cpp index 8994649dd..cf984a6e4 100644 --- a/Linphone/core/call-history/CallHistoryCore.cpp +++ b/Linphone/core/call-history/CallHistoryCore.cpp @@ -50,7 +50,8 @@ CallHistoryCore::CallHistoryCore(const std::shared_ptr &callL mStatus = LinphoneEnums::fromLinphone(callLog->getStatus()); mDate = QDateTime::fromMSecsSinceEpoch(callLog->getStartDate() * 1000); mIsOutgoing = callLog->getDir() == linphone::Call::Dir::Outgoing; - mDuration = QString::number(callLog->getDuration()); + mDuration = callLog->getDuration(); + mDurationString = QString::number(mDuration); mIsConference = callLog->wasConference(); mCallId = Utils::coreStringToAppString(callLog->getCallId()); if (mIsConference) { @@ -144,16 +145,17 @@ ConferenceInfoGui *CallHistoryCore::getConferenceInfoGui() const { return mConferenceInfo ? new ConferenceInfoGui(mConferenceInfo) : nullptr; } -QString CallHistoryCore::getDuration() const { +int CallHistoryCore::getDuration() const { return mDuration; } -void CallHistoryCore::setDuration(const QString &duration) { +QString CallHistoryCore::getDurationString() const { + return mDurationString; +} + +QDateTime CallHistoryCore::getStartDate() const { mustBeInMainThread(log().arg(Q_FUNC_INFO)); - if (mDuration != duration) { - mDuration = duration; - emit durationChanged(mDuration); - } + return mDate; } void CallHistoryCore::remove() { diff --git a/Linphone/core/call-history/CallHistoryCore.hpp b/Linphone/core/call-history/CallHistoryCore.hpp index b39364085..3eb09aef6 100644 --- a/Linphone/core/call-history/CallHistoryCore.hpp +++ b/Linphone/core/call-history/CallHistoryCore.hpp @@ -42,7 +42,7 @@ class CallHistoryCore : public QObject, public AbstractObject { Q_PROPERTY(ConferenceInfoGui *conferenceInfo READ getConferenceInfoGui CONSTANT) Q_PROPERTY(QDateTime date MEMBER mDate CONSTANT) Q_PROPERTY(LinphoneEnums::CallStatus status MEMBER mStatus CONSTANT) - Q_PROPERTY(QString duration READ getDuration WRITE setDuration NOTIFY durationChanged) + Q_PROPERTY(int duration READ getDuration NOTIFY durationChanged) public: static QSharedPointer create(const std::shared_ptr &callLogs); @@ -52,8 +52,10 @@ public: void setSelf(QSharedPointer me); ConferenceInfoGui *getConferenceInfoGui() const; - QString getDuration() const; - void setDuration(const QString &duration); + int getDuration() const; + QString getDurationString() const; + + QDateTime getStartDate() const; void onRemoved(const std::shared_ptr &updatedFriend); @@ -68,13 +70,15 @@ public: QString mCallId; signals: - void durationChanged(QString duration); + void durationChanged(int duration); + void durationStringChanged(QString duration); void displayNameChanged(); void friendUpdated(); // When a friend is created, this log is linked to it. void removed(); private: - QString mDuration; + int mDuration; + QString mDurationString; QSharedPointer mConferenceInfo = nullptr; std::shared_ptr mCallHistoryModel; std::shared_ptr mFriendModel; diff --git a/Linphone/core/call-history/CallHistoryList.cpp b/Linphone/core/call-history/CallHistoryList.cpp index 8b02d5184..c9db6ee18 100644 --- a/Linphone/core/call-history/CallHistoryList.cpp +++ b/Linphone/core/call-history/CallHistoryList.cpp @@ -56,11 +56,11 @@ CallHistoryList::~CallHistoryList() { void CallHistoryList::setSelf(QSharedPointer me) { mModelConnection = SafeConnection::create(me, CoreModel::getInstance()); - mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this]() { - clearData(); - emit listAboutToBeReset(); + mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this](bool signalReset) { + mustBeInMainThread(log().arg(Q_FUNC_INFO)); + if (signalReset) emit listAboutToBeReset(); mModelConnection->invokeToModel([this]() { - mustBeInLinphoneThread(getClassName()); + mustBeInLinphoneThread(Q_FUNC_INFO); // Avoid copy to lambdas QList> *callLogs = new QList>(); std::list> linphoneCallLogs; @@ -73,8 +73,13 @@ void CallHistoryList::setSelf(QSharedPointer me) { callLogs->push_front(model); } mModelConnection->invokeToCore([this, callLogs]() { - mustBeInMainThread(getClassName()); - resetData(*callLogs); + mustBeInMainThread(Q_FUNC_INFO); + beginResetModel(); + mList.clear(); + for (auto &item : *callLogs) { + mList.append(item); + } + endResetModel(); delete callLogs; }); }); @@ -84,21 +89,24 @@ void CallHistoryList::setSelf(QSharedPointer me) { mModelConnection->makeConnectToModel( &CoreModel::callLogUpdated, [this](const std::shared_ptr &core, const std::shared_ptr &callLog) { - QSharedPointer *callLogs = new QSharedPointer[1]; - auto model = createCallHistoryCore(callLog); - callLogs[0] = model; - mModelConnection->invokeToCore([this, callLogs]() { - auto oldLog = std::find_if(mList.begin(), mList.end(), [callLogs](QSharedPointer log) { - return (*callLogs)->mCallId == log.objectCast()->mCallId; - }); - toConnect(callLogs->get()); - if (oldLog == mList.end()) { // New - prepend(*callLogs); - } else { // Update (status, duration, etc …) - replace(oldLog->objectCast(), *callLogs); - } - delete[] callLogs; - }); + if (!callLog->getLocalAddress()->weakEqual( + CoreModel::getInstance()->getCore()->getDefaultAccount()->getParams()->getIdentityAddress())) { + lInfo() << "call log does not refer to current account, return"; + return; + } + emit lUpdate(false); + // auto callLogCore = createCallHistoryCore(callLog); + // mModelConnection->invokeToCore([this, callLogCore]() { + // auto oldLog = std::find_if(mList.begin(), mList.end(), [callLogCore](QSharedPointer log) { + // return (callLogCore)->mCallId == log.objectCast()->mCallId; + // }); + // toConnect(callLogCore.get()); + // if (oldLog == mList.end()) { // New + // prepend(callLogCore); + // } else { // Update (status, duration, etc …) + // replace(oldLog->objectCast(), callLogCore); + // } + // }); }); mModelConnection->makeConnectToCore(&CallHistoryList::lRemoveEntriesForAddress, [this](QString address) { mModelConnection->invokeToModel([this, address]() { diff --git a/Linphone/core/call-history/CallHistoryList.hpp b/Linphone/core/call-history/CallHistoryList.hpp index e91e233f4..1ef15fff4 100644 --- a/Linphone/core/call-history/CallHistoryList.hpp +++ b/Linphone/core/call-history/CallHistoryList.hpp @@ -59,7 +59,7 @@ public: // void displayMore(); signals: - void lUpdate(); + void lUpdate(bool signalReset = true); void lRemoveEntriesForAddress(QString address); void lRemoveAllEntries(); void listAboutToBeReset();