feat: getMessageQuoteProps now loads data from conversation.quotes state and loads correctly into the Quote

pull/2757/head
William Grant 2 years ago
parent ab1cf7a658
commit a962ef2228

@ -636,6 +636,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
if (quote.text) {
// do not show text of not found messages.
// if the message was deleted better not show it's text content in the message
// TODO this will be where we show message not found.
quoteProps.text = sliceQuoteText(quote.text);
}
@ -1408,3 +1409,50 @@ const updatesToDispatch: Map<string, MessageModelPropsWithoutConvoProps> = new M
export class MessageCollection extends Backbone.Collection<MessageModel> {}
MessageCollection.prototype.model = MessageModel;
// TODO rename and consolidate with getPropsForQuote
export function verifyQuote(
convo: ConversationModel,
msg: PropsForMessageWithoutConvoProps | undefined
) {
const referencedMessageNotFound = Boolean(msg);
const authorName = convo ? convo.getContactProfileNameOrShortenedPubKey() : null;
let isFromMe = convo ? convo.id === UserUtils.getOurPubKeyStrFromCache() : false;
// NOTE follows PropsForQuote except the sender can be undefined
let quoteProps: any = {
authorName: authorName || 'Unknown',
isFromMe,
referencedMessageNotFound,
};
if (!msg) {
return quoteProps;
}
const id = msg.id;
const author = msg.sender;
if (convo?.isPublic() && PubKey.hasBlindedPrefix(author)) {
const room = OpenGroupData.getV2OpenGroupRoom(msg.convoId);
if (room && roomHasBlindEnabled(room)) {
const usFromCache = findCachedBlindedIdFromUnblinded(
UserUtils.getOurPubKeyStrFromCache(),
room.serverPublicKey
);
if (usFromCache && usFromCache === author) {
isFromMe = true;
}
}
}
const attachment = msg.attachments && msg.attachments[0];
quoteProps = {
...quoteProps,
sender: author,
messageId: id,
attachment: referencedMessageNotFound && attachment ? attachment : undefined,
};
return quoteProps;
}

@ -8,6 +8,7 @@ import {
MessageModelPropsWithConvoProps,
MessageModelPropsWithoutConvoProps,
MessagePropsDetails,
PropsForQuote,
ReduxConversationType,
SortedMessageModelProps,
} from '../ducks/conversations';
@ -25,7 +26,6 @@ import { MessageContentSelectorProps } from '../../components/conversation/messa
import { MessageContentWithStatusSelectorProps } from '../../components/conversation/message/message-content/MessageContentWithStatus';
import { MessageContextMenuSelectorProps } from '../../components/conversation/message/message-content/MessageContextMenu';
import { MessageLinkPreviewSelectorProps } from '../../components/conversation/message/message-content/MessageLinkPreview';
import { MessageQuoteSelectorProps } from '../../components/conversation/message/message-content/MessageQuote';
import { MessageStatusSelectorProps } from '../../components/conversation/message/message-content/MessageStatus';
import { MessageTextSelectorProps } from '../../components/conversation/message/message-content/MessageText';
import { GenericReadableMessageSelectorProps } from '../../components/conversation/message/message-item/GenericReadableMessage';
@ -37,6 +37,7 @@ import { ConversationTypeEnum } from '../../models/conversationAttributes';
import { MessageReactsSelectorProps } from '../../components/conversation/message/message-content/MessageReactions';
import { filter, isEmpty, pick, sortBy } from 'lodash';
import { verifyQuote } from '../../models/message';
export const getConversations = (state: StateType): ConversationsStateType => state.conversations;
@ -967,17 +968,39 @@ export const getMessageLinkPreviewProps = createSelector(getMessagePropsByMessag
return msgProps;
});
export const getMessageQuoteProps = createSelector(getMessagePropsByMessageId, (props):
| MessageQuoteSelectorProps
| undefined => {
if (!props || isEmpty(props)) {
return undefined;
}
export const getMessageQuoteProps = createSelector(
getConversations,
getMessagePropsByMessageId,
(convosProps, msgProps) => {
if (!convosProps || isEmpty(convosProps) || !msgProps || isEmpty(msgProps)) {
return undefined;
}
const msgProps: MessageQuoteSelectorProps = pick(props.propsForMessage, ['direction', 'quote']);
const direction = msgProps.propsForMessage.direction;
const quote = msgProps.propsForQuote;
if (!direction || !quote || isEmpty(quote)) {
return undefined;
}
return msgProps;
});
const { messageId, sender } = quote;
if (!messageId || !sender) {
return undefined;
}
let quoteProps: PropsForQuote = quote;
const conversationId = convosProps.selectedConversation;
const sourceMessage = convosProps.quotes[`${messageId}-${sender}`].propsForMessage;
if (conversationId && sourceMessage) {
const convo = getConversationController().get(conversationId);
quoteProps = verifyQuote(convo, sourceMessage);
}
window.log.debug(`WIP: quoteProps`, quoteProps);
return { direction, quote: quoteProps };
}
);
export const getMessageStatusProps = createSelector(getMessagePropsByMessageId, (props):
| MessageStatusSelectorProps

Loading…
Cancel
Save