@@ -18,14 +18,15 @@ import React, { createRef, KeyboardEvent, ReactNode, TransitionEvent } from 'rea
1818import ReactDOM from 'react-dom' ;
1919import classNames from 'classnames' ;
2020import { Room } from 'matrix-js-sdk/src/models/room' ;
21- import { EventType } from 'matrix-js-sdk/src/@types/event' ;
21+ import { EventType , MsgType } from 'matrix-js-sdk/src/@types/event' ;
2222import { MatrixEvent } from 'matrix-js-sdk/src/models/event' ;
2323import { Relations } from "matrix-js-sdk/src/models/relations" ;
2424import { logger } from 'matrix-js-sdk/src/logger' ;
2525import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state" ;
2626import { M_BEACON_INFO } from 'matrix-js-sdk/src/@types/beacon' ;
2727import { isSupportedReceiptType } from "matrix-js-sdk/src/utils" ;
2828
29+
2930import shouldHideEvent from '../../shouldHideEvent' ;
3031import { wantsDateSeparator } from '../../DateUtils' ;
3132import { MatrixClientPeg } from '../../MatrixClientPeg' ;
@@ -57,6 +58,9 @@ import { IReadReceiptInfo } from "../views/rooms/ReadReceiptMarker";
5758import { haveRendererForEvent } from "../../events/EventTileFactory" ;
5859import { editorRoomKey } from "../../Editing" ;
5960import { hasThreadSummary } from "../../utils/EventUtils" ;
61+ import { mediaFromMxc } from "../../customisations/Media" ;
62+ import { mockStateEventImplementation } from '../../../test/test-utils' ;
63+
6064
6165const CONTINUATION_MAX_INTERVAL = 5 * 60 * 1000 ; // 5 minutes
6266const continuedTypes = [ EventType . Sticker , EventType . RoomMessage ] ;
@@ -195,6 +199,7 @@ interface IState {
195199 ghostReadMarkers : string [ ] ;
196200 showTypingNotifications : boolean ;
197201 hideSender : boolean ;
202+ emotes :Dictionary < string > ;
198203}
199204
200205interface IReadReceiptForUser {
@@ -272,6 +277,7 @@ export default class MessagePanel extends React.Component<IProps, IState> {
272277 ghostReadMarkers : [ ] ,
273278 showTypingNotifications : SettingsStore . getValue ( "showTypingNotifications" ) ,
274279 hideSender : this . shouldHideSender ( ) ,
280+ emotes : { } ,
275281 } ;
276282
277283 // Cache these settings on mount since Settings is expensive to query,
@@ -282,11 +288,20 @@ export default class MessagePanel extends React.Component<IProps, IState> {
282288
283289 this . showTypingNotificationsWatcherRef =
284290 SettingsStore . watchSetting ( "showTypingNotifications" , null , this . onShowTypingNotificationsChange ) ;
291+
292+ let emotesEvent = this . props . room . currentState . getStateEvents ( "m.room.emotes" , "" ) ;
293+ let rawEmotes = emotesEvent ? ( emotesEvent . getContent ( ) || { } ) : { } ;
294+ let finalEmotes = { } ;
295+ for ( let key in rawEmotes ) {
296+ this . state . emotes [ ":" + key + ":" ] = "<img src=" + mediaFromMxc ( rawEmotes [ key ] ) . srcHttp + "/>" ;
297+ }
298+
285299 }
286300
287301 componentDidMount ( ) {
288302 this . calculateRoomMembersCount ( ) ;
289303 this . props . room ?. currentState . on ( RoomStateEvent . Update , this . calculateRoomMembersCount ) ;
304+ //this.props.room?.currentState.on(RoomStateEvent.Update, this.getEmotes);
290305 this . isMounted = true ;
291306 }
292307
@@ -608,7 +623,6 @@ export default class MessagePanel extends React.Component<IProps, IState> {
608623 // we also need to figure out which is the last event we show which isn't
609624 // a local echo, to manage the read-marker.
610625 let lastShownEvent ;
611-
612626 let lastShownNonLocalEchoIndex = - 1 ;
613627 for ( i = this . props . events . length - 1 ; i >= 0 ; i -- ) {
614628 const mxEv = this . props . events [ i ] ;
@@ -768,37 +782,77 @@ export default class MessagePanel extends React.Component<IProps, IState> {
768782 isLastSuccessful = isLastSuccessful && mxEv . getSender ( ) === MatrixClientPeg . get ( ) . getUserId ( ) ;
769783
770784 const callEventGrouper = this . props . callEventGroupers . get ( mxEv . getContent ( ) . call_id ) ;
785+
771786 // use txnId as key if available so that we don't remount during sending
787+ if ( mxEv . getType ( ) === "m.room.message" ) {
788+ let messageText = mxEv . getContent ( ) . body ;
789+ //console.log(messageText);
790+ let editedMessageText = messageText . replace ( / : [ \w + - ] + : / , m => this . state . emotes [ m ] ? this . state . emotes [ m ] : m ) ;
791+ let m = [ { body :messageText ,
792+ mimetype :"text/plain" ,
793+ } ,
794+ {
795+ body :editedMessageText ,
796+ mimetype :"text/html" ,
797+ }
798+ ] ;
799+ // if(mxEv.clearEvent){
800+ // console.log("clearevent",mxEv.getRoomId());
801+ // mxEv.clearEvent.content={
802+ // "format":"org.matrix.custom.html",
803+ // "formatted_body":editedMessageText,
804+ // "body":messageText,
805+ // "msgtype":"m.text",
806+ // "org.matrix.msc1767.message":m
807+ // }
808+ // }
809+ // else{
810+ // console.log("no clearevent",mxEv);
811+ // mxEv.content={
812+ // "format":"org.matrix.custom.html",
813+ // "formatted_body":editedMessageText,
814+ // "body":messageText,
815+ // "msgtype":"m.text",
816+ // "org.matrix.msc1767.message":m
817+ // }
818+ // }
819+
820+ //mxEv.getContent().formatted_body = messageText;
821+ //mxEv.clearEvent.content["org.matrix.msc1767.text"] = "";
822+ //mxEv.getContent().formatted_body = (<span>hi</span>);
823+ //mxEv.getContent().format = "org.matrix.custom.html";
824+
825+ }
772826 ret . push (
773827 < EventTile
774- key = { mxEv . getTxnId ( ) || eventId }
775- as = "li"
776- ref = { this . collectEventTile . bind ( this , eventId ) }
777- alwaysShowTimestamps = { this . props . alwaysShowTimestamps }
778- mxEvent = { mxEv }
779- continuation = { continuation }
780- isRedacted = { mxEv . isRedacted ( ) }
781- replacingEventId = { mxEv . replacingEventId ( ) }
782- editState = { isEditing && this . props . editState }
783- onHeightChanged = { this . onHeightChanged }
784- readReceipts = { readReceipts }
785- readReceiptMap = { this . readReceiptMap }
786- showUrlPreview = { this . props . showUrlPreview }
787- checkUnmounting = { this . isUnmounting }
788- eventSendStatus = { mxEv . getAssociatedStatus ( ) }
789- isTwelveHour = { this . props . isTwelveHour }
790- permalinkCreator = { this . props . permalinkCreator }
791- last = { last }
792- lastInSection = { lastInSection }
793- lastSuccessful = { isLastSuccessful }
794- isSelectedEvent = { highlight }
795- getRelationsForEvent = { this . props . getRelationsForEvent }
796- showReactions = { this . props . showReactions }
797- layout = { this . props . layout }
798- showReadReceipts = { this . props . showReadReceipts }
799- callEventGrouper = { callEventGrouper }
800- hideSender = { this . state . hideSender }
801- /> ,
828+ key = { mxEv . getTxnId ( ) || eventId }
829+ as = "li"
830+ ref = { this . collectEventTile . bind ( this , eventId ) }
831+ alwaysShowTimestamps = { this . props . alwaysShowTimestamps }
832+ mxEvent = { mxEv }
833+ continuation = { continuation }
834+ isRedacted = { mxEv . isRedacted ( ) }
835+ replacingEventId = { mxEv . replacingEventId ( ) }
836+ editState = { isEditing && this . props . editState }
837+ onHeightChanged = { this . onHeightChanged }
838+ readReceipts = { readReceipts }
839+ readReceiptMap = { this . readReceiptMap }
840+ showUrlPreview = { this . props . showUrlPreview }
841+ checkUnmounting = { this . isUnmounting }
842+ eventSendStatus = { mxEv . getAssociatedStatus ( ) }
843+ isTwelveHour = { this . props . isTwelveHour }
844+ permalinkCreator = { this . props . permalinkCreator }
845+ last = { last }
846+ lastInSection = { lastInSection }
847+ lastSuccessful = { isLastSuccessful }
848+ isSelectedEvent = { highlight }
849+ getRelationsForEvent = { this . props . getRelationsForEvent }
850+ showReactions = { this . props . showReactions }
851+ layout = { this . props . layout }
852+ showReadReceipts = { this . props . showReadReceipts }
853+ callEventGrouper = { callEventGrouper }
854+ hideSender = { this . state . hideSender }
855+ />
802856 ) ;
803857
804858 return ret ;
0 commit comments