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
|
@ -238,6 +238,12 @@
|
|||
appView.openInbox();
|
||||
}
|
||||
});
|
||||
Whisper.events.on('showConversation', function(conversation) {
|
||||
if (appView) {
|
||||
appView.openConversation(conversation);
|
||||
}
|
||||
});
|
||||
|
||||
Whisper.Notifications.on('click', function(conversation) {
|
||||
showWindow();
|
||||
if (conversation) {
|
||||
|
|
1
js/modules/types/errors.d.ts
vendored
Normal file
1
js/modules/types/errors.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export function toLogFormat(error: any): string;
|
|
@ -1007,15 +1007,17 @@
|
|||
},
|
||||
|
||||
showContactDetail(contact) {
|
||||
console.log('showContactDetail', contact); // TODO
|
||||
|
||||
// TODO: need to run contact through selector to format email, get absolute path
|
||||
// think it's probably time to move it to typescript
|
||||
const regionCode = storage.get('regionCode');
|
||||
const { contactSelector } = Signal.Types.Contact;
|
||||
const { getAbsoluteAttachmentPath } = window.Signal.Migrations;
|
||||
|
||||
const view = new Whisper.ReactWrapperView({
|
||||
Component: Signal.Components.MediaGallery,
|
||||
Component: Signal.Components.ContactDetail,
|
||||
props: {
|
||||
contact,
|
||||
contact: contactSelector(contact, {
|
||||
regionCode,
|
||||
getAbsoluteAttachmentPath,
|
||||
}),
|
||||
hasSignalAccount: true,
|
||||
onSendMessage: () => {
|
||||
const number =
|
||||
|
@ -1032,13 +1034,11 @@
|
|||
},
|
||||
|
||||
async openConversation(number) {
|
||||
console.log('openConversation', number); // TODO
|
||||
|
||||
const conversation = await window.ConversationController.getOrCreateAndWait(
|
||||
number,
|
||||
'private'
|
||||
);
|
||||
window.Whisper.Events.trigger('click', conversation);
|
||||
window.Whisper.events.trigger('showConversation', conversation);
|
||||
},
|
||||
|
||||
listenBack(view) {
|
||||
|
@ -1244,7 +1244,6 @@
|
|||
|
||||
if (message) {
|
||||
const quote = await this.model.makeQuote(this.quotedMessage);
|
||||
console.log({ quote });
|
||||
this.quote = quote;
|
||||
|
||||
this.focusMessageFieldAndClearDisabled();
|
||||
|
|
|
@ -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