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

This commit is contained in:
Gaelle Braud 2026-03-10 14:53:06 +01:00
parent dbfe9ee774
commit 8959cca74e
5 changed files with 49 additions and 37 deletions

View file

@ -51,7 +51,8 @@ CallHistoryCore::CallHistoryCore(const std::shared_ptr<linphone::CallLog> &callL
mStatus = LinphoneEnums::fromLinphone(callLog->getStatus()); mStatus = LinphoneEnums::fromLinphone(callLog->getStatus());
mDate = QDateTime::fromMSecsSinceEpoch(callLog->getStartDate() * 1000); mDate = QDateTime::fromMSecsSinceEpoch(callLog->getStartDate() * 1000);
mIsOutgoing = callLog->getDir() == linphone::Call::Dir::Outgoing; mIsOutgoing = callLog->getDir() == linphone::Call::Dir::Outgoing;
mDuration = QString::number(callLog->getDuration()); mDuration = callLog->getDuration();
mDurationString = QString::number(mDuration);
mIsConference = callLog->wasConference(); mIsConference = callLog->wasConference();
mCallId = Utils::coreStringToAppString(callLog->getCallId()); mCallId = Utils::coreStringToAppString(callLog->getCallId());
mHasChat = false; mHasChat = false;
@ -149,16 +150,17 @@ ConferenceInfoGui *CallHistoryCore::getConferenceInfoGui() const {
return mConferenceInfo ? new ConferenceInfoGui(mConferenceInfo) : nullptr; return mConferenceInfo ? new ConferenceInfoGui(mConferenceInfo) : nullptr;
} }
QString CallHistoryCore::getDuration() const { int CallHistoryCore::getDuration() const {
return mDuration; return mDuration;
} }
void CallHistoryCore::setDuration(const QString &duration) { QString CallHistoryCore::getDurationString() const {
mustBeInMainThread(log().arg(Q_FUNC_INFO)); return mDurationString;
if (mDuration != duration) {
mDuration = duration;
emit durationChanged(mDuration);
} }
QDateTime CallHistoryCore::getStartDate() const {
mustBeInMainThread(log().arg(Q_FUNC_INFO));
return mDate;
} }
std::shared_ptr<CallHistoryModel> CallHistoryCore::getModel() const { std::shared_ptr<CallHistoryModel> CallHistoryCore::getModel() const {

View file

@ -43,7 +43,7 @@ class CallHistoryCore : public QObject, public AbstractObject {
Q_PROPERTY(ConferenceInfoGui *conferenceInfo READ getConferenceInfoGui CONSTANT) Q_PROPERTY(ConferenceInfoGui *conferenceInfo READ getConferenceInfoGui CONSTANT)
Q_PROPERTY(QDateTime date MEMBER mDate CONSTANT) Q_PROPERTY(QDateTime date MEMBER mDate CONSTANT)
Q_PROPERTY(LinphoneEnums::CallStatus status MEMBER mStatus 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: public:
static QSharedPointer<CallHistoryCore> create(const std::shared_ptr<linphone::CallLog> &callLogs); static QSharedPointer<CallHistoryCore> create(const std::shared_ptr<linphone::CallLog> &callLogs);
@ -53,8 +53,10 @@ public:
void setSelf(QSharedPointer<CallHistoryCore> me); void setSelf(QSharedPointer<CallHistoryCore> me);
ConferenceInfoGui *getConferenceInfoGui() const; ConferenceInfoGui *getConferenceInfoGui() const;
QString getDuration() const; int getDuration() const;
void setDuration(const QString &duration); QString getDurationString() const;
QDateTime getStartDate() const;
std::shared_ptr<CallHistoryModel> getModel() const; std::shared_ptr<CallHistoryModel> getModel() const;
@ -71,13 +73,15 @@ public:
QString mCallId; QString mCallId;
signals: signals:
void durationChanged(QString duration); void durationChanged(int duration);
void durationStringChanged(QString duration);
void displayNameChanged(); void displayNameChanged();
void friendUpdated(); // When a friend is created, this log is linked to it. void friendUpdated(); // When a friend is created, this log is linked to it.
void removed(); void removed();
private: private:
QString mDuration; int mDuration;
QString mDurationString;
QSharedPointer<ConferenceInfoCore> mConferenceInfo = nullptr; QSharedPointer<ConferenceInfoCore> mConferenceInfo = nullptr;
bool mHasChat = false; bool mHasChat = false;
std::shared_ptr<CallHistoryModel> mCallHistoryModel; std::shared_ptr<CallHistoryModel> mCallHistoryModel;

View file

@ -56,11 +56,11 @@ CallHistoryList::~CallHistoryList() {
void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) { void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) {
mModelConnection = SafeConnection<CallHistoryList, CoreModel>::create(me, CoreModel::getInstance()); mModelConnection = SafeConnection<CallHistoryList, CoreModel>::create(me, CoreModel::getInstance());
mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&CallHistoryList::lUpdate, [this](bool signalReset) {
clearData(); mustBeInMainThread(log().arg(Q_FUNC_INFO));
emit listAboutToBeReset(); if (signalReset) emit listAboutToBeReset();
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {
mustBeInLinphoneThread(getClassName()); mustBeInLinphoneThread(Q_FUNC_INFO);
// Avoid copy to lambdas // Avoid copy to lambdas
QList<QSharedPointer<CallHistoryCore>> *callLogs = new QList<QSharedPointer<CallHistoryCore>>(); QList<QSharedPointer<CallHistoryCore>> *callLogs = new QList<QSharedPointer<CallHistoryCore>>();
std::list<std::shared_ptr<linphone::CallLog>> linphoneCallLogs; std::list<std::shared_ptr<linphone::CallLog>> linphoneCallLogs;
@ -73,8 +73,13 @@ void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) {
callLogs->push_front(model); callLogs->push_front(model);
} }
mModelConnection->invokeToCore([this, callLogs]() { mModelConnection->invokeToCore([this, callLogs]() {
mustBeInMainThread(getClassName()); mustBeInMainThread(Q_FUNC_INFO);
resetData<CallHistoryCore>(*callLogs); beginResetModel();
mList.clear();
for (auto &item : *callLogs) {
mList.append(item);
}
endResetModel();
delete callLogs; delete callLogs;
}); });
}); });
@ -84,21 +89,24 @@ void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) {
mModelConnection->makeConnectToModel( mModelConnection->makeConnectToModel(
&CoreModel::callLogUpdated, &CoreModel::callLogUpdated,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::CallLog> &callLog) { [this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::CallLog> &callLog) {
QSharedPointer<CallHistoryCore> *callLogs = new QSharedPointer<CallHistoryCore>[1]; if (!callLog->getLocalAddress()->weakEqual(
auto model = createCallHistoryCore(callLog); CoreModel::getInstance()->getCore()->getDefaultAccount()->getParams()->getIdentityAddress())) {
callLogs[0] = model; lInfo() << "call log does not refer to current account, return";
mModelConnection->invokeToCore([this, callLogs]() { return;
auto oldLog = std::find_if(mList.begin(), mList.end(), [callLogs](QSharedPointer<QObject> log) {
return (*callLogs)->mCallId == log.objectCast<CallHistoryCore>()->mCallId;
});
toConnect(callLogs->get());
if (oldLog == mList.end()) { // New
prepend(*callLogs);
} else { // Update (status, duration, etc …)
replace(oldLog->objectCast<CallHistoryCore>(), *callLogs);
} }
delete[] callLogs; emit lUpdate(false);
}); // auto callLogCore = createCallHistoryCore(callLog);
// mModelConnection->invokeToCore([this, callLogCore]() {
// auto oldLog = std::find_if(mList.begin(), mList.end(), [callLogCore](QSharedPointer<QObject> log) {
// return (callLogCore)->mCallId == log.objectCast<CallHistoryCore>()->mCallId;
// });
// toConnect(callLogCore.get());
// if (oldLog == mList.end()) { // New
// prepend(callLogCore);
// } else { // Update (status, duration, etc …)
// replace(oldLog->objectCast<CallHistoryCore>(), callLogCore);
// }
// });
}); });
mModelConnection->makeConnectToCore(&CallHistoryList::lRemoveEntriesForAddress, [this](QString address) { mModelConnection->makeConnectToCore(&CallHistoryList::lRemoveEntriesForAddress, [this](QString address) {
mModelConnection->invokeToModel([this, address]() { mModelConnection->invokeToModel([this, address]() {

View file

@ -59,7 +59,7 @@ public:
// void displayMore(); // void displayMore();
signals: signals:
void lUpdate(); void lUpdate(bool signalReset = true);
void lRemoveEntriesForAddress(QString address); void lRemoveEntriesForAddress(QString address);
void lRemoveAllEntries(); void lRemoveAllEntries();
void listAboutToBeReset(); void listAboutToBeReset();

View file

@ -683,9 +683,7 @@ AbstractMainPage {
Layout.fillWidth: true Layout.fillWidth: true
} }
Text { Text {
text: UtilsCpp.formatElapsedTime( text: UtilsCpp.formatElapsedTime(modelData.core.duration,false)
modelData.core.duration,
false)
font { font {
pixelSize: Utils.getSizeWithScreenRatio(12) pixelSize: Utils.getSizeWithScreenRatio(12)
weight: Utils.getSizeWithScreenRatio(300) weight: Utils.getSizeWithScreenRatio(300)