1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 12:03:18 +02:00

file_attachments: fix behaviour when changing conversations

Fixes an issue where the files that were loaded are not cleared
when switching conversations. Implements the correct behavior
for restoring the files as was done with text drafts.

GitLab: #1847
GitLab: #1528

Change-Id: Id04c9820d08f25ef247002da66d99ae893d8495a
This commit is contained in:
Andreas Hatziiliou 2024-10-01 17:59:26 -04:00 committed by Adrien Béraud
parent 112c6a4d7a
commit cb829676e3
5 changed files with 36 additions and 12 deletions

View file

@ -99,7 +99,7 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
}
case Role::Draft: {
if (!item.uid.isEmpty())
return lrcInstance_->getContentDraft(item.uid, item.accountId);
return lrcInstance_->getContentDraft(item.uid, item.accountId)["text"];
return {};
}
case Role::ActiveCallsCount: {
@ -137,7 +137,7 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
auto bestName = interaction.authorUri == accInfo.profileInfo.uri
? accInfo.accountModel->bestNameForAccount(accInfo.id)
: accInfo.contactModel->bestNameForContact(
interaction.authorUri);
interaction.authorUri);
lastInteractionBody
= interaction::getContactInteractionString(bestName,
interaction::to_action(

View file

@ -352,30 +352,36 @@ LRCInstance::stopAudioMeter()
});
}
QString
QVariantMap
LRCInstance::getContentDraft(const QString& convUid, const QString& accountId)
{
auto draftKey = accountId + "_" + convUid;
return contentDrafts_[draftKey];
QVariantMap draftMap;
draftMap["text"] = contentDrafts_[draftKey];
draftMap["files"] = fileDrafts_[draftKey];
return draftMap;
}
void
LRCInstance::setContentDraft(const QString& convUid,
const QString& accountId,
const QString& content)
const QString& textDraft,
const QList<QString>& filePathDraft)
{
if (accountId.isEmpty() || convUid.isEmpty()) {
return;
}
auto draftKey = accountId + "_" + convUid;
// prevent a senseless dataChanged signal from the
// model if nothing has changed
if (contentDrafts_[draftKey] == content)
if (contentDrafts_[draftKey] == textDraft && fileDrafts_[draftKey] == filePathDraft) {
return;
}
contentDrafts_[draftKey] = content;
contentDrafts_[draftKey] = textDraft;
fileDrafts_[draftKey] = filePathDraft;
// this signal is only needed to update the current smartlist
Q_EMIT draftSaved(convUid);
}

View file

@ -102,10 +102,12 @@ public:
Q_INVOKABLE void deselectConversation();
Q_INVOKABLE void makeConversationPermanent(const QString& convId = {},
const QString& accountId = {});
Q_INVOKABLE QString getContentDraft(const QString& convUid, const QString& accountId);
Q_INVOKABLE QVariantMap getContentDraft(const QString& convUid, const QString& accountId);
Q_INVOKABLE void setContentDraft(const QString& convUid,
const QString& accountId,
const QString& content);
const QString& textDraft,
const QList<QString>& filePathDraft);
Q_INVOKABLE int indexOfActiveCall(const QString& confId,
const QString& uri,
const QString& deviceId);
@ -157,6 +159,7 @@ private:
QString selectedConvUid_;
MapStringString contentDrafts_;
MapStringString lastConferences_;
MapStringListString fileDrafts_;
conversation::Info invalid {"", nullptr};

View file

@ -43,17 +43,31 @@ Rectangle {
color: JamiTheme.primaryBackgroundColor
function updateMessageDraft() {
LRCInstance.setContentDraft(previousConvId, previousAccountId, messageBar.text);
// Store the current files that have not been sent, if any. Do the same for the message draft.
var filePathDraft = [];
while(messageBar.fileContainer.filesToSendCount > 0) {
var currentIndex = messageBar.fileContainer.filesToSendListModel.index(0, 0);
var filePath = messageBar.fileContainer.filesToSendListModel.data(currentIndex, FilesToSend.FilePath);
filePathDraft.push(filePath);
messageBar.fileContainer.filesToSendListModel.removeFromPending(0);
}
LRCInstance.setContentDraft(previousConvId, previousAccountId, messageBar.text, filePathDraft);
previousConvId = CurrentConversation.id;
previousAccountId = CurrentAccount.id;
// turn off the button animations when switching convs
messageBar.animate = false;
messageBar.textAreaObj.clearText();
// restore the draft state of contents for a specific conversation
var restoredContent = LRCInstance.getContentDraft(CurrentConversation.id, CurrentAccount.id);
if (restoredContent) {
messageBar.textAreaObj.insertText(restoredContent);
messageBar.textAreaObj.insertText(restoredContent["text"]);
for (var i = 0; i < restoredContent["files"].length; ++i) {
messageBar.fileContainer.filesToSendListModel.addToPending(restoredContent["files"][i]);
}
}
}
Connections {

View file

@ -39,6 +39,7 @@ Q_DECLARE_LOGGING_CATEGORY(libclientLog)
// Typedefs (required to avoid '<' and '>' in the DBus XML)
typedef QMap<QString, QString> MapStringString;
typedef QMap<QString, QList<QString>> MapStringListString;
typedef QMap<QString, int> MapStringInt;
typedef QMap<QString, double> MapStringDouble;
typedef QMap<QPair<QString, QString>, bool> MapPairStrStrBool;