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

Commit 66ea757

Browse files
committed
Ask to refresh timeline when historical messages are imported (MSC2716)
Associated matrix-js-sdk PR: matrix-org/matrix-js-sdk#2282
1 parent a4d3da7 commit 66ea757

File tree

3 files changed

+71
-2
lines changed

3 files changed

+71
-2
lines changed

res/css/structures/_RoomStatusBar.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ limitations under the License.
145145
mask-image: url('$(res)/img/element-icons/retry.svg');
146146
}
147147
}
148+
149+
&.mx_RoomStatusBar_refreshTimelineBtn {
150+
&::before {
151+
mask-image: url('$(res)/img/element-icons/retry.svg');
152+
}
153+
}
148154
}
149155

150156
.mx_InlineSpinner {

src/components/structures/RoomStatusBar.tsx

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ interface IState {
7979
syncStateData: ISyncStateData;
8080
unsentMessages: MatrixEvent[];
8181
isResending: boolean;
82+
timelineNeedsRefresh: boolean;
8283
}
8384

8485
export 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
}

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3042,6 +3042,9 @@
30423042
"You can select all or individual messages to retry or delete": "You can select all or individual messages to retry or delete",
30433043
"Connectivity to the server has been lost.": "Connectivity to the server has been lost.",
30443044
"Sent messages will be stored until your connection has returned.": "Sent messages will be stored until your connection has returned.",
3045+
"History import detected.": "History import detected.",
3046+
"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.",
3047+
"Refresh timeline": "Refresh timeline",
30453048
"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?",
30463049
"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?",
30473050
"Search failed": "Search failed",

0 commit comments

Comments
 (0)