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());
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());
mHasChat = false;
@ -149,16 +150,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;
}
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(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<CallHistoryCore> create(const std::shared_ptr<linphone::CallLog> &callLogs);
@ -53,8 +53,10 @@ public:
void setSelf(QSharedPointer<CallHistoryCore> me);
ConferenceInfoGui *getConferenceInfoGui() const;
QString getDuration() const;
void setDuration(const QString &duration);
int getDuration() const;
QString getDurationString() const;
QDateTime getStartDate() const;
std::shared_ptr<CallHistoryModel> getModel() const;
@ -71,13 +73,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<ConferenceInfoCore> mConferenceInfo = nullptr;
bool mHasChat = false;
std::shared_ptr<CallHistoryModel> mCallHistoryModel;

View file

@ -56,11 +56,11 @@ CallHistoryList::~CallHistoryList() {
void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) {
mModelConnection = SafeConnection<CallHistoryList, CoreModel>::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<QSharedPointer<CallHistoryCore>> *callLogs = new QList<QSharedPointer<CallHistoryCore>>();
std::list<std::shared_ptr<linphone::CallLog>> linphoneCallLogs;
@ -73,8 +73,13 @@ void CallHistoryList::setSelf(QSharedPointer<CallHistoryList> me) {
callLogs->push_front(model);
}
mModelConnection->invokeToCore([this, callLogs]() {
mustBeInMainThread(getClassName());
resetData<CallHistoryCore>(*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<CallHistoryList> me) {
mModelConnection->makeConnectToModel(
&CoreModel::callLogUpdated,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::CallLog> &callLog) {
QSharedPointer<CallHistoryCore> *callLogs = new QSharedPointer<CallHistoryCore>[1];
auto model = createCallHistoryCore(callLog);
callLogs[0] = model;
mModelConnection->invokeToCore([this, callLogs]() {
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;
});
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<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->invokeToModel([this, address]() {

View file

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

View file

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