signal-desktop/js/views/contact_list_view.js

69 lines
1.8 KiB
JavaScript
Raw Normal View History

/* global Whisper: false */
/* global textsecure: false */
// eslint-disable-next-line func-names
2018-04-27 21:25:04 +00:00
(function() {
'use strict';
2018-04-27 21:25:04 +00:00
window.Whisper = window.Whisper || {};
2018-04-27 21:25:04 +00:00
Whisper.ContactListView = Whisper.ListView.extend({
tagName: 'div',
itemView: Whisper.View.extend({
tagName: 'div',
className: 'contact',
templateName: 'contact',
initialize(options) {
2018-04-27 21:25:04 +00:00
this.ourNumber = textsecure.storage.user.getNumber();
this.listenBack = options.listenBack;
this.loading = false;
2018-04-27 21:25:04 +00:00
this.listenTo(this.model, 'change', this.render);
},
render() {
if (this.contactView) {
this.contactView.remove();
this.contactView = null;
2018-04-27 21:25:04 +00:00
}
const isMe = this.ourNumber === this.model.id;
this.contactView = new Whisper.ReactWrapperView({
className: 'contact-wrapper',
Component: window.Signal.Components.ContactListItem,
props: {
isMe,
color: this.model.getColor(),
avatarPath: this.model.getAvatarPath(),
phoneNumber: this.model.getNumber(),
name: this.model.getName(),
profileName: this.model.getProfileName(),
verified: this.model.isVerified(),
onClick: this.showIdentity.bind(this),
disabled: this.loading,
},
});
this.$el.append(this.contactView.el);
return this;
2018-04-27 21:25:04 +00:00
},
showIdentity() {
if (this.model.id === this.ourNumber || this.loading) {
2018-04-27 21:25:04 +00:00
return;
}
this.loading = true;
this.render();
const view = new Whisper.KeyVerificationPanelView({
2018-04-27 21:25:04 +00:00
model: this.model,
onLoad: () => {
this.loading = false;
this.listenBack(view);
this.render();
},
2018-04-27 21:25:04 +00:00
});
},
}),
});
})();