aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/room.cpp43
-rw-r--r--lib/room.h2
2 files changed, 42 insertions, 3 deletions
diff --git a/lib/room.cpp b/lib/room.cpp
index 6500366e..2c90955e 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1367,7 +1367,32 @@ QString Room::retryMessage(const QString& txnId)
[txnId] (const auto& evt) { return evt->transactionId() == txnId; });
Q_ASSERT(it != d->unsyncedEvents.end());
qDebug(EVENTS) << "Retrying transaction" << txnId;
- // TODO: Support retrying uploads
+ const auto& transferIt = d->fileTransfers.find(txnId);
+ if (transferIt != d->fileTransfers.end())
+ {
+ Q_ASSERT(transferIt->isUpload);
+ if (transferIt->status == FileTransferInfo::Completed)
+ {
+ qCDebug(MAIN) << "File for transaction" << txnId
+ << "has already been uploaded, bypassing re-upload";
+ } else {
+ if (isJobRunning(transferIt->job))
+ {
+ qCDebug(MAIN) << "Abandoning the upload job for transaction"
+ << txnId << "and starting again";
+ transferIt->job->abandon();
+ emit fileTransferFailed(txnId, tr("File upload will be retried"));
+ }
+ uploadFile(txnId,
+ QUrl::fromLocalFile(transferIt->localFileInfo.absoluteFilePath()));
+ // FIXME: Content type is no more passed here but it should
+ }
+ }
+ if (it->deliveryStatus() == EventStatus::ReachedServer)
+ {
+ qCWarning(MAIN) << "The previous attempt has reached the server; two"
+ " events are likely to be in the timeline after retry";
+ }
it->resetStatus();
return d->doSendEvent(it->event());
}
@@ -1378,7 +1403,21 @@ void Room::discardMessage(const QString& txnId)
[txnId] (const auto& evt) { return evt->transactionId() == txnId; });
Q_ASSERT(it != d->unsyncedEvents.end());
qDebug(EVENTS) << "Discarding transaction" << txnId;
- // TODO: Discard an ongoing upload if there is any
+ const auto& transferIt = d->fileTransfers.find(txnId);
+ if (transferIt != d->fileTransfers.end())
+ {
+ Q_ASSERT(transferIt->isUpload);
+ if (isJobRunning(transferIt->job))
+ {
+ transferIt->status = FileTransferInfo::Cancelled;
+ transferIt->job->abandon();
+ emit fileTransferFailed(txnId, tr("File upload cancelled"));
+ } else if (transferIt->status == FileTransferInfo::Completed)
+ {
+ qCWarning(MAIN) << "File for transaction" << txnId
+ << "has been uploaded but the message was discarded";
+ }
+ }
emit pendingEventAboutToDiscard(it - d->unsyncedEvents.begin());
d->unsyncedEvents.erase(it);
emit pendingEventDiscarded();
diff --git a/lib/room.h b/lib/room.h
index ce1c3dd3..2b6a2172 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -60,7 +60,7 @@ namespace QMatrixClient
Q_PROPERTY(QUrl localDir MEMBER localDir CONSTANT)
Q_PROPERTY(QUrl localPath MEMBER localPath CONSTANT)
public:
- enum Status { None, Started, Completed, Failed };
+ enum Status { None, Started, Completed, Failed, Cancelled };
Status status = None;
bool isUpload = false;
int progress = 0;