diff --git a/Gruntfile.js b/Gruntfile.js index 97eeb02b2..557e0085b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -89,7 +89,6 @@ module.exports = grunt => { 'libtextsecure/account_manager.js', 'libtextsecure/http-resources.js', 'libtextsecure/message_receiver.js', - 'libtextsecure/contacts_parser.js', 'libtextsecure/task_with_timeout.js', ], dest: 'js/libtextsecure.js', diff --git a/js/models/messages.js b/js/models/messages.js index 799e1d05c..386d15974 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -51,7 +51,6 @@ this.on('destroy', this.onDestroy); this.on('change:expirationStartTimestamp', this.setToExpire); this.on('change:expireTimer', this.setToExpire); - this.on('unload', this.unload); this.on('expired', this.onExpired); this.setToExpire(); // Keep props ready @@ -266,14 +265,8 @@ }, async cleanup() { getMessageController().unregister(this.id); - this.unload(); await deleteExternalMessageFiles(this.attributes); }, - unload() { - if (this.quotedMessage) { - this.quotedMessage = null; - } - }, onExpired() { this.hasExpired = true; }, diff --git a/js/modules/signal.js b/js/modules/signal.js index d7c2db048..0b2ab2117 100644 --- a/js/modules/signal.js +++ b/js/modules/signal.js @@ -14,9 +14,6 @@ const LinkPreviews = require('./link_previews'); const AttachmentDownloads = require('./attachment_downloads'); // Components -const { - ContactDetail, -} = require('../../ts/components/conversation/ContactDetail'); const { ContactListItem } = require('../../ts/components/ContactListItem'); const { ContactName } = require('../../ts/components/conversation/ContactName'); const { @@ -217,7 +214,6 @@ exports.setup = (options = {}) => { }); const Components = { - ContactDetail, ContactListItem, ContactName, EmbeddedContact, diff --git a/libtextsecure/contacts_parser.js b/libtextsecure/contacts_parser.js deleted file mode 100644 index e7f1a7e21..000000000 --- a/libtextsecure/contacts_parser.js +++ /dev/null @@ -1,61 +0,0 @@ -/* global dcodeIO, window, textsecure */ - -function ProtoParser(arrayBuffer, protobuf) { - this.protobuf = protobuf; - this.buffer = new dcodeIO.ByteBuffer(); - this.buffer.append(arrayBuffer); - this.buffer.offset = 0; - this.buffer.limit = arrayBuffer.byteLength; -} -ProtoParser.prototype = { - constructor: ProtoParser, - next() { - try { - if (this.buffer.limit === this.buffer.offset) { - return undefined; // eof - } - const len = this.buffer.readInt32(); - const nextBuffer = this.buffer - .slice(this.buffer.offset, this.buffer.offset + len) - .toArrayBuffer(); - // TODO: de-dupe ByteBuffer.js includes in libaxo/libts - // then remove this toArrayBuffer call. - - const proto = this.protobuf.decode(nextBuffer); - this.buffer.skip(len); - - if (proto.avatar) { - const attachmentLen = proto.avatar.length; - proto.avatar.data = this.buffer - .slice(this.buffer.offset, this.buffer.offset + attachmentLen) - .toArrayBuffer(); - this.buffer.skip(attachmentLen); - } - - if (proto.profileKey) { - proto.profileKey = proto.profileKey.toArrayBuffer(); - } - - return proto; - } catch (error) { - window.log.error( - 'ProtoParser.next error:', - error && error.stack ? error.stack : error - ); - } - - return null; - }, -}; -const GroupBuffer = function Constructor(arrayBuffer) { - ProtoParser.call(this, arrayBuffer, textsecure.protobuf.GroupDetails); -}; -GroupBuffer.prototype = Object.create(ProtoParser.prototype); -GroupBuffer.prototype.constructor = GroupBuffer; -const ContactBuffer = function Constructor(arrayBuffer) { - ProtoParser.call(this, arrayBuffer, textsecure.protobuf.ContactDetails); -}; - -window.GroupBuffer = GroupBuffer; -ContactBuffer.prototype = Object.create(ProtoParser.prototype); -ContactBuffer.prototype.constructor = ContactBuffer; diff --git a/libtextsecure/test/contacts_parser_test.js b/libtextsecure/test/contacts_parser_test.js deleted file mode 100644 index 16f70254c..000000000 --- a/libtextsecure/test/contacts_parser_test.js +++ /dev/null @@ -1,106 +0,0 @@ -/* global ContactBuffer, GroupBuffer, textsecure */ - -describe('ContactBuffer', () => { - function getTestBuffer() { - const buffer = new dcodeIO.ByteBuffer(); - const avatarBuffer = new dcodeIO.ByteBuffer(); - const avatarLen = 255; - for (let i = 0; i < avatarLen; i += 1) { - avatarBuffer.writeUint8(i); - } - avatarBuffer.limit = avatarBuffer.offset; - avatarBuffer.offset = 0; - const contactInfo = new textsecure.protobuf.ContactDetails({ - name: 'Zero Cool', - number: '+10000000000', - avatar: { contentType: 'image/jpeg', length: avatarLen }, - }); - const contactInfoBuffer = contactInfo.encode().toArrayBuffer(); - - for (let i = 0; i < 3; i += 1) { - buffer.writeInt32(contactInfoBuffer.byteLength); - buffer.append(contactInfoBuffer); - buffer.append(avatarBuffer.clone()); - } - - buffer.limit = buffer.offset; - buffer.offset = 0; - return buffer.toArrayBuffer(); - } - - it('parses an array buffer of contacts', () => { - const arrayBuffer = getTestBuffer(); - const contactBuffer = new ContactBuffer(arrayBuffer); - let contact = contactBuffer.next(); - let count = 0; - while (contact !== undefined) { - count += 1; - assert.strictEqual(contact.name, 'Zero Cool'); - assert.strictEqual(contact.number, '+10000000000'); - assert.strictEqual(contact.avatar.contentType, 'image/jpeg'); - assert.strictEqual(contact.avatar.length, 255); - assert.strictEqual(contact.avatar.data.byteLength, 255); - const avatarBytes = new Uint8Array(contact.avatar.data); - for (let j = 0; j < 255; j += 1) { - assert.strictEqual(avatarBytes[j], j); - } - contact = contactBuffer.next(); - } - assert.strictEqual(count, 3); - }); -}); - -describe('GroupBuffer', () => { - function getTestBuffer() { - const buffer = new dcodeIO.ByteBuffer(); - const avatarBuffer = new dcodeIO.ByteBuffer(); - const avatarLen = 255; - for (let i = 0; i < avatarLen; i += 1) { - avatarBuffer.writeUint8(i); - } - avatarBuffer.limit = avatarBuffer.offset; - avatarBuffer.offset = 0; - const groupInfo = new textsecure.protobuf.GroupDetails({ - id: new Uint8Array([1, 3, 3, 7]).buffer, - name: 'Hackers', - members: ['cereal', 'burn', 'phreak', 'joey'], - avatar: { contentType: 'image/jpeg', length: avatarLen }, - }); - const groupInfoBuffer = groupInfo.encode().toArrayBuffer(); - - for (let i = 0; i < 3; i += 1) { - buffer.writeInt32(groupInfoBuffer.byteLength); - buffer.append(groupInfoBuffer); - buffer.append(avatarBuffer.clone()); - } - - buffer.limit = buffer.offset; - buffer.offset = 0; - return buffer.toArrayBuffer(); - } - - it('parses an array buffer of groups', () => { - const arrayBuffer = getTestBuffer(); - const groupBuffer = new GroupBuffer(arrayBuffer); - let group = groupBuffer.next(); - let count = 0; - while (group !== undefined) { - count += 1; - assert.strictEqual(group.name, 'Hackers'); - assertEqualArrayBuffers( - group.id.toArrayBuffer(), - new Uint8Array([1, 3, 3, 7]).buffer - ); - assert.sameMembers(group.members, ['cereal', 'burn', 'phreak', 'joey']); - assert.strictEqual(group.avatar.contentType, 'image/jpeg'); - assert.strictEqual(group.avatar.length, 255); - assert.strictEqual(group.avatar.data.byteLength, 255); - const avatarBytes = new Uint8Array(group.avatar.data); - for (let j = 0; j < 255; j += 1) { - assert.strictEqual(avatarBytes[j], j); - } - group = groupBuffer.next(); - } - assert.strictEqual(count, 3); - }); -}); diff --git a/libtextsecure/test/index.html b/libtextsecure/test/index.html index 20d44b38f..3477b0328 100644 --- a/libtextsecure/test/index.html +++ b/libtextsecure/test/index.html @@ -27,12 +27,10 @@ - - diff --git a/ts/components/conversation/ContactDetail.tsx b/ts/components/conversation/ContactDetail.tsx deleted file mode 100644 index 5d029cad2..000000000 --- a/ts/components/conversation/ContactDetail.tsx +++ /dev/null @@ -1,178 +0,0 @@ -import React from 'react'; - -import { - AddressType, - Contact, - ContactType, - Email, - Phone, - PostalAddress, -} from '../../types/Contact'; -import { missingCaseError } from '../../util/missingCaseError'; - -import { - renderAvatar, - renderContactShorthand, - renderName, -} from './_contactUtil'; - -import { LocalizerType } from '../../types/Util'; - -interface Props { - contact: Contact; - i18n: LocalizerType; - onSendMessage: () => void; -} - -function getLabelForEmail(method: Email, i18n: LocalizerType): string { - switch (method.type) { - case ContactType.CUSTOM: - return method.label || i18n('email'); - case ContactType.HOME: - return i18n('home'); - case ContactType.MOBILE: - return i18n('mobile'); - case ContactType.WORK: - return i18n('work'); - default: - throw missingCaseError(method.type); - } -} - -function getLabelForPhone(method: Phone, i18n: LocalizerType): string { - switch (method.type) { - case ContactType.CUSTOM: - return method.label || i18n('phone'); - case ContactType.HOME: - return i18n('home'); - case ContactType.MOBILE: - return i18n('mobile'); - case ContactType.WORK: - return i18n('work'); - default: - throw missingCaseError(method.type); - } -} - -function getLabelForAddress( - address: PostalAddress, - i18n: LocalizerType -): string { - switch (address.type) { - case AddressType.CUSTOM: - return address.label || i18n('address'); - case AddressType.HOME: - return i18n('home'); - case AddressType.WORK: - return i18n('work'); - default: - throw missingCaseError(address.type); - } -} - -export class ContactDetail extends React.Component { - public renderSendMessage({ - i18n, - onSendMessage, - }: { - i18n: (key: string, values?: Array) => string; - onSendMessage: () => void; - }) { - return null; - } - - public renderPhone(items: Array | undefined, i18n: LocalizerType) { - if (!items || items.length === 0) { - return; - } - - return items.map((item: Phone) => { - return ( -
-
- {getLabelForPhone(item, i18n)} -
- {item.value} -
- ); - }); - } - - public renderAddressLine(value: string | undefined) { - if (!value) { - return; - } - - return
{value}
; - } - - public renderPOBox(poBox: string | undefined, i18n: LocalizerType) { - if (!poBox) { - return null; - } - - return ( -
- {i18n('poBox')} {poBox} -
- ); - } - - public renderAddressLineTwo(address: PostalAddress) { - if (address.city || address.region || address.postcode) { - return ( -
- {address.city} {address.region} {address.postcode} -
- ); - } - - return null; - } - - public renderAddresses( - addresses: Array | undefined, - i18n: LocalizerType - ) { - if (!addresses || addresses.length === 0) { - return; - } - - return addresses.map((address: PostalAddress, index: number) => { - return ( -
-
- {getLabelForAddress(address, i18n)} -
- {this.renderAddressLine(address.street)} - {this.renderPOBox(address.pobox, i18n)} - {this.renderAddressLine(address.neighborhood)} - {this.renderAddressLineTwo(address)} - {this.renderAddressLine(address.country)} -
- ); - }); - } - - public render() { - const { contact, i18n, onSendMessage } = this.props; - const isIncoming = false; - const module = 'contact-detail'; - - return ( -
-
- {renderAvatar({ contact, i18n, size: 80 })} -
- {renderName({ contact, isIncoming, module })} - {renderContactShorthand({ contact, isIncoming, module })} - {this.renderSendMessage({ i18n, onSendMessage })} - {this.renderPhone(contact.number, i18n)} - {this.renderAddresses(contact.address, i18n)} -
- ); - } -} diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index e931394ac..6db5fe3e1 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -909,14 +909,6 @@ "updated": "2018-09-15T00:38:04.183Z", "reasonDetail": "Getting the value, not setting it" }, - { - "rule": "jQuery-append(", - "path": "libtextsecure/contacts_parser.js", - "line": " this.buffer.append(arrayBuffer);", - "lineNumber": 6, - "reasonCategory": "falseMatch", - "updated": "2018-09-19T18:13:29.628Z" - }, { "rule": "jQuery-wrap(", "path": "libtextsecure/crypto.js", diff --git a/ts/window.d.ts b/ts/window.d.ts index c79d74d01..883755c25 100644 --- a/ts/window.d.ts +++ b/ts/window.d.ts @@ -93,8 +93,6 @@ declare global { getStoragePubKey: any; getConversations: () => ConversationCollection; getGuid: any; - ContactBuffer: any; - GroupBuffer: any; SwarmPolling: SwarmPolling; SnodePool: { getSnodesFor: (string) => any;