|
|
@ -310,6 +310,8 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const logPrefix = `${message.idForLogging()} (type: ${type}, index: ${index})`;
|
|
|
|
|
|
|
|
|
|
|
|
if (type === 'attachment') {
|
|
|
|
if (type === 'attachment') {
|
|
|
|
const attachments = message.get('attachments');
|
|
|
|
const attachments = message.get('attachments');
|
|
|
|
if (!attachments || attachments.length <= index) {
|
|
|
|
if (!attachments || attachments.length <= index) {
|
|
|
@ -317,7 +319,7 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
`_addAttachmentToMessage: attachments didn't exist or ${index} was too large`
|
|
|
|
`_addAttachmentToMessage: attachments didn't exist or ${index} was too large`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_replaceAttachment(attachments, index, attachment);
|
|
|
|
_replaceAttachment(attachments, index, attachment, logPrefix);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -332,7 +334,7 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
if (!item) {
|
|
|
|
if (!item) {
|
|
|
|
throw new Error(`_addAttachmentToMessage: preview ${index} was falsey`);
|
|
|
|
throw new Error(`_addAttachmentToMessage: preview ${index} was falsey`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_replaceAttachment(item, 'image', attachment);
|
|
|
|
_replaceAttachment(item, 'image', attachment, logPrefix);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -345,7 +347,7 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const item = contact[index];
|
|
|
|
const item = contact[index];
|
|
|
|
if (item && item.avatar && item.avatar.avatar) {
|
|
|
|
if (item && item.avatar && item.avatar.avatar) {
|
|
|
|
_replaceAttachment(item.avatar, 'avatar', attachment);
|
|
|
|
_replaceAttachment(item.avatar, 'avatar', attachment, logPrefix);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
logger.warn(
|
|
|
|
logger.warn(
|
|
|
|
`_addAttachmentToMessage: Couldn't update contact with avatar attachment for message ${message.idForLogging()}`
|
|
|
|
`_addAttachmentToMessage: Couldn't update contact with avatar attachment for message ${message.idForLogging()}`
|
|
|
@ -373,7 +375,7 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
`_addAttachmentToMessage: attachment ${index} was falsey`
|
|
|
|
`_addAttachmentToMessage: attachment ${index} was falsey`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_replaceAttachment(item, 'thumbnail', attachment);
|
|
|
|
_replaceAttachment(item, 'thumbnail', attachment, logPrefix);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -388,7 +390,7 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
await Signal.Migrations.deleteAttachmentData(existingAvatar.path);
|
|
|
|
await Signal.Migrations.deleteAttachmentData(existingAvatar.path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_replaceAttachment(group, 'avatar', attachment);
|
|
|
|
_replaceAttachment(group, 'avatar', attachment, logPrefix);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -397,11 +399,11 @@ async function _addAttachmentToMessage(message, attachment, { type, index }) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _replaceAttachment(object, key, newAttachment) {
|
|
|
|
function _replaceAttachment(object, key, newAttachment, logPrefix) {
|
|
|
|
const oldAttachment = object[key];
|
|
|
|
const oldAttachment = object[key];
|
|
|
|
if (oldAttachment && oldAttachment.path) {
|
|
|
|
if (oldAttachment && oldAttachment.path) {
|
|
|
|
logger.warn(
|
|
|
|
logger.warn(
|
|
|
|
'_replaceAttachment: Old attachment already had path, not replacing'
|
|
|
|
`_replaceAttachment: ${logPrefix} - old attachment already had path, not replacing`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|