Wire up all contact behaviors, refactor Contact type/selector
This commit is contained in:
parent
41be7f126b
commit
37821e5a1b
13 changed files with 198 additions and 192 deletions
99
ts/types/Contact.ts
Normal file
99
ts/types/Contact.ts
Normal file
|
@ -0,0 +1,99 @@
|
|||
// @ts-ignore
|
||||
import Attachments from '../../app/attachments';
|
||||
import { formatPhoneNumber } from '../util/formatPhoneNumber';
|
||||
|
||||
export interface Contact {
|
||||
name: Name;
|
||||
number?: Array<Phone>;
|
||||
email?: Array<Email>;
|
||||
address?: Array<PostalAddress>;
|
||||
avatar?: Avatar;
|
||||
organization?: string;
|
||||
}
|
||||
|
||||
interface Name {
|
||||
givenName?: string;
|
||||
familyName?: string;
|
||||
prefix?: string;
|
||||
suffix?: string;
|
||||
middleName?: string;
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export enum ContactType {
|
||||
HOME = 1,
|
||||
MOBILE = 2,
|
||||
WORK = 3,
|
||||
CUSTOM = 4,
|
||||
}
|
||||
|
||||
export enum AddressType {
|
||||
HOME = 1,
|
||||
WORK = 2,
|
||||
CUSTOM = 3,
|
||||
}
|
||||
|
||||
export interface Phone {
|
||||
value: string;
|
||||
type: ContactType;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface Email {
|
||||
value: string;
|
||||
type: ContactType;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface PostalAddress {
|
||||
type: AddressType;
|
||||
label?: string;
|
||||
street?: string;
|
||||
pobox?: string;
|
||||
neighborhood?: string;
|
||||
city?: string;
|
||||
region?: string;
|
||||
postcode?: string;
|
||||
country?: string;
|
||||
}
|
||||
|
||||
interface Avatar {
|
||||
avatar: Attachment;
|
||||
isProfile: boolean;
|
||||
}
|
||||
|
||||
interface Attachment {
|
||||
path: string;
|
||||
}
|
||||
|
||||
export function contactSelector(
|
||||
contact: Contact,
|
||||
options: {
|
||||
regionCode: string;
|
||||
getAbsoluteAttachmentPath: (path: string) => string;
|
||||
}
|
||||
) {
|
||||
const { regionCode, getAbsoluteAttachmentPath } = options;
|
||||
|
||||
let { avatar } = contact;
|
||||
if (avatar && avatar.avatar && avatar.avatar.path) {
|
||||
avatar = {
|
||||
...avatar,
|
||||
avatar: {
|
||||
...avatar.avatar,
|
||||
path: getAbsoluteAttachmentPath(avatar.avatar.path),
|
||||
},
|
||||
};
|
||||
}
|
||||
return Object.assign({}, contact, {
|
||||
avatar,
|
||||
number:
|
||||
contact.number &&
|
||||
contact.number.map(item => ({
|
||||
...item,
|
||||
value: formatPhoneNumber(item.value, {
|
||||
ourRegionCode: regionCode,
|
||||
}),
|
||||
})),
|
||||
});
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { Attachment } from './Attachment';
|
||||
import { Contact } from './Contact';
|
||||
import { IndexableBoolean, IndexablePresence } from './IndexedDB';
|
||||
|
||||
export type Message = UserMessage | VerifiedChangeMessage;
|
||||
|
@ -21,6 +22,7 @@ export type IncomingMessage = Readonly<
|
|||
sourceDevice?: number;
|
||||
} & SharedMessageProperties &
|
||||
MessageSchemaVersion5 &
|
||||
MessageSchemaVersion6 &
|
||||
ExpirationTimerUpdate
|
||||
>;
|
||||
|
||||
|
@ -81,3 +83,9 @@ type MessageSchemaVersion5 = Partial<
|
|||
hasFileAttachments: IndexablePresence;
|
||||
}>
|
||||
>;
|
||||
|
||||
type MessageSchemaVersion6 = Partial<
|
||||
Readonly<{
|
||||
contact: Array<Contact>;
|
||||
}>
|
||||
>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue