remove ContactDetails unused
							parent
							
								
									273eedc6a9
								
							
						
					
					
						commit
						a6cecd33e3
					
				| @ -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); |  | ||||||
|   }); |  | ||||||
| }); |  | ||||||
| @ -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> |  | ||||||
|     ); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
					Loading…
					
					
				
		Reference in New Issue