Refactor: Push selector logic for quote props into Message model
This commit is contained in:
parent
d0b11c59f5
commit
b4ff223d18
3 changed files with 95 additions and 67 deletions
|
@ -31,6 +31,8 @@
|
||||||
this.on('change:expireTimer', this.setToExpire);
|
this.on('change:expireTimer', this.setToExpire);
|
||||||
this.on('unload', this.unload);
|
this.on('unload', this.unload);
|
||||||
this.setToExpire();
|
this.setToExpire();
|
||||||
|
|
||||||
|
this.VOICE_FLAG = textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE;
|
||||||
},
|
},
|
||||||
idForLogging() {
|
idForLogging() {
|
||||||
return `${this.get('source')}.${this.get('sourceDevice')} ${this.get('sent_at')}`;
|
return `${this.get('source')}.${this.get('sourceDevice')} ${this.get('sent_at')}`;
|
||||||
|
@ -200,6 +202,84 @@
|
||||||
}
|
}
|
||||||
return this.imageUrl;
|
return this.imageUrl;
|
||||||
},
|
},
|
||||||
|
getQuoteObjectUrl() {
|
||||||
|
const fromDB = this.quotedMessageFromDatabase;
|
||||||
|
if (fromDB && fromDB.imageUrl) {
|
||||||
|
return fromDB.imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const inMemory = this.quotedMessage;
|
||||||
|
if (inMemory && inMemory.imageUrl) {
|
||||||
|
return inMemory.imageUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
const thumbnail = this.quoteThumbnail;
|
||||||
|
if (thumbnail && thumbnail.objectUrl) {
|
||||||
|
return thumbnail.objectUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
getQuoteContact() {
|
||||||
|
const quote = this.get('quote');
|
||||||
|
if (!quote) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const { author } = quote;
|
||||||
|
if (!author) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ConversationController.get(author);
|
||||||
|
},
|
||||||
|
processAttachment(attachment, objectUrl) {
|
||||||
|
const thumbnail = !objectUrl
|
||||||
|
? null
|
||||||
|
: Object.assign({}, attachment.thumbnail || {}, {
|
||||||
|
objectUrl,
|
||||||
|
});
|
||||||
|
|
||||||
|
return Object.assign({}, attachment, {
|
||||||
|
// eslint-disable-next-line no-bitwise
|
||||||
|
isVoiceMessage: Boolean(attachment.flags & this.VOICE_FLAG),
|
||||||
|
thumbnail,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getPropsForQuote() {
|
||||||
|
const quote = this.get('quote');
|
||||||
|
if (!quote) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const objectUrl = this.getQuoteObjectUrl();
|
||||||
|
const OUR_NUMBER = textsecure.storage.user.getNumber();
|
||||||
|
const { author } = quote;
|
||||||
|
const contact = this.getQuoteContact();
|
||||||
|
|
||||||
|
const authorTitle = contact ? contact.getTitle() : author;
|
||||||
|
const authorProfileName = contact ? contact.getProfileName() : null;
|
||||||
|
const authorColor = contact ? contact.getColor() : 'grey';
|
||||||
|
const isFromMe = contact ? contact.id === OUR_NUMBER : false;
|
||||||
|
const isIncoming = this.isIncoming();
|
||||||
|
const onClick = () => {
|
||||||
|
const { quotedMessage } = this;
|
||||||
|
if (quotedMessage) {
|
||||||
|
this.trigger('scroll-to-message', { id: quotedMessage.id });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
attachments: (quote.attachments || []).map(attachment =>
|
||||||
|
this.processAttachment(attachment, objectUrl)),
|
||||||
|
authorColor,
|
||||||
|
authorProfileName,
|
||||||
|
authorTitle,
|
||||||
|
isFromMe,
|
||||||
|
isIncoming,
|
||||||
|
onClick: this.quotedMessage ? onClick : null,
|
||||||
|
text: quote.text,
|
||||||
|
};
|
||||||
|
},
|
||||||
getConversation() {
|
getConversation() {
|
||||||
// This needs to be an unsafe call, because this method is called during
|
// This needs to be an unsafe call, because this method is called during
|
||||||
// initial module setup. We may be in the middle of the initial fetch to
|
// initial module setup. We may be in the middle of the initial fetch to
|
||||||
|
|
|
@ -130,6 +130,7 @@
|
||||||
'scroll-to-message',
|
'scroll-to-message',
|
||||||
this.scrollToMessage
|
this.scrollToMessage
|
||||||
);
|
);
|
||||||
|
this.listenTo(this.model.messageCollection, 'reply', this.setReplyMessage);
|
||||||
|
|
||||||
this.lazyUpdateVerified = _.debounce(
|
this.lazyUpdateVerified = _.debounce(
|
||||||
this.model.updateVerified.bind(this.model),
|
this.model.updateVerified.bind(this.model),
|
||||||
|
@ -337,7 +338,6 @@
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
markAllAsApproved(untrusted) {
|
markAllAsApproved(untrusted) {
|
||||||
return Promise.all(untrusted.map(contact => contact.setApproved()));
|
return Promise.all(untrusted.map(contact => contact.setApproved()));
|
||||||
},
|
},
|
||||||
|
@ -1061,6 +1061,12 @@
|
||||||
}
|
}
|
||||||
this.focusMessageField();
|
this.focusMessageField();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setMessageReply(message) {
|
||||||
|
this.quotedMessage = message;
|
||||||
|
console.log('setMessageReply', this.quotedMessage);
|
||||||
|
},
|
||||||
|
|
||||||
async sendMessage(e) {
|
async sendMessage(e) {
|
||||||
this.removeLastSeenIndicator();
|
this.removeLastSeenIndicator();
|
||||||
this.closeEmojiPanel();
|
this.closeEmojiPanel();
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
/* global _: false */
|
/* global _: false */
|
||||||
/* global emoji_util: false */
|
/* global emoji_util: false */
|
||||||
/* global Mustache: false */
|
/* global Mustache: false */
|
||||||
/* global ConversationController: false */
|
|
||||||
|
|
||||||
// eslint-disable-next-line func-names
|
// eslint-disable-next-line func-names
|
||||||
(function () {
|
(function () {
|
||||||
|
@ -217,6 +216,7 @@
|
||||||
'click .status': 'select',
|
'click .status': 'select',
|
||||||
'click .some-failed': 'select',
|
'click .some-failed': 'select',
|
||||||
'click .error-message': 'select',
|
'click .error-message': 'select',
|
||||||
|
'click .hover-icon-container': 'onReply',
|
||||||
},
|
},
|
||||||
retryMessage() {
|
retryMessage() {
|
||||||
const retrys = _.filter(
|
const retrys = _.filter(
|
||||||
|
@ -227,6 +227,10 @@
|
||||||
this.model.resend(number);
|
this.model.resend(number);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onReply() {
|
||||||
|
console.log('onReply');
|
||||||
|
this.model.trigger('reply', this.model);
|
||||||
|
},
|
||||||
onExpired() {
|
onExpired() {
|
||||||
this.$el.addClass('expired');
|
this.$el.addClass('expired');
|
||||||
this.$el.find('.bubble').one('webkitAnimationEnd animationend', (e) => {
|
this.$el.find('.bubble').one('webkitAnimationEnd animationend', (e) => {
|
||||||
|
@ -366,75 +370,13 @@
|
||||||
this.timerView.setElement(this.$('.timer'));
|
this.timerView.setElement(this.$('.timer'));
|
||||||
this.timerView.update();
|
this.timerView.update();
|
||||||
},
|
},
|
||||||
getQuoteObjectUrl() {
|
|
||||||
const fromDB = this.model.quotedMessageFromDatabase;
|
|
||||||
if (fromDB && fromDB.imageUrl) {
|
|
||||||
return fromDB.imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const inMemory = this.model.quotedMessage;
|
|
||||||
if (inMemory && inMemory.imageUrl) {
|
|
||||||
return inMemory.imageUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
const thumbnail = this.model.quoteThumbnail;
|
|
||||||
if (thumbnail && thumbnail.objectUrl) {
|
|
||||||
return thumbnail.objectUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
renderQuote() {
|
renderQuote() {
|
||||||
const quote = this.model.get('quote');
|
const props = this.model.getPropsForQuote();
|
||||||
if (!quote) {
|
if (!props) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const VOICE_FLAG = textsecure.protobuf.AttachmentPointer.Flags.VOICE_MESSAGE;
|
const contact = this.model.getQuoteContact();
|
||||||
const objectUrl = this.getQuoteObjectUrl();
|
|
||||||
|
|
||||||
|
|
||||||
function processAttachment(attachment) {
|
|
||||||
const thumbnail = !objectUrl
|
|
||||||
? null
|
|
||||||
: Object.assign({}, attachment.thumbnail || {}, {
|
|
||||||
objectUrl,
|
|
||||||
});
|
|
||||||
|
|
||||||
return Object.assign({}, attachment, {
|
|
||||||
// eslint-disable-next-line no-bitwise
|
|
||||||
isVoiceMessage: Boolean(attachment.flags & VOICE_FLAG),
|
|
||||||
thumbnail,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const OUR_NUMBER = textsecure.storage.user.getNumber();
|
|
||||||
const { author } = quote;
|
|
||||||
const contact = ConversationController.get(author);
|
|
||||||
|
|
||||||
const authorTitle = contact ? contact.getTitle() : author;
|
|
||||||
const authorProfileName = contact ? contact.getProfileName() : null;
|
|
||||||
const authorColor = contact ? contact.getColor() : 'grey';
|
|
||||||
const isFromMe = contact ? contact.id === OUR_NUMBER : false;
|
|
||||||
const isIncoming = this.model.isIncoming();
|
|
||||||
const onClick = () => {
|
|
||||||
const { quotedMessage } = this.model;
|
|
||||||
if (quotedMessage) {
|
|
||||||
this.model.trigger('scroll-to-message', { id: quotedMessage.id });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const props = {
|
|
||||||
attachments: (quote.attachments || []).map(processAttachment),
|
|
||||||
authorColor,
|
|
||||||
authorProfileName,
|
|
||||||
authorTitle,
|
|
||||||
isFromMe,
|
|
||||||
isIncoming,
|
|
||||||
onClick: this.model.quotedMessage ? onClick : null,
|
|
||||||
text: quote.text,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (this.replyView) {
|
if (this.replyView) {
|
||||||
this.replyView.remove();
|
this.replyView.remove();
|
||||||
this.replyView = null;
|
this.replyView = null;
|
||||||
|
|
Loading…
Reference in a new issue