@@ -306,28 +306,15 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
306306 ! this . message ! . mentioned_users ||
307307 this . message ! . mentioned_users . length === 0
308308 ) {
309- // Wrap emojis in span to display emojis correctly in Chrome https://bugs.chromium.org/p/chromium/issues/detail?id=596223
310- const regex = new RegExp ( emojiRegex ( ) , 'g' ) ;
311- // Based on this: https://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome
312- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
313- const isChrome =
314- ! ! ( window as any ) . chrome &&
315- typeof ( window as any ) . opr === 'undefined' ;
316- /* eslint-enable @typescript-eslint/no-unsafe-member-access */
317- content = content . replace (
318- regex ,
319- ( match ) =>
320- `<span ${
321- isChrome ? 'class="str-chat__emoji-display-fix"' : ''
322- } >${ match } </span>`
323- ) ;
309+ content = this . fixEmojiDisplay ( content ) ;
324310 this . messageTextParts = [ { content, type : 'text' } ] ;
325311 } else {
326312 this . messageTextParts = [ ] ;
327313 let text = content ;
328314 this . message ! . mentioned_users . forEach ( ( user ) => {
329315 const mention = `@${ user . name || user . id } ` ;
330- const precedingText = text . substring ( 0 , text . indexOf ( mention ) ) ;
316+ let precedingText = text . substring ( 0 , text . indexOf ( mention ) ) ;
317+ precedingText = this . fixEmojiDisplay ( precedingText ) ;
331318 this . messageTextParts . push ( {
332319 content : precedingText ,
333320 type : 'text' ,
@@ -340,9 +327,29 @@ export class MessageComponent implements OnInit, OnChanges, OnDestroy {
340327 text = text . replace ( precedingText + mention , '' ) ;
341328 } ) ;
342329 if ( text ) {
330+ text = this . fixEmojiDisplay ( text ) ;
343331 this . messageTextParts . push ( { content : text , type : 'text' } ) ;
344332 }
345333 }
346334 }
347335 }
336+
337+ private fixEmojiDisplay ( content : string ) {
338+ // Wrap emojis in span to display emojis correctly in Chrome https://bugs.chromium.org/p/chromium/issues/detail?id=596223
339+ const regex = new RegExp ( emojiRegex ( ) , 'g' ) ;
340+ // Based on this: https://stackoverflow.com/questions/4565112/javascript-how-to-find-out-if-the-user-browser-is-chrome
341+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
342+ const isChrome =
343+ ! ! ( window as any ) . chrome && typeof ( window as any ) . opr === 'undefined' ;
344+ /* eslint-enable @typescript-eslint/no-unsafe-member-access */
345+ content = content . replace (
346+ regex ,
347+ ( match ) =>
348+ `<span ${
349+ isChrome ? 'class="str-chat__emoji-display-fix"' : ''
350+ } >${ match } </span>`
351+ ) ;
352+
353+ return content ;
354+ }
348355}
0 commit comments