mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-03-03 13:56:45 +00:00
bug: verifies user still has an account before trying to download a media file
This commit is contained in:
parent
e8b9466e15
commit
90bf634f59
2 changed files with 46 additions and 9 deletions
|
|
@ -23,10 +23,44 @@ Future<void> tryDownloadAllMediaFiles({bool force = false}) async {
|
|||
await twonlyDB.mediaFilesDao.getAllMediaFilesPendingDownload();
|
||||
|
||||
for (final mediaFile in mediaFiles) {
|
||||
await startDownloadMedia(mediaFile, force);
|
||||
if (await canMediaFileBeDownloaded(mediaFile)) {
|
||||
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 {
|
||||
video,
|
||||
image,
|
||||
|
|
@ -90,11 +124,9 @@ Future<void> handleDownloadStatusUpdate(TaskStatusUpdate update) async {
|
|||
failed = false;
|
||||
} else {
|
||||
failed = true;
|
||||
if (update.responseStatusCode != null) {
|
||||
Log.error(
|
||||
'Got invalid response status code: ${update.responseStatusCode}',
|
||||
);
|
||||
}
|
||||
Log.error(
|
||||
'Got invalid response status code: ${update.responseStatusCode}',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Log.info('Got ${update.status} for $mediaId');
|
||||
|
|
|
|||
|
|
@ -74,6 +74,14 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
|
|||
}
|
||||
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 &&
|
||||
receipt.ackByServerAt != null &&
|
||||
receipt.markForRetry == null) {
|
||||
|
|
@ -177,9 +185,6 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
|
|||
if (receiptId != null) {
|
||||
await twonlyDB.receiptsDao.deleteReceipt(receiptId);
|
||||
}
|
||||
if (receipt != null) {
|
||||
await twonlyDB.receiptsDao.deleteReceipt(receipt.receiptId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue