Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Ask to refresh timeline when historical messages are imported (MSC2716) #8303

6 changes: 6 additions & 0 deletions res/css/structures/_RoomStatusBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ limitations under the License.
mask-image: url('$(res)/img/element-icons/retry.svg');
}
}

&.mx_RoomStatusBar_refreshTimelineBtn {
&::before {
mask-image: url('$(res)/img/element-icons/retry.svg');
}
}
}

.mx_InlineSpinner {
Expand Down
4 changes: 3 additions & 1 deletion src/components/structures/FilePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ class FilePanel extends React.Component<IProps, IState> {
}

if (!this.state.timelineSet.eventIdToTimeline(ev.getId())) {
this.state.timelineSet.addEventToTimeline(ev, timeline, false);
this.state.timelineSet.addEventToTimeline(ev, timeline, {
toStartOfTimeline: false,
});
}
}

Expand Down
58 changes: 57 additions & 1 deletion src/components/structures/RoomStatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ interface IState {
syncStateData: ISyncStateData;
unsentMessages: MatrixEvent[];
isResending: boolean;
timelineNeedsRefresh: boolean;
}

export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
Expand All @@ -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);
Copy link
Member

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.context is any here though

Copy link
Member

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

Copy link
Contributor Author

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

So I don't guess, what should we do? 🙇

Copy link
Member

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.

Copy link
Contributor Author

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.

Updated 👍

Please add the context type definition around line L87 as string emitter keys are no longer allowed in TypedEventEmitter

I'm not sure what to do here exactly. I've stopped using string keys. Is there anything further?

Copy link
Contributor Author

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)


this.checkSize();
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -142,6 +146,15 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
dis.fire(Action.FocusSendMessageComposer);
};

private onRefreshTimelineClick = (): void => {
// Empty out the current timeline and re-request it
this.props.room.refreshLiveTimeline();

this.setState({
timelineNeedsRefresh: false,
});
};
Copy link
Contributor Author

@MadLittleMods MadLittleMods Apr 19, 2022

Choose a reason for hiding this comment

The 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.

  • Needs a command to create a user behind the scenes and visit Element as the user already signed in
  • Needs commands to setup rooms and send events
  • Needs a way to enable experimental_features in the homeserver.yaml template
  • Needs a way to add an application service registration in the Synapse instance. The MSC2716 /batch_send endpoint is only accessible from a AS token. No extra AS server needed, just the AS token configured.
  • Needs a way to interact with the homserver directly from the application service token to call /batch_send (probably via matrix-js-sdk)

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?

Copy link
Contributor Author

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)


private onRoomLocalEchoUpdated = (ev: MatrixEvent, room: Room) => {
if (room.roomId !== this.props.room.roomId) return;
const messages = getUnsentMessages(this.props.room);
Expand All @@ -151,6 +164,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()) {
Expand All @@ -166,7 +187,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;
Expand Down Expand Up @@ -306,6 +331,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.
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;
}
}
14 changes: 13 additions & 1 deletion src/components/structures/TimelinePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
const cli = MatrixClientPeg.get();
cli.on(RoomEvent.Timeline, this.onRoomTimeline);
cli.on(RoomEvent.TimelineReset, this.onRoomTimelineReset);
this.props.timelineSet.room.on(RoomEvent.TimelineRefresh, this.onRoomTimelineRefresh);
cli.on(RoomEvent.Redaction, this.onRoomRedaction);
if (SettingsStore.getValue("feature_msc3531_hide_messages_pending_moderation")) {
// Make sure that events are re-rendered when their visibility-pending-moderation changes.
Expand Down Expand Up @@ -370,6 +371,8 @@ class TimelinePanel extends React.Component<IProps, IState> {
client.removeListener(MatrixEventEvent.VisibilityChange, this.onEventVisibilityChange);
client.removeListener(ClientEvent.Sync, this.onSync);
}

this.props.timelineSet.room.removeListener(RoomEvent.TimelineRefresh, this.onRoomTimelineRefresh);
}

private onMessageListUnfillRequest = (backwards: boolean, scrollToken: string): void => {
Expand Down Expand Up @@ -627,10 +630,18 @@ class TimelinePanel extends React.Component<IProps, IState> {
});
};

private onRoomTimelineRefresh = (room: Room, timelineSet: EventTimelineSet): void => {
debuglog(`onRoomTimelineRefresh skipping=${timelineSet !== this.props.timelineSet}`);
if (timelineSet !== this.props.timelineSet) return;

this.refreshTimeline();
};

private onRoomTimelineReset = (room: Room, timelineSet: EventTimelineSet): void => {
debuglog(`onRoomTimelineReset skipping=${timelineSet !== this.props.timelineSet} skippingBecauseAtBottom=${this.canResetTimeline()}`);
if (timelineSet !== this.props.timelineSet) return;

if (this.messagePanel.current && this.messagePanel.current.isAtBottom()) {
if (this.canResetTimeline()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a missed refactor. canResetTimeline by name seems aplicable here and the logic appears pretty equivalent.

public canResetTimeline = () => {
if (!this.messagePanel) {
return true;
}
return this.messagePanel.canResetTimeline();
};

public canResetTimeline = () => this.messagePanel?.current.isAtBottom();

this.loadTimeline();
}
};
Expand Down Expand Up @@ -1319,6 +1330,7 @@ class TimelinePanel extends React.Component<IProps, IState> {
// get the list of events from the timeline window and the pending event list
private getEvents(): Pick<IState, "events" | "liveEvents" | "firstVisibleEventIndex"> {
const events: MatrixEvent[] = this.timelineWindow.getEvents();
console.log('TimelinePanel: getEvents', events.length);

// `arrayFastClone` performs a shallow copy of the array
// we want the last event to be decrypted first but displayed last
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,9 @@
"You can select all or individual messages to retry or delete": "You can select all or individual messages to retry or delete",
"Connectivity to the server has been lost.": "Connectivity to the server has been lost.",
"Sent messages will be stored until your connection has returned.": "Sent messages will be stored until your connection has returned.",
"History import detected.": "History import detected.",
"History was just imported somewhere in the room. In order to see the historical messages, refresh your timeline.": "History was just imported somewhere in the room. In order to see the historical messages, refresh your timeline.",
"Refresh timeline": "Refresh timeline",
"You seem to be uploading files, are you sure you want to quit?": "You seem to be uploading files, are you sure you want to quit?",
"You seem to be in a call, are you sure you want to quit?": "You seem to be in a call, are you sure you want to quit?",
"Search failed": "Search failed",
Expand Down
4 changes: 3 additions & 1 deletion src/indexing/EventIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,9 @@ export default class EventIndex extends EventEmitter {
// Add the events to the timeline of the file panel.
matrixEvents.forEach(e => {
if (!timelineSet.eventIdToTimeline(e.getId())) {
timelineSet.addEventToTimeline(e, timeline, direction == EventTimeline.BACKWARDS);
timelineSet.addEventToTimeline(e, timeline, {
toStartOfTimeline: direction == EventTimeline.BACKWARDS,
});
}
});

Expand Down