Use POJO instead of MessageModel in ConversationView quote logic

This commit is contained in:
Evan Hahn 2021-06-22 18:16:50 -05:00 committed by GitHub
parent c9b1ce6655
commit 6b2dfeb9f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 92 additions and 119 deletions

View file

@ -23,6 +23,7 @@ import {
isGroupV1,
isMe,
} from '../util/whatTypeOfConversation';
import { findAndFormatContact } from '../util/findAndFormatContact';
import * as Bytes from '../Bytes';
import {
canReply,
@ -3745,12 +3746,7 @@ Whisper.ConversationView = Whisper.View.extend({
})
: undefined;
if (
message &&
!canReply(message.attributes, (id?: string) =>
message.findAndFormatContact(id)
)
) {
if (message && !canReply(message.attributes, findAndFormatContact)) {
return;
}
@ -3760,7 +3756,6 @@ Whisper.ConversationView = Whisper.View.extend({
this.quote = null;
this.quotedMessage = null;
this.quoteHolder = null;
const existing = model.get('quotedMessageId');
if (existing !== messageId) {
@ -3806,16 +3801,12 @@ Whisper.ConversationView = Whisper.View.extend({
return;
}
const message = new Whisper.Message({
conversationId: model.id,
quote: this.quote,
} as any);
message.quotedMessage = this.quotedMessage;
this.quoteHolder = message;
const props = getPropsForQuote(
message.attributes,
(id?: string) => message.findAndFormatContact(id),
{
conversationId: model.id,
quote: this.quote,
},
findAndFormatContact,
window.ConversationController.getOurConversationIdOrThrow()
);
@ -3829,7 +3820,7 @@ Whisper.ConversationView = Whisper.View.extend({
props: {
...props,
withContentAbove: true,
onClick: () => this.scrollToMessage(message.quotedMessage.id),
onClick: () => this.scrollToMessage(this.quotedMessage.id),
onClose: () => {
// This can't be the normal 'onClose' because that is always run when this
// view is removed from the DOM, and would clear the draft quote.