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

Commit

Permalink
Raw refreshLiveTimeline usage that seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Apr 16, 2022
1 parent ed910bb commit 8d61226
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/components/structures/MessagePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,8 @@ export default class MessagePanel extends React.Component<IProps, IState> {
"mx_MessagePanel_narrow": this.context.narrow,
});

//console.log('MessagePanel: render', this.props.events.length)

return (
<ErrorBoundary>
<ScrollPanel
Expand Down
11 changes: 7 additions & 4 deletions src/components/structures/RoomStatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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(),
timelineNeedsRefresh: true // TODO: Put this back to this.props.room.getTimelineNeedsRefresh(),
};
}

Expand Down Expand Up @@ -153,10 +153,13 @@ export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
// 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.props.room.refreshLiveTimeline();
//timelinePanel.refreshTimeline();

this.setState({
timelineNeedsRefresh: false,
});
// TODO: Uncomment
// this.setState({
// timelineNeedsRefresh: false,
// });
};

private onRoomLocalEchoUpdated = (ev: MatrixEvent, room: Room) => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/structures/RoomView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2065,11 +2065,14 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
highlightedEventId = this.state.initialEventId;
}

const timelineSet = this.state.room.getUnfilteredTimelineSet();
console.log('RoomView: timelineSet', timelineSet);

// console.info("ShowUrlPreview for %s is %s", this.state.room.roomId, this.state.showUrlPreview);
const messagePanel = (
<TimelinePanel
ref={this.gatherTimelinePanelRef}
timelineSet={this.state.room.getUnfilteredTimelineSet()}
timelineSet={timelineSet}
showReadReceipts={this.state.showReadReceipts}
manageReadReceipts={!this.state.isPeeking}
sendReadReceiptOnLoad={!this.state.wasContextSwitch}
Expand Down
17 changes: 16 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 => {
console.log(`onRoomTimelineRefresh skipping=${timelineSet !== this.props.timelineSet}`);
if (timelineSet !== this.props.timelineSet) return;

this.refreshTimeline();
};

private onRoomTimelineReset = (room: Room, timelineSet: EventTimelineSet): void => {
console.log(`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()) {
this.loadTimeline();
}
};
Expand Down Expand Up @@ -1181,6 +1192,9 @@ class TimelinePanel extends React.Component<IProps, IState> {
* @param {boolean?} scrollIntoView whether to scroll the event into view.
*/
private loadTimeline(eventId?: string, pixelOffset?: number, offsetBase?: number, scrollIntoView = true): void {
console.log('TimelinePanel: loadTimeline', this.props.timelineSet.getTimelines(), this.props.timelineSet.getTimelines().map((timeline) => {
return timeline.getEvents().length;
}))
this.timelineWindow = new TimelineWindow(
MatrixClientPeg.get(), this.props.timelineSet,
{ windowLimit: this.props.timelineCap });
Expand Down Expand Up @@ -1319,6 +1333,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

0 comments on commit 8d61226

Please sign in to comment.