Properly handle avatar changes in group update messages

This commit is contained in:
Scott Nonnenberg 2018-10-24 11:31:01 -07:00
parent 7789beec64
commit 1e562c8293
2 changed files with 23 additions and 6 deletions

View file

@ -19,10 +19,12 @@
const { Message: TypedMessage, Contact, PhoneNumber } = Signal.Types;
const {
deleteAttachmentData,
deleteExternalMessageFiles,
getAbsoluteAttachmentPath,
loadAttachmentData,
loadQuoteData,
writeNewAttachmentData,
} = window.Signal.Migrations;
window.AccountCache = Object.create(null);
@ -1033,28 +1035,43 @@
return conversation.queueJob(async () => {
try {
const now = new Date().getTime();
let attributes = { type: 'private' };
let attributes = {
...conversation.attributes,
};
if (dataMessage.group) {
let groupUpdate = null;
attributes = {
...attributes,
type: 'group',
groupId: dataMessage.group.id,
};
if (dataMessage.group.type === GROUP_TYPES.UPDATE) {
attributes = {
type: 'group',
groupId: dataMessage.group.id,
...attributes,
name: dataMessage.group.name,
avatar: dataMessage.group.avatar,
members: _.union(
dataMessage.group.members,
conversation.get('members')
),
};
// Update this group conversations's avatar on disk if it has changed.
if (dataMessage.group.avatar) {
attributes = await window.Signal.Types.Conversation.maybeUpdateAvatar(
attributes,
dataMessage.group.avatar.data,
{
writeNewAttachmentData,
deleteAttachmentData,
}
);
}
groupUpdate =
conversation.changedAttributes(
_.pick(dataMessage.group, 'name', 'avatar')
) || {};
const difference = _.difference(
attributes.members,
conversation.get('members')

View file

@ -119,6 +119,7 @@ function initializeMigrations({
return {
attachmentsPath,
deleteAttachmentData: deleteOnDisk,
deleteExternalMessageFiles: MessageType.deleteAllExternalFiles({
deleteAttachmentData: Type.deleteData(deleteOnDisk),
deleteOnDisk,
@ -131,8 +132,6 @@ function initializeMigrations({
loadMessage: MessageType.createAttachmentLoader(loadAttachmentData),
Migrations0DatabaseWithAttachmentData,
Migrations1DatabaseWithoutAttachmentData,
writeNewAttachmentData: createWriterForNew(attachmentsPath),
deleteAttachmentData: deleteOnDisk,
upgradeMessageSchema: (message, options = {}) => {
const { maxVersion } = options;
@ -153,6 +152,7 @@ function initializeMigrations({
writeExistingAttachmentData: createWriterForExisting(attachmentsPath),
logger,
}),
writeNewAttachmentData: createWriterForNew(attachmentsPath),
};
}