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);
|
2019-05-16 22:32:11 +00:00
|
|
|
|
|
|
|
this.updateHiddenSticker();
|
|
|
|
},
|
|
|
|
updateHiddenSticker() {
|
|
|
|
const sticker = this.model.get('sticker');
|
|
|
|
this.isHiddenSticker = sticker && (!sticker.data || !sticker.data.path);
|
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;
|
2019-03-20 17:42:28 +00:00
|
|
|
const { type, data: props } = this.model.props;
|
2018-04-09 16:43:03 +00:00
|
|
|
|
2019-06-10 21:40:02 +00:00
|
|
|
if (type === 'unsupportedMessage') {
|
|
|
|
return {
|
|
|
|
Component: Components.UnsupportedMessage,
|
|
|
|
props,
|
|
|
|
};
|
|
|
|
} else if (type === 'timerNotification') {
|
2018-07-09 21:29:13 +00:00
|
|
|
return {
|
|
|
|
Component: Components.TimerNotification,
|
2019-03-20 17:42:28 +00:00
|
|
|
props,
|
2018-07-09 21:29:13 +00:00
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
} else if (type === 'safetyNumberNotification') {
|
2018-07-09 21:29:13 +00:00
|
|
|
return {
|
|
|
|
Component: Components.SafetyNumberNotification,
|
2019-03-20 17:42:28 +00:00
|
|
|
props,
|
2018-07-09 21:29:13 +00:00
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
} else if (type === 'verificationNotification') {
|
2018-07-09 21:29:13 +00:00
|
|
|
return {
|
|
|
|
Component: Components.VerificationNotification,
|
2019-03-20 17:42:28 +00:00
|
|
|
props,
|
2018-07-09 21:29:13 +00:00
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
} else if (type === 'groupNotification') {
|
2018-07-09 21:29:13 +00:00
|
|
|
return {
|
2019-03-20 17:42:28 +00:00
|
|
|
Component: Components.GroupNotification,
|
|
|
|
props,
|
2018-07-09 21:29:13 +00:00
|
|
|
};
|
2019-03-20 17:42:28 +00:00
|
|
|
} else if (type === 'resetSessionNotification') {
|
2018-07-09 21:29:13 +00:00
|
|
|
return {
|
2019-03-20 17:42:28 +00:00
|
|
|
Component: Components.ResetSessionNotification,
|
|
|
|
props,
|
2018-07-09 21:29:13 +00:00
|
|
|
};
|
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,
|
2019-03-20 17:42:28 +00:00
|
|
|
props,
|
2018-07-09 21:29:13 +00:00
|
|
|
};
|
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();
|
2019-05-16 22:32:11 +00:00
|
|
|
this.childView.update(info.props, () => {
|
|
|
|
if (!this.isHiddenSticker) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateHiddenSticker();
|
|
|
|
|
|
|
|
if (!this.isHiddenSticker) {
|
|
|
|
this.model.trigger('height-changed');
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
})();
|