2018-03-19 21:19:09 +00:00
|
|
|
/* global Whisper: false */
|
|
|
|
|
2018-04-09 16:43:03 +00:00
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
2018-04-09 16:43:03 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
window.Whisper = window.Whisper || {};
|
|
|
|
|
|
|
|
Whisper.MessageView = Whisper.View.extend({
|
|
|
|
tagName: 'li',
|
|
|
|
id() {
|
|
|
|
return this.model.id;
|
|
|
|
},
|
|
|
|
initialize() {
|
2018-04-13 01:12:40 +00:00
|
|
|
this.listenTo(this.model, 'change', this.onChange);
|
2018-04-09 16:43:03 +00:00
|
|
|
this.listenTo(this.model, 'destroy', this.onDestroy);
|
|
|
|
this.listenTo(this.model, 'unload', this.onUnload);
|
2018-08-09 23:18:10 +00:00
|
|
|
this.listenTo(this.model, 'expired', this.onExpired);
|
2018-04-09 16:43:03 +00:00
|
|
|
},
|
2018-07-09 21:29:13 +00:00
|
|
|
onChange() {
|
|
|
|
this.addId();
|
2018-04-17 21:31:16 +00:00
|
|
|
},
|
2018-07-09 21:29:13 +00:00
|
|
|
addId() {
|
|
|
|
// The ID is important for other items inserting themselves into the DOM. Because
|
|
|
|
// of ReactWrapperView and this view, there are two layers of DOM elements
|
|
|
|
// between the parent and the elements returned by the React component, so this is
|
|
|
|
// necessary.
|
|
|
|
const { id } = this.model;
|
|
|
|
this.$el.attr('id', id);
|
2018-04-09 16:43:03 +00:00
|
|
|
},
|
2018-08-09 23:18:10 +00:00
|
|
|
onExpired() {
|
|
|
|
setTimeout(() => this.onUnload(), 1000);
|
|
|
|
},
|
2018-04-09 16:43:03 +00:00
|
|
|
onUnload() {
|
2018-07-09 21:29:13 +00:00
|
|
|
if (this.childView) {
|
|
|
|
this.childView.remove();
|
2018-05-18 23:57:26 +00:00
|
|
|
}
|
2018-04-09 16:43:03 +00:00
|
|
|
|
|
|
|
this.remove();
|
|
|
|
},
|
|
|
|
onDestroy() {
|
|
|
|
this.onUnload();
|
|
|
|
},
|
2018-07-09 21:29:13 +00:00
|
|
|
getRenderInfo() {
|
|
|
|
const { Components } = window.Signal;
|
2018-04-09 16:43:03 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
if (this.model.isExpirationTimerUpdate()) {
|
|
|
|
return {
|
|
|
|
Component: Components.TimerNotification,
|
|
|
|
props: this.model.getPropsForTimerNotification(),
|
|
|
|
};
|
|
|
|
} else if (this.model.isKeyChange()) {
|
|
|
|
return {
|
|
|
|
Component: Components.SafetyNumberNotification,
|
|
|
|
props: this.model.getPropsForSafetyNumberNotification(),
|
|
|
|
};
|
|
|
|
} else if (this.model.isVerifiedChange()) {
|
|
|
|
return {
|
|
|
|
Component: Components.VerificationNotification,
|
|
|
|
props: this.model.getPropsForVerificationNotification(),
|
|
|
|
};
|
|
|
|
} else if (this.model.isEndSession()) {
|
|
|
|
return {
|
|
|
|
Component: Components.ResetSessionNotification,
|
|
|
|
props: this.model.getPropsForResetSessionNotification(),
|
|
|
|
};
|
|
|
|
} else if (this.model.isGroupUpdate()) {
|
|
|
|
return {
|
|
|
|
Component: Components.GroupNotification,
|
|
|
|
props: this.model.getPropsForGroupNotification(),
|
|
|
|
};
|
2018-04-09 16:43:03 +00:00
|
|
|
}
|
2018-05-18 23:57:26 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
return {
|
|
|
|
Component: Components.Message,
|
|
|
|
props: this.model.getPropsForMessage(),
|
|
|
|
};
|
2018-04-09 16:43:03 +00:00
|
|
|
},
|
2018-07-09 21:29:13 +00:00
|
|
|
render() {
|
|
|
|
this.addId();
|
2018-04-10 01:31:52 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
if (this.childView) {
|
|
|
|
this.childView.remove();
|
|
|
|
this.childView = null;
|
2018-04-10 01:31:52 +00:00
|
|
|
}
|
2018-04-12 23:57:50 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const { Component, props } = this.getRenderInfo();
|
|
|
|
this.childView = new Whisper.ReactWrapperView({
|
|
|
|
className: 'message-wrapper',
|
|
|
|
Component,
|
|
|
|
props,
|
2018-04-12 23:57:50 +00:00
|
|
|
});
|
2018-05-05 01:19:54 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
const update = () => {
|
|
|
|
const info = this.getRenderInfo();
|
|
|
|
this.childView.update(info.props);
|
2018-05-03 02:43:23 +00:00
|
|
|
};
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
this.listenTo(this.model, 'change', update);
|
2018-08-09 23:18:10 +00:00
|
|
|
this.listenTo(this.model, 'expired', update);
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-08-31 20:39:56 +00:00
|
|
|
const applicableConversationChanges =
|
|
|
|
'change:color change:name change:number change:profileName change:profileAvatar';
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
this.conversation = this.model.getConversation();
|
2018-08-31 20:39:56 +00:00
|
|
|
this.listenTo(this.conversation, applicableConversationChanges, update);
|
2018-05-03 02:43:23 +00:00
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
this.fromContact = this.model.getIncomingContact();
|
|
|
|
if (this.fromContact) {
|
2018-08-31 20:39:56 +00:00
|
|
|
this.listenTo(this.fromContact, applicableConversationChanges, update);
|
2018-04-09 16:43:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
this.quotedContact = this.model.getQuoteContact();
|
|
|
|
if (this.quotedContact) {
|
2018-08-31 20:39:56 +00:00
|
|
|
this.listenTo(
|
|
|
|
this.quotedContact,
|
|
|
|
applicableConversationChanges,
|
|
|
|
update
|
|
|
|
);
|
2018-04-09 16:43:03 +00:00
|
|
|
}
|
|
|
|
|
2018-07-09 21:29:13 +00:00
|
|
|
this.$el.append(this.childView.el);
|
2018-04-09 16:43:03 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
});
|
2018-04-27 21:25:04 +00:00
|
|
|
})();
|