Merge remote-tracking branch 'handydevcom/dont_update_model_when_forwarding_message' into aurora_beta

This commit is contained in:
Nikolai Sinyov 2024-07-02 16:25:01 +03:00
commit 74cdee5652
4 changed files with 40 additions and 2 deletions

View file

@ -91,6 +91,7 @@ public:
QVector<int> updateLastMessage(const QVariantMap &message);
QVector<int> updateGroup(const TDLibWrapper::Group *group);
QVector<int> updateSecretChat(const QVariantMap &secretChatDetails);
ChatData* clone();
TDLibWrapper *tdLibWrapper;
public:
@ -384,6 +385,24 @@ QVector<int> ChatListModel::ChatData::updateSecretChat(const QVariantMap &secret
return changedRoles;
}
ChatListModel::ChatData* ChatListModel::ChatData::clone() {
QVariantMap clonedChatData;
QList<QString> keys = chatData.keys();
for(int i = 0; i < keys.count(); i++) {
clonedChatData.insert(keys[i], QVariant(chatData[keys[i]]));
}
ChatData* res = new ChatData(tdLibWrapper, clonedChatData);
res->chatId = chatId;
res->order = order;
res->groupId = groupId;
res->verified = verified;
res->chatType = chatType;
res->memberStatus = memberStatus;
res->secretChatState = secretChatState;
return res;
}
ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper, AppSettings *appSettings) : showHiddenChats(false)
{
this->tdLibWrapper = tdLibWrapper;
@ -426,6 +445,15 @@ ChatListModel::~ChatListModel()
qDeleteAll(hiddenChats.values());
}
ChatListModel* ChatListModel::clone() {
ChatListModel* res = new ChatListModel(tdLibWrapper, appSettings);
res->relativeTimeRefreshTimer->stop();
for(int i = 0; i < chatList.count(); i++) {
res->chatList.append(chatList.at(i)->clone());
}
return res;
}
void ChatListModel::reset()
{
chatList.clear();

View file

@ -75,6 +75,7 @@ public:
bool showAllChats() const;
void setShowAllChats(bool showAll);
ChatListModel* clone();
private slots:
void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation);

View file

@ -33,7 +33,9 @@ ChatPermissionFilterModel::ChatPermissionFilterModel(QObject *parent) : QSortFil
void ChatPermissionFilterModel::setSource(QObject *model)
{
setSourceModel(qobject_cast<ChatListModel*>(model));
ChatListModel* chatListModel = qobject_cast<ChatListModel*>(model);
ChatListModel* chatListModelClone = chatListModel->clone();
setSourceModel(chatListModelClone);
}
void ChatPermissionFilterModel::setSourceModel(QAbstractItemModel *model)
@ -45,6 +47,13 @@ void ChatPermissionFilterModel::setSourceModel(QAbstractItemModel *model)
}
}
ChatPermissionFilterModel::~ChatPermissionFilterModel() {
QAbstractItemModel* _sourceModel = sourceModel();
if(_sourceModel != nullptr) {
delete _sourceModel;
}
}
TDLibWrapper *ChatPermissionFilterModel::getTDLibWrapper() const
{
return tdLibWrapper;

View file

@ -31,7 +31,7 @@ class ChatPermissionFilterModel : public QSortFilterProxyModel
public:
ChatPermissionFilterModel(QObject *parent = Q_NULLPTR);
~ChatPermissionFilterModel() override;
TDLibWrapper *getTDLibWrapper() const;
void setTDLibWrapper(QObject* obj);