|
|
|
@ -2,14 +2,16 @@ import { filter, isNumber, omit } from 'lodash';
|
|
|
|
|
|
|
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
|
|
|
|
|
|
import * as Constants from '../constants';
|
|
|
|
|
import { Data } from '../../data/data';
|
|
|
|
|
import { MessageModel } from '../../models/message';
|
|
|
|
|
import { downloadAttachment, downloadAttachmentSogsV3 } from '../../receiver/attachments';
|
|
|
|
|
import { initializeAttachmentLogic, processNewAttachment } from '../../types/MessageAttachment';
|
|
|
|
|
import { getAttachmentMetadata } from '../../types/message/initializeAttachmentMetadata';
|
|
|
|
|
import { was404Error } from '../apis/snode_api/onions';
|
|
|
|
|
import { AttachmentDownloadMessageDetails } from '../../types/sqlSharedTypes';
|
|
|
|
|
import { MetaGroupWrapperActions } from '../../webworker/workers/browser/libsession_worker_interface';
|
|
|
|
|
import { was404Error } from '../apis/snode_api/onions';
|
|
|
|
|
import * as Constants from '../constants';
|
|
|
|
|
import { PubKey } from '../types';
|
|
|
|
|
|
|
|
|
|
// this may cause issues if we increment that value to > 1, but only having one job will block the whole queue while one attachment is downloading
|
|
|
|
|
const MAX_ATTACHMENT_JOB_PARALLELISM = 3;
|
|
|
|
@ -137,6 +139,34 @@ async function _maybeStartJob() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function shouldSkipGroupAttachmentDownload({
|
|
|
|
|
groupPk,
|
|
|
|
|
messageModel,
|
|
|
|
|
}: {
|
|
|
|
|
groupPk: string;
|
|
|
|
|
messageModel: MessageModel;
|
|
|
|
|
}) {
|
|
|
|
|
if (!PubKey.is03Pubkey(groupPk)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
const infos = await MetaGroupWrapperActions.infoGet(groupPk);
|
|
|
|
|
const sentAt = messageModel.get('sent_at');
|
|
|
|
|
if (!sentAt) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
(infos.deleteAttachBeforeSeconds && sentAt <= infos.deleteAttachBeforeSeconds * 1000) ||
|
|
|
|
|
(infos.deleteBeforeSeconds && sentAt <= infos.deleteBeforeSeconds * 1000)
|
|
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
window.log.warn('shouldSkipGroupAttachmentDownload failed with ', e.message);
|
|
|
|
|
}
|
|
|
|
|
return false; // try to download it
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function _runJob(job: any) {
|
|
|
|
|
const { id, messageId, attachment, type, index, attempts, isOpenGroupV2, openGroupV2Details } =
|
|
|
|
|
job || {};
|
|
|
|
@ -152,6 +182,17 @@ async function _runJob(job: any) {
|
|
|
|
|
await _finishJob(null, id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const shouldSkipJobForGroup = await shouldSkipGroupAttachmentDownload({
|
|
|
|
|
groupPk: found.get('conversationId'),
|
|
|
|
|
messageModel: found,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (shouldSkipJobForGroup) {
|
|
|
|
|
logger.info('_runJob: shouldSkipGroupAttachmentDownload is true, deleting job');
|
|
|
|
|
await _finishJob(null, id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isTrusted = found.isTrustedForAttachmentDownload();
|
|
|
|
|
|
|
|
|
|
if (!isTrusted) {
|
|
|
|
|