Render quoted mentions as text
This commit is contained in:
parent
bc3b61db1d
commit
2d5292b2f3
7 changed files with 26 additions and 32 deletions
|
@ -41,7 +41,7 @@
|
||||||
savePackMetadata,
|
savePackMetadata,
|
||||||
getStickerPackStatus,
|
getStickerPackStatus,
|
||||||
} = window.Signal.Stickers;
|
} = window.Signal.Stickers;
|
||||||
const { GoogleChrome } = window.Signal.Util;
|
const { GoogleChrome, getTextWithMentions } = window.Signal.Util;
|
||||||
|
|
||||||
const { addStickerPackReference, getMessageBySender } = window.Signal.Data;
|
const { addStickerPackReference, getMessageBySender } = window.Signal.Data;
|
||||||
const { bytesFromString } = window.Signal.Crypto;
|
const { bytesFromString } = window.Signal.Crypto;
|
||||||
|
@ -696,14 +696,6 @@
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
getTextWithMentionStrings(bodyRanges, text) {
|
|
||||||
return bodyRanges.reduce((str, range) => {
|
|
||||||
const textBegin = str.substr(0, range.start);
|
|
||||||
const textEnd = str.substr(range.start + range.length, str.length);
|
|
||||||
return `${textBegin}@${range.replacementText}${textEnd}`;
|
|
||||||
}, text);
|
|
||||||
},
|
|
||||||
|
|
||||||
// Dependencies of prop-generation functions
|
// Dependencies of prop-generation functions
|
||||||
findAndFormatContact(identifier) {
|
findAndFormatContact(identifier) {
|
||||||
if (!identifier) {
|
if (!identifier) {
|
||||||
|
@ -1215,7 +1207,7 @@
|
||||||
|
|
||||||
if (hasMentions) {
|
if (hasMentions) {
|
||||||
const bodyRanges = this.processBodyRanges();
|
const bodyRanges = this.processBodyRanges();
|
||||||
modifiedText = this.getTextWithMentionStrings(bodyRanges, modifiedText);
|
modifiedText = getTextWithMentions(bodyRanges, modifiedText);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux emoji support is mixed, so we disable it. (Note that this doesn't touch
|
// Linux emoji support is mixed, so we disable it. (Note that this doesn't touch
|
||||||
|
|
|
@ -5285,10 +5285,10 @@ button.module-image__border-overlay:focus {
|
||||||
@include light-theme {
|
@include light-theme {
|
||||||
background-color: $color-gray-20;
|
background-color: $color-gray-20;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@include dark-theme {
|
@include ios-dark-theme {
|
||||||
background-color: $color-gray-60;
|
background-color: $color-gray-60;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -914,7 +914,6 @@ export class Message extends React.PureComponent<Props, State> {
|
||||||
direction,
|
direction,
|
||||||
disableScroll,
|
disableScroll,
|
||||||
i18n,
|
i18n,
|
||||||
openConversation,
|
|
||||||
quote,
|
quote,
|
||||||
scrollToQuotedMessage,
|
scrollToQuotedMessage,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
@ -951,7 +950,6 @@ export class Message extends React.PureComponent<Props, State> {
|
||||||
authorColor={quoteColor}
|
authorColor={quoteColor}
|
||||||
authorTitle={quote.authorTitle}
|
authorTitle={quote.authorTitle}
|
||||||
bodyRanges={quote.bodyRanges}
|
bodyRanges={quote.bodyRanges}
|
||||||
openConversation={openConversation}
|
|
||||||
referencedMessageNotFound={referencedMessageNotFound}
|
referencedMessageNotFound={referencedMessageNotFound}
|
||||||
isFromMe={quote.isFromMe}
|
isFromMe={quote.isFromMe}
|
||||||
withContentAbove={withContentAbove}
|
withContentAbove={withContentAbove}
|
||||||
|
|
|
@ -104,7 +104,6 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
|
||||||
isIncoming: boolean('isIncoming', overrideProps.isIncoming || false),
|
isIncoming: boolean('isIncoming', overrideProps.isIncoming || false),
|
||||||
onClick: action('onClick'),
|
onClick: action('onClick'),
|
||||||
onClose: action('onClose'),
|
onClose: action('onClose'),
|
||||||
openConversation: action('openConversation'),
|
|
||||||
referencedMessageNotFound: boolean(
|
referencedMessageNotFound: boolean(
|
||||||
'referencedMessageNotFound',
|
'referencedMessageNotFound',
|
||||||
overrideProps.referencedMessageNotFound || false
|
overrideProps.referencedMessageNotFound || false
|
||||||
|
|
|
@ -8,6 +8,7 @@ import { MessageBody } from './MessageBody';
|
||||||
import { BodyRangesType, LocalizerType } from '../../types/Util';
|
import { BodyRangesType, LocalizerType } from '../../types/Util';
|
||||||
import { ColorType } from '../../types/Colors';
|
import { ColorType } from '../../types/Colors';
|
||||||
import { ContactName } from './ContactName';
|
import { ContactName } from './ContactName';
|
||||||
|
import { getTextWithMentions } from '../../util/getTextWithMentions';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
attachment?: QuotedAttachmentType;
|
attachment?: QuotedAttachmentType;
|
||||||
|
@ -23,7 +24,6 @@ export interface Props {
|
||||||
withContentAbove: boolean;
|
withContentAbove: boolean;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
openConversation: (conversationId: string, messageId?: string) => void;
|
|
||||||
text: string;
|
text: string;
|
||||||
referencedMessageNotFound: boolean;
|
referencedMessageNotFound: boolean;
|
||||||
}
|
}
|
||||||
|
@ -238,16 +238,13 @@ export class Quote extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public renderText(): JSX.Element | null {
|
public renderText(): JSX.Element | null {
|
||||||
const {
|
const { bodyRanges, i18n, text, attachment, isIncoming } = this.props;
|
||||||
bodyRanges,
|
|
||||||
i18n,
|
|
||||||
text,
|
|
||||||
attachment,
|
|
||||||
isIncoming,
|
|
||||||
openConversation,
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
if (text) {
|
if (text) {
|
||||||
|
const quoteText = bodyRanges
|
||||||
|
? getTextWithMentions(bodyRanges, text)
|
||||||
|
: text;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
dir="auto"
|
dir="auto"
|
||||||
|
@ -256,13 +253,7 @@ export class Quote extends React.Component<Props, State> {
|
||||||
isIncoming ? 'module-quote__primary__text--incoming' : null
|
isIncoming ? 'module-quote__primary__text--incoming' : null
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<MessageBody
|
<MessageBody disableLinks text={quoteText} i18n={i18n} />
|
||||||
disableLinks
|
|
||||||
text={text}
|
|
||||||
i18n={i18n}
|
|
||||||
bodyRanges={bodyRanges}
|
|
||||||
openConversation={openConversation}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
12
ts/util/getTextWithMentions.ts
Normal file
12
ts/util/getTextWithMentions.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { BodyRangesType } from '../types/Util';
|
||||||
|
|
||||||
|
export function getTextWithMentions(
|
||||||
|
bodyRanges: BodyRangesType,
|
||||||
|
text: string
|
||||||
|
): string {
|
||||||
|
return bodyRanges.reduce((str, range) => {
|
||||||
|
const textBegin = str.substr(0, range.start);
|
||||||
|
const textEnd = str.substr(range.start + range.length, str.length);
|
||||||
|
return `${textBegin}@${range.replacementText}${textEnd}`;
|
||||||
|
}, text);
|
||||||
|
}
|
|
@ -11,6 +11,7 @@ import {
|
||||||
getPlaceholder as getSafetyNumberPlaceholder,
|
getPlaceholder as getSafetyNumberPlaceholder,
|
||||||
} from './safetyNumber';
|
} from './safetyNumber';
|
||||||
import { getStringForProfileChange } from './getStringForProfileChange';
|
import { getStringForProfileChange } from './getStringForProfileChange';
|
||||||
|
import { getTextWithMentions } from './getTextWithMentions';
|
||||||
import { getUserAgent } from './getUserAgent';
|
import { getUserAgent } from './getUserAgent';
|
||||||
import { hasExpired } from './hasExpired';
|
import { hasExpired } from './hasExpired';
|
||||||
import { isFileDangerous } from './isFileDangerous';
|
import { isFileDangerous } from './isFileDangerous';
|
||||||
|
@ -30,6 +31,7 @@ export {
|
||||||
generateSecurityNumber,
|
generateSecurityNumber,
|
||||||
getSafetyNumberPlaceholder,
|
getSafetyNumberPlaceholder,
|
||||||
getStringForProfileChange,
|
getStringForProfileChange,
|
||||||
|
getTextWithMentions,
|
||||||
getUserAgent,
|
getUserAgent,
|
||||||
GoogleChrome,
|
GoogleChrome,
|
||||||
hasExpired,
|
hasExpired,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue