fix(service): Fix downloading a file again
This commit is contained in:
parent
c8c0239e36
commit
79226f6ca8
@ -1348,20 +1348,21 @@ class XmppService {
|
|||||||
// The dimensions of the file, if available.
|
// The dimensions of the file, if available.
|
||||||
final dimensions = _getDimensions(event);
|
final dimensions = _getDimensions(event);
|
||||||
// Indicates if we should auto-download the file, if a file is specified in the message
|
// Indicates if we should auto-download the file, if a file is specified in the message
|
||||||
final shouldDownload = await _shouldDownloadFile(conversationJid);
|
final shouldDownload =
|
||||||
|
isFileEmbedded && await _shouldDownloadFile(conversationJid);
|
||||||
// Indicates if a notification should be created for the message.
|
// Indicates if a notification should be created for the message.
|
||||||
// The way this variable works is that if we can download the file, then the
|
// The way this variable works is that if we can download the file, then the
|
||||||
// notification will be created later by the [DownloadService]. If we don't want the
|
// notification will be created later by the [DownloadService]. If we don't want the
|
||||||
// download to happen automatically, then the notification should happen immediately.
|
// download to happen automatically, then the notification should happen immediately.
|
||||||
var shouldNotify = !(isFileEmbedded && isInRoster && shouldDownload);
|
var shouldNotify = !(isInRoster && shouldDownload);
|
||||||
// A guess for the Mime type of the embedded file.
|
// A guess for the Mime type of the embedded file.
|
||||||
var mimeGuess = _getMimeGuess(event);
|
var mimeGuess = _getMimeGuess(event);
|
||||||
|
|
||||||
FileMetadata? fileMetadata;
|
FileMetadataWrapper? fileMetadata;
|
||||||
if (isFileEmbedded) {
|
if (isFileEmbedded) {
|
||||||
final thumbnail = _getThumbnailData(event);
|
final thumbnail = _getThumbnailData(event);
|
||||||
fileMetadata =
|
fileMetadata =
|
||||||
(await GetIt.I.get<FilesService>().createFileMetadataIfRequired(
|
await GetIt.I.get<FilesService>().createFileMetadataIfRequired(
|
||||||
embeddedFile!,
|
embeddedFile!,
|
||||||
mimeGuess,
|
mimeGuess,
|
||||||
embeddedFile.size,
|
embeddedFile.size,
|
||||||
@ -1370,8 +1371,7 @@ class XmppService {
|
|||||||
thumbnail != null ? 'blurhash' : null,
|
thumbnail != null ? 'blurhash' : null,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
createHashPointers: false,
|
createHashPointers: false,
|
||||||
))
|
);
|
||||||
.fileMetadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the message in the database
|
// Create the message in the database
|
||||||
@ -1386,15 +1386,17 @@ class XmppService {
|
|||||||
event.encrypted,
|
event.encrypted,
|
||||||
event.messageProcessingHints?.contains(MessageProcessingHint.noStore) ??
|
event.messageProcessingHints?.contains(MessageProcessingHint.noStore) ??
|
||||||
false,
|
false,
|
||||||
fileMetadata: fileMetadata,
|
fileMetadata: fileMetadata?.fileMetadata,
|
||||||
quoteId: replyId,
|
quoteId: replyId,
|
||||||
originId: event.stanzaId.originId,
|
originId: event.stanzaId.originId,
|
||||||
errorType: errorTypeFromException(event.other['encryption_error']),
|
errorType: errorTypeFromException(event.other['encryption_error']),
|
||||||
stickerPackId: event.stickerPackId,
|
stickerPackId: event.stickerPackId,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Attempt to auto-download the embedded file
|
// Attempt to auto-download the embedded file, if
|
||||||
if (isFileEmbedded && shouldDownload && fileMetadata?.path == null) {
|
// - there is a file attached and
|
||||||
|
// - we have not retrieved the file metadata
|
||||||
|
if (shouldDownload && !(fileMetadata?.retrieved ?? false)) {
|
||||||
final fts = GetIt.I.get<HttpFileTransferService>();
|
final fts = GetIt.I.get<HttpFileTransferService>();
|
||||||
final metadata = await peekFile(embeddedFile!.urls.first);
|
final metadata = await peekFile(embeddedFile!.urls.first);
|
||||||
|
|
||||||
@ -1422,10 +1424,10 @@ class XmppService {
|
|||||||
} else {
|
} else {
|
||||||
// Make sure we create the notification
|
// Make sure we create the notification
|
||||||
shouldNotify = true;
|
shouldNotify = true;
|
||||||
|
|
||||||
if (fileMetadata?.path != null) {
|
|
||||||
_log.info('Not downloading file as we already have it locally');
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (fileMetadata?.retrieved ?? false) {
|
||||||
|
_log.info('Not downloading file as we already have it locally');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user