1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-25 01:45:35 +02:00

conversationsadapter: clear source models when removing account

If we detect that the current account has been deleted, remove the proxy model source models immediately.

Gitlab: #1557
Change-Id: Iaf84198438b54e44d31a46870acdfa9569be6daa
This commit is contained in:
Andreas Traczyk 2024-02-05 13:07:01 -05:00
parent 24edba9a2f
commit f67a181e83
6 changed files with 47 additions and 12 deletions

View file

@ -22,6 +22,8 @@
#include "appsettingsmanager.h"
#include "qtutils.h"
#include "systemtray.h"
#include "lrcinstance.h"
#include "accountlistmodel.h"
#include <QtConcurrent/QtConcurrent>
@ -61,6 +63,14 @@ AccountAdapter::getModel()
return &(lrcInstance_->accountModel());
}
AccountAdapter*
AccountAdapter::create(QQmlEngine*, QJSEngine*)
{
return new AccountAdapter(qApp->property("AppSettingsManager").value<AppSettingsManager*>(),
qApp->property("SystemTray").value<SystemTray*>(),
qApp->property("LRCInstance").value<LRCInstance*>());
}
void
AccountAdapter::changeAccount(int row)
{

View file

@ -20,8 +20,7 @@
#include "qmladapterbase.h"
#include "systemtray.h"
#include "lrcinstance.h"
#include "api/accountmodel.h"
#include <QSettings>
#include <QString>
@ -29,6 +28,7 @@
#include <QApplication> // QML registration
class AppSettingsManager;
class SystemTray;
class AccountAdapter final : public QmlAdapterBase
{
@ -44,12 +44,7 @@ Q_SIGNALS:
void modelChanged();
public:
static AccountAdapter* create(QQmlEngine*, QJSEngine*)
{
return new AccountAdapter(qApp->property("AppSettingsManager").value<AppSettingsManager*>(),
qApp->property("SystemTray").value<SystemTray*>(),
qApp->property("LRCInstance").value<LRCInstance*>());
}
static AccountAdapter* create(QQmlEngine*, QJSEngine*);
explicit AccountAdapter(AppSettingsManager* settingsManager,
SystemTray* systemTray,

View file

@ -21,8 +21,6 @@
#include "qtutils.h"
#include "systemtray.h"
#include "qmlregister.h"
#include "qtutils.h"
#ifdef Q_OS_LINUX
#include "namedirectory.h"
@ -139,6 +137,12 @@ ConversationsAdapter::ConversationsAdapter(SystemTray* systemTray,
this,
&ConversationsAdapter::onCurrentAccountIdChanged);
connect(lrcInstance_,
&LRCInstance::currentAccountRemoved,
this,
&ConversationsAdapter::onCurrentAccountRemoved,
Qt::DirectConnection);
connectConversationModel();
}
@ -595,6 +599,14 @@ ConversationsAdapter::openDialogConversationWith(const QString& peerUri)
lrcInstance_->selectConversation(convInfo.uid);
}
void
ConversationsAdapter::onCurrentAccountRemoved()
{
// Unbind proxy model source models.
convModel_->bindSourceModel(nullptr);
searchModel_->bindSourceModel(nullptr);
}
void
ConversationsAdapter::connectConversationModel()
{

View file

@ -19,7 +19,6 @@
#pragma once
#include "lrcinstance.h"
#include "qmladapterbase.h"
#include "conversationlistmodel.h"
#include "searchresultslistmodel.h"
@ -91,6 +90,7 @@ Q_SIGNALS:
void conversationReady(const QString& convId);
private Q_SLOTS:
void onCurrentAccountRemoved();
void onCurrentAccountIdChanged();
// cross-account slots

View file

@ -70,6 +70,12 @@ LRCInstance::LRCInstance(migrateCallback willMigrateCb,
set_currentAccountAvatarSet(!getCurrentAccountInfo().profileInfo.avatar.isEmpty());
});
connect(&accountModel(),
&AccountModel::accountRemoved,
this,
&LRCInstance::onAccountRemoved,
Qt::DirectConnection);
// set the current account if any
auto accountList = accountModel().getAccountList();
if (accountList.size()) {
@ -469,4 +475,12 @@ VectorMapStringString
LRCInstance::getChannelList(const QString& accountId, const QString& uid)
{
return Lrc::getChannelList(accountId, uid);
}
}
void
LRCInstance::onAccountRemoved(const QString& accountId)
{
if (accountId != currentAccountId_)
return;
Q_EMIT currentAccountRemoved();
}

View file

@ -141,6 +141,7 @@ public:
Q_SIGNALS:
void accountListChanged();
void currentAccountRemoved();
void selectedConvUidChanged();
void restoreAppRequested();
void notificationClicked();
@ -148,6 +149,9 @@ Q_SIGNALS:
void draftSaved(const QString& convId);
void base64SwarmAvatarChanged();
private Q_SLOTS:
void onAccountRemoved(const QString& accountId);
private:
std::unique_ptr<Lrc> lrc_;
std::unique_ptr<AppVersionManager> updateManager_;