@@ -20,21 +20,23 @@ import classNames from 'classnames';
2020import { MatrixEvent } from 'matrix-js-sdk/src/models/event' ;
2121import { Room } from 'matrix-js-sdk/src/models/room' ;
2222import { Relations } from 'matrix-js-sdk/src/models/relations' ;
23+ import { MatrixClient } from 'matrix-js-sdk/src/client' ;
2324
2425import { _t } from '../../../languageHandler' ;
2526import dis from '../../../dispatcher/dispatcher' ;
2627import { makeUserPermalink , RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks" ;
2728import SettingsStore from "../../../settings/SettingsStore" ;
2829import { Layout } from "../../../settings/enums/Layout" ;
29- import MatrixClientContext from "../../../contexts/MatrixClientContext" ;
3030import { getUserNameColorClass } from "../../../utils/FormattingUtils" ;
3131import { Action } from "../../../dispatcher/actions" ;
3232import { replaceableComponent } from "../../../utils/replaceableComponent" ;
3333import Spinner from './Spinner' ;
3434import ReplyTile from "../rooms/ReplyTile" ;
3535import Pill from './Pill' ;
3636import { ButtonEvent } from './AccessibleButton' ;
37- import { getParentEventId } from '../../../utils/Reply' ;
37+ import { getParentEventId , shouldDisplayReply } from '../../../utils/Reply' ;
38+ import RoomContext , { TimelineRenderingType } from "../../../contexts/RoomContext" ;
39+ import { MatrixClientPeg } from '../../../MatrixClientPeg' ;
3840
3941/**
4042 * This number is based on the previous behavior - if we have message of height
@@ -76,12 +78,14 @@ interface IState {
7678// be low as each event being loaded (after the first) is triggered by an explicit user action.
7779@replaceableComponent ( "views.elements.ReplyChain" )
7880export default class ReplyChain extends React . Component < IProps , IState > {
79- static contextType = MatrixClientContext ;
81+ static contextType = RoomContext ;
82+ public context ! : React . ContextType < typeof RoomContext > ;
83+
8084 private unmounted = false ;
8185 private room : Room ;
8286 private blockquoteRef = React . createRef < HTMLElement > ( ) ;
8387
84- constructor ( props , context ) {
88+ constructor ( props : IProps , context : React . ContextType < typeof RoomContext > ) {
8589 super ( props , context ) ;
8690
8791 this . state = {
@@ -91,7 +95,11 @@ export default class ReplyChain extends React.Component<IProps, IState> {
9195 err : false ,
9296 } ;
9397
94- this . room = this . context . getRoom ( this . props . parentEv . getRoomId ( ) ) ;
98+ this . room = this . matrixClient . getRoom ( this . props . parentEv . getRoomId ( ) ) ;
99+ }
100+
101+ private get matrixClient ( ) : MatrixClient {
102+ return MatrixClientPeg . get ( ) ;
95103 }
96104
97105 componentDidMount ( ) {
@@ -158,7 +166,7 @@ export default class ReplyChain extends React.Component<IProps, IState> {
158166 try {
159167 // ask the client to fetch the event we want using the context API, only interface to do so is to ask
160168 // for a timeline with that event, but once it is loaded we can use findEventById to look up the ev map
161- await this . context . getEventTimeline ( this . room . getUnfilteredTimelineSet ( ) , eventId ) ;
169+ await this . matrixClient . getEventTimeline ( this . room . getUnfilteredTimelineSet ( ) , eventId ) ;
162170 } catch ( e ) {
163171 // if it fails catch the error and return early, there's no point trying to find the event in this case.
164172 // Return null as it is falsey and thus should be treated as an error (as the event cannot be resolved).
@@ -198,16 +206,17 @@ export default class ReplyChain extends React.Component<IProps, IState> {
198206 render ( ) {
199207 let header = null ;
200208
209+ const inThread = this . context . timelineRenderingType === TimelineRenderingType . Thread ;
201210 if ( this . state . err ) {
202211 header = < blockquote className = "mx_ReplyChain mx_ReplyChain_error" >
203212 {
204213 _t ( 'Unable to load event that was replied to, ' +
205214 'it either does not exist or you do not have permission to view it.' )
206215 }
207216 </ blockquote > ;
208- } else if ( this . state . loadedEv ) {
217+ } else if ( this . state . loadedEv && shouldDisplayReply ( this . state . events [ 0 ] , inThread ) ) {
209218 const ev = this . state . loadedEv ;
210- const room = this . context . getRoom ( ev . getRoomId ( ) ) ;
219+ const room = this . matrixClient . getRoom ( ev . getRoomId ( ) ) ;
211220 header = < blockquote className = { `mx_ReplyChain ${ this . getReplyChainColorClass ( ev ) } ` } >
212221 {
213222 _t ( '<a>In reply to</a> <pill>' , { } , {
0 commit comments