@@ -9,6 +9,10 @@ import { AddNewLines } from '../../AddNewLines';
9
9
import { Emojify } from '../../Emojify' ;
10
10
import { LinkPreviews } from '../../../../util/linkPreviews' ;
11
11
import { showLinkVisitWarningDialog } from '../../../dialog/SessionConfirm' ;
12
+ import styled from 'styled-components' ;
13
+ import { PubKey } from '../../../../session/types' ;
14
+ import { isUsAnySogsFromCache } from '../../../../session/apis/open_group_api/sogsv3/knownBlindedkeys' ;
15
+ import { getConversationController } from '../../../../session/conversations' ;
12
16
13
17
const linkify = LinkifyIt ( ) ;
14
18
@@ -184,6 +188,12 @@ const Linkify = (props: LinkifyProps): JSX.Element => {
184
188
return < > { results } </ > ;
185
189
} ;
186
190
191
+ const StyledPre = styled . pre `
192
+ backdrop-filter: brightness(0.8);
193
+ padding: var(--margins-xs);
194
+ user-select: text;
195
+ ` ;
196
+
187
197
export const MessageBody = ( props : Props ) => {
188
198
const { text, disableJumbomoji, disableLinks, isGroup } = props ;
189
199
const sizeClass : SizeClassType = disableJumbomoji ? 'default' : getEmojiSizeClass ( text ) ;
@@ -200,29 +210,35 @@ export const MessageBody = (props: Props) => {
200
210
) ;
201
211
}
202
212
203
- const onlyEmoji = text . match ( / ^ ( ( \ud83c [ \udde6 - \uddff ] ) { 2 } | ( [ \# \* 0 - 9 ] \u20e3 ) | ( \u00a9 | \u00ae | [ \u2000 - \u3300 ] | [ \u / d 8 3 c - \ud83e ] [ \ud000 - \udfff ] ) ( ( \ud83c [ \udffb - \udfff ] ) ? ( \ud83e [ \uddb0 - \uddb3 ] ) ? ( \ufe0f ? \u200d ( [ \u2000 - \u3300 ] | [ \ud83c - \ud83e ] [ \ud000 - \udfff ] ) \ufe0f ? ) ? ) * ) $ / )
213
+ if ( window . getSettingValue ( 'message-formatting' ) ) {
214
+ const onlyEmoji = text . match ( / ^ ( ( \ud83c [ \udde6 - \uddff ] ) { 2 } | ( [ \# \* 0 - 9 ] \u20e3 ) | ( \u00a9 | \u00ae | [ \u2000 - \u3300 ] | [ \u / d 8 3 c - \ud83e ] [ \ud000 - \udfff ] ) ( ( \ud83c [ \udffb - \udfff ] ) ? ( \ud83e [ \uddb0 - \uddb3 ] ) ? ( \ufe0f ? \u200d ( [ \u2000 - \u3300 ] | [ \ud83c - \ud83e ] [ \ud000 - \udfff ] ) \ufe0f ? ) ? ) * ) $ / )
204
215
205
- if ( window . getSettingValue ( 'message-formatting' ) && ! onlyEmoji ) {
206
- /* Resolve mentioned ids to user names and mark them up in bold */
207
- const mention = new RegExp ( `@${ PubKey . regexForPubkeys } ` , 'g' ) ;
208
- const textWithMentions = text . trim ( ) . replace ( mention ,
209
- ( _match , capture ) => {
210
- if ( isUsAnySogsFromCache ( capture ) ) {
211
- /* It's me. Italicise also. */
212
- return `***@${ window . i18n ( 'you' ) } ***` ;
213
- }
216
+ if ( ! onlyEmoji ) {
217
+ /* Resolve mentioned ids to user names and mark them up in bold */
218
+ const mention = new RegExp ( `@${ PubKey . regexForPubkeys } ` , 'g' ) ;
219
+ const textWithMentions = text . trim ( ) . replace ( mention ,
220
+ ( _match , capture ) => {
221
+ if ( isUsAnySogsFromCache ( capture ) ) {
222
+ /* It's me. Italicise also. */
223
+ return `***@${ window . i18n ( 'you' ) } ***` ;
224
+ }
214
225
215
- /* It's someone else. */
216
- return `**@${ getConversationController ( ) . get ( capture ) ?. getContactProfileNameOrShortenedPubKey ( ) || PubKey . shorten ( capture ) } **` ;
217
- }
218
- ) ;
226
+ /* It's someone else. */
227
+ return `**@${ getConversationController ( ) . get ( capture ) ?. getContactProfileNameOrShortenedPubKey ( ) || PubKey . shorten ( capture ) } **` ;
228
+ }
229
+ ) ;
219
230
220
- /* tslint:disable:react-no-dangerous-html */
221
- return (
222
- < div className = "text-selectable"
223
- dangerouslySetInnerHTML = { { __html : `<span style="font-size: 1.1em;">${ markdown . render ( textWithMentions ) } </span>` } }
224
- />
225
- ) ;
231
+ /* tslint:disable:react-no-dangerous-html */
232
+ return (
233
+ < div className = "text-selectable"
234
+ dangerouslySetInnerHTML = { { __html : `<span style="font-size: 1.1em;">${ markdown . render ( textWithMentions ) } </span>` } }
235
+ />
236
+ ) ;
237
+ }
238
+ }
239
+
240
+ if ( text && text . startsWith ( '```' ) && text . endsWith ( '```' ) && text . length > 6 ) {
241
+ return < StyledPre className = "text-selectable" > { text . substring ( 4 , text . length - 3 ) } </ StyledPre > ;
226
242
}
227
243
228
244
return JsxSelectable (
0 commit comments