remove ContactDetails unused

pull/1459/head
Audric Ackermann 4 years ago
parent 273eedc6a9
commit a6cecd33e3

@ -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',

@ -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;
},

@ -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,

@ -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;

@ -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);
});
});

@ -27,12 +27,10 @@
<script type="text/javascript" src="../helpers.js" data-cover></script>
<script type="text/javascript" src="../stringview.js" data-cover></script>
<script type="text/javascript" src="../account_manager.js" data-cover></script>
<script type="text/javascript" src="../contacts_parser.js" data-cover></script>
<script type="text/javascript" src="../task_with_timeout.js" data-cover></script>
<script type="text/javascript" src="errors_test.js"></script>
<script type="text/javascript" src="helpers_test.js"></script>
<script type="text/javascript" src="contacts_parser_test.js"></script>
<script type="text/javascript" src="task_with_timeout_test.js"></script>
<script type="text/javascript" src="account_manager_test.js"></script>

@ -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<Props> {
public renderSendMessage({
i18n,
onSendMessage,
}: {
i18n: (key: string, values?: Array<string>) => string;
onSendMessage: () => void;
}) {
return null;
}
public renderPhone(items: Array<Phone> | undefined, i18n: LocalizerType) {
if (!items || items.length === 0) {
return;
}
return items.map((item: Phone) => {
return (
<div
key={item.value}
className="module-contact-detail__additional-contact"
>
<div className="module-contact-detail__additional-contact__type">
{getLabelForPhone(item, i18n)}
</div>
{item.value}
</div>
);
});
}
public renderAddressLine(value: string | undefined) {
if (!value) {
return;
}
return <div>{value}</div>;
}
public renderPOBox(poBox: string | undefined, i18n: LocalizerType) {
if (!poBox) {
return null;
}
return (
<div>
{i18n('poBox')} {poBox}
</div>
);
}
public renderAddressLineTwo(address: PostalAddress) {
if (address.city || address.region || address.postcode) {
return (
<div>
{address.city} {address.region} {address.postcode}
</div>
);
}
return null;
}
public renderAddresses(
addresses: Array<PostalAddress> | undefined,
i18n: LocalizerType
) {
if (!addresses || addresses.length === 0) {
return;
}
return addresses.map((address: PostalAddress, index: number) => {
return (
<div key={index} className="module-contact-detail__additional-contact">
<div className="module-contact-detail__additional-contact__type">
{getLabelForAddress(address, i18n)}
</div>
{this.renderAddressLine(address.street)}
{this.renderPOBox(address.pobox, i18n)}
{this.renderAddressLine(address.neighborhood)}
{this.renderAddressLineTwo(address)}
{this.renderAddressLine(address.country)}
</div>
);
});
}
public render() {
const { contact, i18n, onSendMessage } = this.props;
const isIncoming = false;
const module = 'contact-detail';
return (
<div className="module-contact-detail">
<div className="module-contact-detail__avatar">
{renderAvatar({ contact, i18n, size: 80 })}
</div>
{renderName({ contact, isIncoming, module })}
{renderContactShorthand({ contact, isIncoming, module })}
{this.renderSendMessage({ i18n, onSendMessage })}
{this.renderPhone(contact.number, i18n)}
{this.renderAddresses(contact.address, i18n)}
</div>
);
}
}

@ -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",

2
ts/window.d.ts vendored

@ -93,8 +93,6 @@ declare global {
getStoragePubKey: any;
getConversations: () => ConversationCollection;
getGuid: any;
ContactBuffer: any;
GroupBuffer: any;
SwarmPolling: SwarmPolling;
SnodePool: {
getSnodesFor: (string) => any;

Loading…
Cancel
Save