remove unused contact field on message
This commit is contained in:
parent
c1225b3a74
commit
03fe67b974
|
@ -1,98 +0,0 @@
|
||||||
const { omit, compact, map } = require('lodash');
|
|
||||||
|
|
||||||
const { toLogFormat } = require('./errors');
|
|
||||||
const { SignalService } = require('../../../ts/protobuf');
|
|
||||||
|
|
||||||
const DEFAULT_PHONE_TYPE = SignalService.DataMessage.Contact.Phone.Type.HOME;
|
|
||||||
|
|
||||||
exports.parseAndWriteAvatar = upgradeAttachment => async (contact, context = {}) => {
|
|
||||||
const { message, logger } = context;
|
|
||||||
const { avatar } = contact;
|
|
||||||
|
|
||||||
// This is to ensure that an omit() call doesn't pull in prototype props/methods
|
|
||||||
const contactShallowCopy = Object.assign({}, contact);
|
|
||||||
|
|
||||||
const contactWithUpdatedAvatar =
|
|
||||||
avatar && avatar.avatar
|
|
||||||
? Object.assign({}, contactShallowCopy, {
|
|
||||||
avatar: Object.assign({}, avatar, {
|
|
||||||
avatar: await upgradeAttachment(avatar.avatar, context),
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
: omit(contactShallowCopy, ['avatar']);
|
|
||||||
|
|
||||||
// eliminates empty numbers, emails, and addresses; adds type if not provided
|
|
||||||
const parsedContact = parseContact(contactWithUpdatedAvatar);
|
|
||||||
|
|
||||||
const error = exports._validate(parsedContact, {
|
|
||||||
messageId: idForLogging(message),
|
|
||||||
});
|
|
||||||
if (error) {
|
|
||||||
logger.error('Contact.parseAndWriteAvatar: contact was malformed.', toLogFormat(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
return parsedContact;
|
|
||||||
};
|
|
||||||
|
|
||||||
function parseContact(contact) {
|
|
||||||
const boundParsePhone = phoneNumber => parsePhoneItem(phoneNumber);
|
|
||||||
|
|
||||||
return Object.assign(
|
|
||||||
{},
|
|
||||||
omit(contact, ['avatar', 'number', 'email', 'address']),
|
|
||||||
parseAvatar(contact.avatar),
|
|
||||||
createArrayKey('number', compact(map(contact.number, boundParsePhone)))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function idForLogging(message) {
|
|
||||||
return `${message.source}.${message.sourceDevice} ${message.sent_at}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports._validate = (contact, options = {}) => {
|
|
||||||
const { messageId } = options;
|
|
||||||
const { name, number, organization } = contact;
|
|
||||||
|
|
||||||
if ((!name || !name.displayName) && !organization) {
|
|
||||||
return new Error(`Message ${messageId}: Contact had neither 'displayName' nor 'organization'`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!number || !number.length) {
|
|
||||||
return new Error(`Message ${messageId}: Contact had no included numbers`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
function parsePhoneItem(item) {
|
|
||||||
if (!item.value) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Object.assign({}, item, {
|
|
||||||
type: item.type || DEFAULT_PHONE_TYPE,
|
|
||||||
value: item.value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseAvatar(avatar) {
|
|
||||||
if (!avatar) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
avatar: Object.assign({}, avatar, {
|
|
||||||
isProfile: avatar.isProfile || false,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createArrayKey(key, array) {
|
|
||||||
if (!array || !array.length) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
[key]: array,
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -255,7 +255,7 @@ const toVersion5 = exports._withSchemaVersion({
|
||||||
});
|
});
|
||||||
const toVersion6 = exports._withSchemaVersion({
|
const toVersion6 = exports._withSchemaVersion({
|
||||||
schemaVersion: 6,
|
schemaVersion: 6,
|
||||||
upgrade: exports._mapContact(Contact.parseAndWriteAvatar(Attachment.migrateDataToFileSystem)),
|
upgrade: () => {},
|
||||||
});
|
});
|
||||||
// IMPORTANT: We’ve updated our definition of `initializeAttachmentMetadata`, so
|
// IMPORTANT: We’ve updated our definition of `initializeAttachmentMetadata`, so
|
||||||
// we need to run it again on existing items that have previously been incorrectly
|
// we need to run it again on existing items that have previously been incorrectly
|
||||||
|
|
|
@ -92,8 +92,10 @@ message DataMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
message OpenGroupInvitation {
|
message OpenGroupInvitation {
|
||||||
optional string url = 1;
|
// @required
|
||||||
optional string name = 3;
|
required string url = 1;
|
||||||
|
// @required
|
||||||
|
required string name = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ClosedGroupControlMessage {
|
message ClosedGroupControlMessage {
|
||||||
|
|
|
@ -259,10 +259,6 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
|
||||||
window.Whisper.ExpirationTimerOptions.getAbbreviated(expireTimerUpdate.expireTimer || 0)
|
window.Whisper.ExpirationTimerOptions.getAbbreviated(expireTimerUpdate.expireTimer || 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const contacts = this.get('contact');
|
|
||||||
if (contacts && contacts.length) {
|
|
||||||
return window.Signal.Types.Contact.getName(contacts[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,6 @@ export interface MessageAttributes {
|
||||||
group_update?: any;
|
group_update?: any;
|
||||||
groupInvitation?: any;
|
groupInvitation?: any;
|
||||||
attachments?: any;
|
attachments?: any;
|
||||||
contact?: any;
|
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
errors?: any;
|
errors?: any;
|
||||||
flags?: number;
|
flags?: number;
|
||||||
|
|
|
@ -181,42 +181,6 @@ async function processPreviews(message: MessageModel, convo: ConversationModel):
|
||||||
return addedCount;
|
return addedCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processAvatars(message: MessageModel, convo: ConversationModel): Promise<number> {
|
|
||||||
let addedCount = 0;
|
|
||||||
const isOpenGroupV2 = convo.isOpenGroupV2();
|
|
||||||
|
|
||||||
const contacts = message.get('contact') || [];
|
|
||||||
|
|
||||||
const contact = await Promise.all(
|
|
||||||
contacts.map(async (item: any, index: any) => {
|
|
||||||
if (!item.avatar || !item.avatar.avatar) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
addedCount += 1;
|
|
||||||
|
|
||||||
const avatarJob = await AttachmentDownloads.addJob(item.avatar.avatar, {
|
|
||||||
messaeId: message.id,
|
|
||||||
type: 'contact',
|
|
||||||
index,
|
|
||||||
isOpenGroupV2,
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
avatar: {
|
|
||||||
...item.avatar,
|
|
||||||
avatar: avatarJob,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
message.set({ contact });
|
|
||||||
|
|
||||||
return addedCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function processQuoteAttachments(
|
async function processQuoteAttachments(
|
||||||
message: MessageModel,
|
message: MessageModel,
|
||||||
convo: ConversationModel
|
convo: ConversationModel
|
||||||
|
@ -292,8 +256,6 @@ export async function queueAttachmentDownloads(
|
||||||
|
|
||||||
count += await processPreviews(message, conversation);
|
count += await processPreviews(message, conversation);
|
||||||
|
|
||||||
count += await processAvatars(message, conversation);
|
|
||||||
|
|
||||||
count += await processQuoteAttachments(message, conversation);
|
count += await processQuoteAttachments(message, conversation);
|
||||||
|
|
||||||
// I don 't think we rely on this for anything
|
// I don 't think we rely on this for anything
|
||||||
|
|
|
@ -331,7 +331,6 @@ async function handleRegularMessage(
|
||||||
schemaVersion: dataMessage.schemaVersion,
|
schemaVersion: dataMessage.schemaVersion,
|
||||||
attachments: dataMessage.attachments,
|
attachments: dataMessage.attachments,
|
||||||
body: dataMessage.body,
|
body: dataMessage.body,
|
||||||
contact: dataMessage.contact,
|
|
||||||
conversationId: conversation.id,
|
conversationId: conversation.id,
|
||||||
decrypted_at: now,
|
decrypted_at: now,
|
||||||
errors: [],
|
errors: [],
|
||||||
|
|
Loading…
Reference in New Issue