@@ -79,6 +79,7 @@ interface IState {
7979 syncStateData : ISyncStateData ;
8080 unsentMessages : MatrixEvent [ ] ;
8181 isResending : boolean ;
82+ timelineNeedsRefresh : boolean ;
8283}
8384
8485export default class RoomStatusBar extends React . PureComponent < IProps , IState > {
@@ -93,13 +94,16 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
9394 syncStateData : this . context . getSyncStateData ( ) ,
9495 unsentMessages : getUnsentMessages ( this . props . room ) ,
9596 isResending : false ,
97+ // TODO: This should be `false`
98+ timelineNeedsRefresh : true ,
9699 } ;
97100 }
98101
99102 public componentDidMount ( ) : void {
100103 const client = this . context ;
101104 client . on ( "sync" , this . onSyncStateChange ) ;
102105 client . on ( "Room.localEchoUpdated" , this . onRoomLocalEchoUpdated ) ;
106+ client . on ( "Room.historyImportedWithinTimeline" , this . onRoomHistoryImportedWithinTimeline ) ;
103107
104108 this . checkSize ( ) ;
105109 }
@@ -115,6 +119,7 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
115119 if ( client ) {
116120 client . removeListener ( "sync" , this . onSyncStateChange ) ;
117121 client . removeListener ( "Room.localEchoUpdated" , this . onRoomLocalEchoUpdated ) ;
122+ client . removeListener ( "Room.historyImportedWithinTimeline" , this . onRoomHistoryImportedWithinTimeline ) ;
118123 }
119124 }
120125
@@ -142,6 +147,19 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
142147 dis . fire ( Action . FocusSendMessageComposer ) ;
143148 } ;
144149
150+ private onRefreshTimelineClick = ( ) : void => {
151+ console . log ( 'TODO: Refresh timeline' ) ;
152+ // TODO: What's the best way to refresh the timeline? Something like
153+ // `room.resetLiveTimeline(null, null);` although this just seems to
154+ // clear the timeline. I also tried to split out
155+ // `scrollbackFromPaginationToken` from the `scrollback` method in to
156+ // paginate from the beginning of the room but it's just not right.
157+
158+ this . setState ( {
159+ timelineNeedsRefresh : false
160+ } ) ;
161+ }
162+
145163 private onRoomLocalEchoUpdated = ( ev : MatrixEvent , room : Room ) => {
146164 if ( room . roomId !== this . props . room . roomId ) return ;
147165 const messages = getUnsentMessages ( this . props . room ) ;
@@ -151,6 +169,14 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
151169 } ) ;
152170 } ;
153171
172+ private onRoomHistoryImportedWithinTimeline = ( markerEv : MatrixEvent , room : Room ) => {
173+ if ( room . roomId !== this . props . room . roomId ) return ;
174+
175+ this . setState ( {
176+ timelineNeedsRefresh : true ,
177+ } ) ;
178+ } ;
179+
154180 // Check whether current size is greater than 0, if yes call props.onVisible
155181 private checkSize ( ) : void {
156182 if ( this . getSize ( ) ) {
@@ -166,7 +192,11 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
166192 private getSize ( ) : number {
167193 if ( this . shouldShowConnectionError ( ) ) {
168194 return STATUS_BAR_EXPANDED ;
169- } else if ( this . state . unsentMessages . length > 0 || this . state . isResending ) {
195+ } else if (
196+ this . state . unsentMessages . length > 0 ||
197+ this . state . isResending ||
198+ this . state . timelineNeedsRefresh
199+ ) {
170200 return STATUS_BAR_EXPANDED_LARGE ;
171201 }
172202 return STATUS_BAR_HIDDEN ;
@@ -182,7 +212,7 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
182212 this . state . syncStateData . error &&
183213 this . state . syncStateData . error . name === 'M_RESOURCE_LIMIT_EXCEEDED' ,
184214 ) ;
185- return this . state . syncState === "ERROR" && ! errorIsMauError ;
215+ return ( this . state . syncState === "ERROR" && ! errorIsMauError ) ;
186216 }
187217
188218 private getUnsentMessageContent ( ) : JSX . Element {
@@ -306,6 +336,36 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
306336 return this . getUnsentMessageContent ( ) ;
307337 }
308338
339+ if ( this . state . timelineNeedsRefresh ) {
340+ return (
341+ < div className = "mx_RoomStatusBar mx_RoomStatusBar_unsentMessages" >
342+ < div role = "alert" >
343+ < div className = "mx_RoomStatusBar_unsentBadge" >
344+ < img
345+ src = { require ( "../../../res/img/feather-customised/warning-triangle.svg" ) . default }
346+ width = "24"
347+ height = "24"
348+ title = "/!\ "
349+ alt = "/!\ " />
350+ </ div >
351+ < div >
352+ < div className = "mx_RoomStatusBar_unsentTitle" >
353+ { _t ( "History import detected." ) }
354+ </ div >
355+ < div className = "mx_RoomStatusBar_unsentDescription" >
356+ { _t ( "History was just imported somewhere in the room. In order to see the historical messages, refresh your timeline." ) }
357+ </ div >
358+ </ div >
359+ < div className = "mx_RoomStatusBar_unsentButtonBar" >
360+ < AccessibleButton onClick = { this . onRefreshTimelineClick } className = "mx_RoomStatusBar_refreshTimelineBtn" >
361+ { _t ( "Refresh timeline" ) }
362+ </ AccessibleButton >
363+ </ div >
364+ </ div >
365+ </ div >
366+ )
367+ }
368+
309369 return null ;
310370 }
311371}
0 commit comments