@@ -5,7 +5,6 @@ import React, {
5
5
import PropTypes from 'prop-types' ;
6
6
import './Message.scss' ;
7
7
8
- import { getShortcodeToCustomEmoji } from '../../organisms/emoji-board/custom-emoji' ;
9
8
import { twemojify } from '../../../util/twemojify' ;
10
9
11
10
import initMatrix from '../../../client/initMatrix' ;
@@ -322,25 +321,25 @@ function getMyEmojiEvent(emojiKey, eventId, roomTimeline) {
322
321
return rEvent ;
323
322
}
324
323
325
- function toggleEmoji ( roomId , eventId , emojiKey , roomTimeline ) {
324
+ function toggleEmoji ( roomId , eventId , emojiKey , shortcode , roomTimeline ) {
326
325
const myAlreadyReactEvent = getMyEmojiEvent ( emojiKey , eventId , roomTimeline ) ;
327
326
if ( myAlreadyReactEvent ) {
328
327
const rId = myAlreadyReactEvent . getId ( ) ;
329
328
if ( rId . startsWith ( '~' ) ) return ;
330
329
redactEvent ( roomId , rId ) ;
331
330
return ;
332
331
}
333
- sendReaction ( roomId , eventId , emojiKey ) ;
332
+ sendReaction ( roomId , eventId , emojiKey , shortcode ) ;
334
333
}
335
334
336
335
function pickEmoji ( e , roomId , eventId , roomTimeline ) {
337
336
openEmojiBoard ( getEventCords ( e ) , ( emoji ) => {
338
- toggleEmoji ( roomId , eventId , emoji . unicode , roomTimeline ) ;
337
+ toggleEmoji ( roomId , eventId , emoji . mxc ?? emoji . unicode , emoji . shortcodes [ 0 ] , roomTimeline ) ;
339
338
e . target . click ( ) ;
340
339
} ) ;
341
340
}
342
341
343
- function genReactionMsg ( userIds , reaction ) {
342
+ function genReactionMsg ( userIds , reaction , shortcode ) {
344
343
return (
345
344
< >
346
345
{ userIds . map ( ( userId , index ) => (
@@ -354,24 +353,22 @@ function genReactionMsg(userIds, reaction) {
354
353
</ React . Fragment >
355
354
) ) }
356
355
< span style = { { opacity : '.6' } } > { ' reacted with ' } </ span >
357
- { twemojify ( reaction , { className : 'react-emoji' } ) }
356
+ { twemojify ( shortcode ? `: ${ shortcode } :` : reaction , { className : 'react-emoji' } ) }
358
357
</ >
359
358
) ;
360
359
}
361
360
362
361
function MessageReaction ( {
363
- shortcodeToEmoji , reaction , count, users, isActive, onClick,
362
+ reaction , shortcode , count, users, isActive, onClick,
364
363
} ) {
365
- const customEmojiMatch = reaction . match ( / ^ : ( \S + ) : $ / ) ;
366
364
let customEmojiUrl = null ;
367
- if ( customEmojiMatch ) {
368
- const customEmoji = shortcodeToEmoji . get ( customEmojiMatch [ 1 ] ) ;
369
- customEmojiUrl = initMatrix . matrixClient . mxcUrlToHttp ( customEmoji ?. mxc ) ;
365
+ if ( reaction . match ( / ^ m x c : \/ \/ \S + $ / ) ) {
366
+ customEmojiUrl = initMatrix . matrixClient . mxcUrlToHttp ( reaction ) ;
370
367
}
371
368
return (
372
369
< Tooltip
373
370
className = "msg__reaction-tooltip"
374
- content = { < Text variant = "b2" > { users . length > 0 ? genReactionMsg ( users , reaction ) : 'Unable to load who has reacted' } </ Text > }
371
+ content = { < Text variant = "b2" > { users . length > 0 ? genReactionMsg ( users , reaction , shortcode ) : 'Unable to load who has reacted' } </ Text > }
375
372
>
376
373
< button
377
374
onClick = { onClick }
@@ -380,17 +377,20 @@ function MessageReaction({
380
377
>
381
378
{
382
379
customEmojiUrl
383
- ? < img className = "react-emoji" draggable = "false" alt = { reaction } src = { customEmojiUrl } />
380
+ ? < img className = "react-emoji" draggable = "false" alt = { shortcode ?? reaction } src = { customEmojiUrl } />
384
381
: twemojify ( reaction , { className : 'react-emoji' } )
385
382
}
386
383
< Text variant = "b3" className = "msg__reaction-count" > { count } </ Text >
387
384
</ button >
388
385
</ Tooltip >
389
386
) ;
390
387
}
388
+ MessageReaction . defaultProps = {
389
+ shortcode : undefined ,
390
+ } ;
391
391
MessageReaction . propTypes = {
392
- shortcodeToEmoji : PropTypes . shape ( { } ) . isRequired ,
393
392
reaction : PropTypes . node . isRequired ,
393
+ shortcode : PropTypes . string ,
394
394
count : PropTypes . number . isRequired ,
395
395
users : PropTypes . arrayOf ( PropTypes . string ) . isRequired ,
396
396
isActive : PropTypes . bool . isRequired ,
@@ -401,17 +401,17 @@ function MessageReactionGroup({ roomTimeline, mEvent }) {
401
401
const { roomId, room, reactionTimeline } = roomTimeline ;
402
402
const mx = initMatrix . matrixClient ;
403
403
const reactions = { } ;
404
- const shortcodeToEmoji = getShortcodeToCustomEmoji ( room ) ;
405
404
const canSendReaction = room . currentState . maySendEvent ( 'm.reaction' , mx . getUserId ( ) ) ;
406
405
407
406
const eventReactions = reactionTimeline . get ( mEvent . getId ( ) ) ;
408
- const addReaction = ( key , count , senderId , isActive ) => {
407
+ const addReaction = ( key , shortcode , count , senderId , isActive ) => {
409
408
let reaction = reactions [ key ] ;
410
409
if ( reaction === undefined ) {
411
410
reaction = {
412
411
count : 0 ,
413
412
users : [ ] ,
414
413
isActive : false ,
414
+ shortcode,
415
415
} ;
416
416
}
417
417
if ( count ) {
@@ -429,17 +429,18 @@ function MessageReactionGroup({ roomTimeline, mEvent }) {
429
429
if ( rEvent . getRelation ( ) === null ) return ;
430
430
const reaction = rEvent . getRelation ( ) ;
431
431
const senderId = rEvent . getSender ( ) ;
432
+ const { shortcode } = rEvent . getContent ( ) ;
432
433
const isActive = senderId === mx . getUserId ( ) ;
433
434
434
- addReaction ( reaction . key , undefined , senderId , isActive ) ;
435
+ addReaction ( reaction . key , shortcode , undefined , senderId , isActive ) ;
435
436
} ) ;
436
437
} else {
437
438
// Use aggregated reactions
438
439
const aggregatedReaction = mEvent . getServerAggregatedRelation ( 'm.annotation' ) ?. chunk ;
439
440
if ( ! aggregatedReaction ) return null ;
440
441
aggregatedReaction . forEach ( ( reaction ) => {
441
442
if ( reaction . type !== 'm.reaction' ) return ;
442
- addReaction ( reaction . key , reaction . count , undefined , false ) ;
443
+ addReaction ( reaction . key , undefined , reaction . count , undefined , false ) ;
443
444
} ) ;
444
445
}
445
446
@@ -449,13 +450,13 @@ function MessageReactionGroup({ roomTimeline, mEvent }) {
449
450
Object . keys ( reactions ) . map ( ( key ) => (
450
451
< MessageReaction
451
452
key = { key }
452
- shortcodeToEmoji = { shortcodeToEmoji }
453
453
reaction = { key }
454
+ shortcode = { reactions [ key ] . shortcode }
454
455
count = { reactions [ key ] . count }
455
456
users = { reactions [ key ] . users }
456
457
isActive = { reactions [ key ] . isActive }
457
458
onClick = { ( ) => {
458
- toggleEmoji ( roomId , mEvent . getId ( ) , key , roomTimeline ) ;
459
+ toggleEmoji ( roomId , mEvent . getId ( ) , key , reactions [ key ] . shortcode , roomTimeline ) ;
459
460
} }
460
461
/>
461
462
) )
0 commit comments