-
-
Notifications
You must be signed in to change notification settings - Fork 815
Ask to refresh timeline when historical messages are imported (MSC2716) #8303
Changes from 6 commits
66ea757
6dba3df
12b0115
eb5e899
a50e011
ed910bb
8d61226
d8f94ed
c43d309
623960b
d9001ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ interface IState { | |
| syncStateData: ISyncStateData; | ||
| unsentMessages: MatrixEvent[]; | ||
| isResending: boolean; | ||
| timelineNeedsRefresh: boolean; | ||
| } | ||
|
|
||
| export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | ||
|
|
@@ -93,13 +94,15 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | |
| syncStateData: this.context.getSyncStateData(), | ||
| unsentMessages: getUnsentMessages(this.props.room), | ||
| isResending: false, | ||
| timelineNeedsRefresh: this.props.room.getTimelineNeedsRefresh(), | ||
| }; | ||
| } | ||
|
|
||
| public componentDidMount(): void { | ||
| const client = this.context; | ||
| client.on("sync", this.onSyncStateChange); | ||
| client.on("Room.localEchoUpdated", this.onRoomLocalEchoUpdated); | ||
| client.on("Room.historyImportedWithinTimeline", this.onRoomHistoryImportedWithinTimeline); | ||
|
|
||
| this.checkSize(); | ||
| } | ||
|
|
@@ -115,6 +118,7 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | |
| if (client) { | ||
| client.removeListener("sync", this.onSyncStateChange); | ||
| client.removeListener("Room.localEchoUpdated", this.onRoomLocalEchoUpdated); | ||
| client.removeListener("Room.historyImportedWithinTimeline", this.onRoomHistoryImportedWithinTimeline); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -142,6 +146,19 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | |
| dis.fire(Action.FocusSendMessageComposer); | ||
| }; | ||
|
|
||
| private onRefreshTimelineClick = (): void => { | ||
| console.log('TODO: Refresh timeline'); | ||
| // TODO: What's the best way to refresh the timeline? Something like | ||
| // `room.resetLiveTimeline(null, null);` although this just seems to | ||
| // clear the timeline. I also tried to split out | ||
| // `scrollbackFromPaginationToken` from the `scrollback` method in to | ||
| // paginate from the beginning of the room but it's just not right. | ||
|
||
|
|
||
| this.setState({ | ||
| timelineNeedsRefresh: false, | ||
| }); | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the behavior of all of this would be best served by an end-to-end test. It looks like we just added Cypress recently but it's missing all of the utility necessary to complete something like this.
I can't find an overall issue describing the need/want to use Cypress so it's unclear how much we want to move forward with it. I've had many troubles using Cypress with Gitter. It seems like we have other e2e tests using Puppeteer but I'm guessing we want to move all of these to Cypress. Better place I should be adding some e2e tests or approaching this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conversation continued at #8354 (comment) |
||
|
|
||
| private onRoomLocalEchoUpdated = (ev: MatrixEvent, room: Room) => { | ||
| if (room.roomId !== this.props.room.roomId) return; | ||
| const messages = getUnsentMessages(this.props.room); | ||
|
|
@@ -151,6 +168,14 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | |
| }); | ||
| }; | ||
|
|
||
| private onRoomHistoryImportedWithinTimeline = (markerEv: MatrixEvent, room: Room) => { | ||
| if (room.roomId !== this.props.room.roomId) return; | ||
|
|
||
| this.setState({ | ||
| timelineNeedsRefresh: room.getTimelineNeedsRefresh(), | ||
| }); | ||
| }; | ||
|
|
||
| // Check whether current size is greater than 0, if yes call props.onVisible | ||
| private checkSize(): void { | ||
| if (this.getSize()) { | ||
|
|
@@ -166,7 +191,11 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | |
| private getSize(): number { | ||
| if (this.shouldShowConnectionError()) { | ||
| return STATUS_BAR_EXPANDED; | ||
| } else if (this.state.unsentMessages.length > 0 || this.state.isResending) { | ||
| } else if ( | ||
| this.state.unsentMessages.length > 0 || | ||
| this.state.isResending || | ||
| this.state.timelineNeedsRefresh | ||
| ) { | ||
| return STATUS_BAR_EXPANDED_LARGE; | ||
| } | ||
| return STATUS_BAR_HIDDEN; | ||
|
|
@@ -306,6 +335,37 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> { | |
| return this.getUnsentMessageContent(); | ||
| } | ||
|
|
||
| if (this.state.timelineNeedsRefresh) { | ||
| return ( | ||
| <div className="mx_RoomStatusBar mx_RoomStatusBar_unsentMessages"> | ||
| <div role="alert"> | ||
| <div className="mx_RoomStatusBar_unsentBadge"> | ||
| <img | ||
| src={require("../../../res/img/feather-customised/warning-triangle.svg").default} | ||
| width="24" | ||
| height="24" | ||
| title="/!\ " | ||
| alt="/!\ " /> | ||
MadLittleMods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </div> | ||
| <div> | ||
| <div className="mx_RoomStatusBar_unsentTitle"> | ||
| { _t("History import detected.") } | ||
| </div> | ||
| <div className="mx_RoomStatusBar_unsentDescription"> | ||
| { _t("History was just imported somewhere in the room. " + | ||
| "In order to see the historical messages, refresh your timeline.") } | ||
| </div> | ||
| </div> | ||
| <div className="mx_RoomStatusBar_unsentButtonBar"> | ||
| <AccessibleButton onClick={this.onRefreshTimelineClick} className="mx_RoomStatusBar_refreshTimelineBtn"> | ||
| { _t("Refresh timeline") } | ||
| </AccessibleButton> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the context type definition around line L87 as string emitter keys are no longer allowed in TypedEventEmitter, TS thinks
this.contextisanyhere thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also not listen on the room directly, re-emitters suck
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I don't guess, what should we do? 🙇
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.props.room.on(...);but with componentDidUpdate comparing this.props.room with prevProps.room to remove old listener and setup a new one. This is all a lot nicer in hooks where its a one-liner.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated 👍
I'm not sure what to do here exactly. I've stopped using string keys. Is there anything further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conversation continued at #8354 (comment)