diff --git a/js/modules/types/contact.js b/js/modules/types/contact.js deleted file mode 100644 index 2eda53ead..000000000 --- a/js/modules/types/contact.js +++ /dev/null @@ -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, - }; -} diff --git a/js/modules/types/message.js b/js/modules/types/message.js index d06cc7e89..44968644d 100644 --- a/js/modules/types/message.js +++ b/js/modules/types/message.js @@ -255,7 +255,7 @@ const toVersion5 = exports._withSchemaVersion({ }); const toVersion6 = exports._withSchemaVersion({ schemaVersion: 6, - upgrade: exports._mapContact(Contact.parseAndWriteAvatar(Attachment.migrateDataToFileSystem)), + upgrade: () => {}, }); // IMPORTANT: We’ve updated our definition of `initializeAttachmentMetadata`, so // we need to run it again on existing items that have previously been incorrectly diff --git a/protos/SignalService.proto b/protos/SignalService.proto index dac96f3ba..b85e6bde3 100644 --- a/protos/SignalService.proto +++ b/protos/SignalService.proto @@ -92,8 +92,10 @@ message DataMessage { } message OpenGroupInvitation { - optional string url = 1; - optional string name = 3; + // @required + required string url = 1; + // @required + required string name = 3; } message ClosedGroupControlMessage { diff --git a/ts/models/message.ts b/ts/models/message.ts index b54081e0b..4d6e9cae9 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -259,10 +259,6 @@ export class MessageModel extends Backbone.Model { 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 ''; } diff --git a/ts/models/messageType.ts b/ts/models/messageType.ts index 4f723d051..de6dd7184 100644 --- a/ts/models/messageType.ts +++ b/ts/models/messageType.ts @@ -32,7 +32,6 @@ export interface MessageAttributes { group_update?: any; groupInvitation?: any; attachments?: any; - contact?: any; conversationId: string; errors?: any; flags?: number; diff --git a/ts/receiver/attachments.ts b/ts/receiver/attachments.ts index 1822c6361..f19c080a9 100644 --- a/ts/receiver/attachments.ts +++ b/ts/receiver/attachments.ts @@ -181,42 +181,6 @@ async function processPreviews(message: MessageModel, convo: ConversationModel): return addedCount; } -async function processAvatars(message: MessageModel, convo: ConversationModel): Promise { - 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( message: MessageModel, convo: ConversationModel @@ -292,8 +256,6 @@ export async function queueAttachmentDownloads( count += await processPreviews(message, conversation); - count += await processAvatars(message, conversation); - count += await processQuoteAttachments(message, conversation); // I don 't think we rely on this for anything diff --git a/ts/receiver/queuedJob.ts b/ts/receiver/queuedJob.ts index 5941a1ac9..7e2f228cd 100644 --- a/ts/receiver/queuedJob.ts +++ b/ts/receiver/queuedJob.ts @@ -331,7 +331,6 @@ async function handleRegularMessage( schemaVersion: dataMessage.schemaVersion, attachments: dataMessage.attachments, body: dataMessage.body, - contact: dataMessage.contact, conversationId: conversation.id, decrypted_at: now, errors: [],