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
|
@ -5,15 +5,17 @@
|
|||
/* global emoji_util: false */
|
||||
/* global Mustache: false */
|
||||
/* global $: false */
|
||||
/* global libphonenumber: false */
|
||||
/* global storage: false */
|
||||
/* global Signal: false */
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
const { Signal } = window;
|
||||
const { loadAttachmentData } = window.Signal.Migrations;
|
||||
const {
|
||||
loadAttachmentData,
|
||||
getAbsoluteAttachmentPath,
|
||||
} = window.Signal.Migrations;
|
||||
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
|
@ -441,46 +443,6 @@
|
|||
});
|
||||
this.$('.inner-bubble').prepend(this.quoteView.el);
|
||||
},
|
||||
formatPhoneNumber(number, options = {}) {
|
||||
const { ourRegionCode } = options;
|
||||
const parsedNumber = libphonenumber.parse(number);
|
||||
const regionCode = libphonenumber.getRegionCodeForNumber(parsedNumber);
|
||||
if (ourRegionCode && regionCode === ourRegionCode) {
|
||||
return libphonenumber.format(
|
||||
parsedNumber,
|
||||
libphonenumber.PhoneNumberFormat.NATIONAL
|
||||
);
|
||||
}
|
||||
return libphonenumber.format(
|
||||
parsedNumber,
|
||||
libphonenumber.PhoneNumberFormat.INTERNATIONAL
|
||||
);
|
||||
},
|
||||
contactSelector(contact) {
|
||||
const { getAbsoluteAttachmentPath } = Signal.Migrations;
|
||||
const region = storage.get('regionCode');
|
||||
|
||||
let { avatar } = contact;
|
||||
if (avatar && avatar.avatar && avatar.avatar.path) {
|
||||
avatar = Object.assign({}, avatar, {
|
||||
avatar: Object.assign({}, avatar.avatar, {
|
||||
path: getAbsoluteAttachmentPath(avatar.avatar.path),
|
||||
}),
|
||||
});
|
||||
}
|
||||
return Object.assign({}, contact, {
|
||||
avatar,
|
||||
number:
|
||||
contact.number &&
|
||||
contact.number.map(item =>
|
||||
Object.assign({}, item, {
|
||||
value: this.formatPhoneNumber(item.value, {
|
||||
ourRegionCode: region,
|
||||
}),
|
||||
})
|
||||
),
|
||||
});
|
||||
},
|
||||
renderContact() {
|
||||
const contacts = this.model.get('contact');
|
||||
if (!contacts || !contacts.length) {
|
||||
|
@ -488,6 +450,9 @@
|
|||
}
|
||||
const contact = contacts[0];
|
||||
|
||||
const regionCode = storage.get('regionCode');
|
||||
const { contactSelector } = Signal.Types.Contact;
|
||||
|
||||
const number =
|
||||
contact.number && contact.number[0] && contact.number[0].value;
|
||||
const haveConversation =
|
||||
|
@ -503,14 +468,15 @@
|
|||
this.model.trigger('show-contact-detail', contact);
|
||||
};
|
||||
|
||||
const getProps = () => {
|
||||
return {
|
||||
contact: this.contactSelector(contact),
|
||||
hasSignalAccount,
|
||||
onSendMessage,
|
||||
onOpenContact,
|
||||
};
|
||||
};
|
||||
const getProps = () => ({
|
||||
contact: contactSelector(contact, {
|
||||
regionCode,
|
||||
getAbsoluteAttachmentPath,
|
||||
}),
|
||||
hasSignalAccount,
|
||||
onSendMessage,
|
||||
onOpenContact,
|
||||
});
|
||||
|
||||
if (this.contactView) {
|
||||
this.contactView.remove();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue