bug: verifies user still has an account before trying to download a media file

This commit is contained in:
otsmr 2026-02-07 23:01:29 +01:00
parent e8b9466e15
commit 90bf634f59
2 changed files with 46 additions and 9 deletions

View file

@ -23,8 +23,42 @@ Future<void> tryDownloadAllMediaFiles({bool force = false}) async {
await twonlyDB.mediaFilesDao.getAllMediaFilesPendingDownload(); await twonlyDB.mediaFilesDao.getAllMediaFilesPendingDownload();
for (final mediaFile in mediaFiles) { for (final mediaFile in mediaFiles) {
if (await canMediaFileBeDownloaded(mediaFile)) {
await startDownloadMedia(mediaFile, force); await startDownloadMedia(mediaFile, force);
} }
}
}
Future<bool> canMediaFileBeDownloaded(MediaFile mediaFile) async {
final messages =
await twonlyDB.messagesDao.getMessagesByMediaId(mediaFile.mediaId);
// Verify that the sender of the original image / message does still exists.
// If not delete the message as it can not be downloaded from the server anymore.
if (messages.length != 1) {
Log.error('A media for download must have one original message.');
return false;
}
if (messages.first.senderId == null) {
Log.error('A media for download must have a sender id.');
return false;
}
final contact =
await twonlyDB.contactsDao.getContactById(messages.first.senderId!);
if (contact == null || contact.accountDeleted) {
Log.info(
'Sender does not exists anymore. Delete media file and message.',
);
await twonlyDB.mediaFilesDao.deleteMediaFile(mediaFile.mediaId);
await twonlyDB.messagesDao.deleteMessagesById(messages.first.messageId);
return false;
}
return true;
} }
enum DownloadMediaTypes { enum DownloadMediaTypes {
@ -90,12 +124,10 @@ Future<void> handleDownloadStatusUpdate(TaskStatusUpdate update) async {
failed = false; failed = false;
} else { } else {
failed = true; failed = true;
if (update.responseStatusCode != null) {
Log.error( Log.error(
'Got invalid response status code: ${update.responseStatusCode}', 'Got invalid response status code: ${update.responseStatusCode}',
); );
} }
}
} else { } else {
Log.info('Got ${update.status} for $mediaId'); Log.info('Got ${update.status} for $mediaId');
return; return;

View file

@ -74,6 +74,14 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
} }
receiptId = receipt.receiptId; receiptId = receipt.receiptId;
final contact =
await twonlyDB.contactsDao.getContactById(receipt.contactId);
if (contact == null || contact.accountDeleted) {
Log.warn('Will not send message again as user does not exist anymore.');
await twonlyDB.receiptsDao.deleteReceipt(receiptId);
return null;
}
if (!onlyReturnEncryptedData && if (!onlyReturnEncryptedData &&
receipt.ackByServerAt != null && receipt.ackByServerAt != null &&
receipt.markForRetry == null) { receipt.markForRetry == null) {
@ -177,9 +185,6 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
if (receiptId != null) { if (receiptId != null) {
await twonlyDB.receiptsDao.deleteReceipt(receiptId); await twonlyDB.receiptsDao.deleteReceipt(receiptId);
} }
if (receipt != null) {
await twonlyDB.receiptsDao.deleteReceipt(receipt.receiptId);
}
} }
return null; return null;
} }