diff --git a/src/lrcinstance.cpp b/src/lrcinstance.cpp index 8f01703d7c867705b3c6ba4cbe551f9540b452a5..0e3bd09a20f53b833c9809a19c76d98aeec49257 100644 --- a/src/lrcinstance.cpp +++ b/src/lrcinstance.cpp @@ -433,11 +433,7 @@ void LRCInstance::set_selectedConvUid(QString selectedConvUid) { if (selectedConvUid_ != selectedConvUid) { - auto& accInfo = accountModel().getAccountInfo(get_currentAccountId()); - auto& convModel = accInfo.conversationModel; - convModel->clearInteractionsCache(selectedConvUid_); - selectedConvUid_ = selectedConvUid; Q_EMIT selectedConvUidChanged(); } -} +} \ No newline at end of file diff --git a/src/mainview/components/SmartListItemDelegate.qml b/src/mainview/components/SmartListItemDelegate.qml index 6797e4cc772e9fb1fbf81461844570ea69b84a07..612e95061767b2a61165ea7f5ff8f1b68412b347 100644 --- a/src/mainview/components/SmartListItemDelegate.qml +++ b/src/mainview/components/SmartListItemDelegate.qml @@ -33,8 +33,23 @@ ItemDelegate { width: ListView.view.width height: JamiTheme.smartListItemHeight - function convUid() { - return UID + property string accountId: "" + property string convId: "" + + onVisibleChanged: { + if (visible) + return + UtilsAdapter.clearInteractionsCache(root.accountId, root.convId) + } + + Component.onCompleted: { + // Store to avoid undefined at the end + root.accountId = CurrentAccount.id + root.convId = UID + } + + Component.onDestruction: { + UtilsAdapter.clearInteractionsCache(root.accountId, root.convId) } RowLayout { diff --git a/src/utilsadapter.cpp b/src/utilsadapter.cpp index 0352cd76b453324f3834b88056257dc61334273c..2d470aa4bb414f5ef4cb2c7b70d7d1cc6cc6abcb 100644 --- a/src/utilsadapter.cpp +++ b/src/utilsadapter.cpp @@ -399,4 +399,16 @@ UtilsAdapter::monitor(const bool& continuous) Q_EMIT debugMessageReceived(data); }); lrcInstance_->monitor(continuous); +} + +void +UtilsAdapter::clearInteractionsCache(const QString& accountId, const QString& convId) +{ + if (lrcInstance_->get_selectedConvUid() != convId) { + try { + auto& accInfo = lrcInstance_->accountModel().getAccountInfo(accountId); + auto& convModel = accInfo.conversationModel; + convModel->clearInteractionsCache(convId); + } catch (...) {} + } } \ No newline at end of file diff --git a/src/utilsadapter.h b/src/utilsadapter.h index 2f595bab4e456465f2541588ee4957fb8da40742..7a92b68db7e71c2a9b3c52311e282ec049b6229f 100644 --- a/src/utilsadapter.h +++ b/src/utilsadapter.h @@ -89,6 +89,7 @@ public: Q_INVOKABLE void setRunOnStartUp(bool state); Q_INVOKABLE void setDownloadPath(QString dir); Q_INVOKABLE void monitor(const bool& continuous); + Q_INVOKABLE void clearInteractionsCache(const QString& accountId, const QString& convUid); Q_SIGNALS: void debugMessageReceived(const QString& message);