Skip to content

Commit 1ab5460

Browse files
committed
Clean up raw commit
1 parent f44489d commit 1ab5460

File tree

3 files changed

+31
-76
lines changed

3 files changed

+31
-76
lines changed

Diff for: src/client.ts

-9
Original file line numberDiff line numberDiff line change
@@ -5135,7 +5135,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
51355135
* @return {module:http-api.MatrixError} Rejects: with an error response.
51365136
*/
51375137
public scrollback(room: Room, limit = 30, callback?: Callback): Promise<Room> {
5138-
console.log('client: scrollback');
51395138
if (utils.isFunction(limit)) {
51405139
callback = limit as any as Callback; // legacy
51415140
limit = undefined;
@@ -5151,13 +5150,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
51515150
}
51525151

51535152
if (room.oldState.paginationToken === null) {
5154-
console.log('client: scrollabck already at the start.', room.oldState);
51555153
return Promise.resolve(room); // already at the start.
51565154
}
51575155
// attempt to grab more events from the store first
51585156
const numAdded = this.store.scrollback(room, limit).length;
51595157
if (numAdded === limit) {
5160-
console.log(`client: scrollback store contained everything we needed numAdded=${numAdded} limit=${limit}`);
51615158
// store contained everything we needed.
51625159
return Promise.resolve(room);
51635160
}
@@ -5184,7 +5181,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
51845181
const [timelineEvents, threadedEvents] = room.partitionThreadedEvents(matrixEvents);
51855182

51865183
this.processBeaconEvents(room, matrixEvents);
5187-
console.log('client: scrollback addEventsToTimeline', timelineEvents.length, room.getLiveTimeline());
51885184
room.addEventsToTimeline(timelineEvents, true, room.getLiveTimeline());
51895185
await this.processThreadEvents(room, threadedEvents, true);
51905186

@@ -5311,9 +5307,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
53115307
}
53125308

53135309
// Here we handle non-thread timelines only, but still process any thread events to populate thread summaries.
5314-
console.log('getEventTimeline: timeline count1', timelineSet.getTimelines().length);
53155310
let timeline = timelineSet.getTimelineForEvent(events[0].getId());
5316-
console.log('getEventTimeline: timeline count2', timelineSet.getTimelines().length);
53175311
if (timeline) {
53185312
timeline.getState(EventTimeline.BACKWARDS).setUnknownStateEvents(res.state.map(mapper));
53195313
} else {
@@ -5322,11 +5316,8 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
53225316
timeline.getState(EventTimeline.FORWARDS).paginationToken = res.end;
53235317
}
53245318

5325-
console.log('getEventTimeline: timeline before', timelineSet.getTimelines().length, timeline.getEvents().length);
5326-
53275319
const [timelineEvents, threadedEvents] = timelineSet.room.partitionThreadedEvents(events);
53285320
timelineSet.addEventsToTimeline(timelineEvents, true, timeline, res.start);
5329-
console.log('getEventTimeline: timeline after', timelineSet.getTimelines().length, timeline.getEvents().length);
53305321
// The target event is not in a thread but process the contextual events, so we can show any threads around it.
53315322
await this.processThreadEvents(timelineSet.room, threadedEvents, true);
53325323
this.processBeaconEvents(timelineSet.room, events);

Diff for: src/models/event-timeline-set.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export class EventTimelineSet extends TypedEventEmitter<EmittedEvents, EventTime
217217
}
218218

219219
/**
220-
* Get the live timeline for this room.
220+
* Set the live timeline for this room.
221221
*
222222
* @return {module:models/event-timeline~EventTimeline} live timeline
223223
*/

Diff for: src/models/room.ts

+30-66
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,25 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
929929
});
930930
}
931931

932-
// TODO
932+
/**
933+
* Empty out the current live timeline and re-request it. This is used when
934+
* historical messages are imported into the room via MSC2716 `/batch_send
935+
* because the client may already have that section of the timeline loaded.
936+
* We need to force the client to throw away their current timeline so that
937+
* when they back paginate over the area again with the historical messages
938+
* in between, it grabs the newly imported messages. We can listen for
939+
* `EventType.Marker`, in order to tell when historical messages are ready
940+
* to be discovered in the room and the timeline needs a refresh. The SDK
941+
* emits a `RoomEvent.historyImportedWithinTimeline` event when we detect a
942+
* valid marker and can check the needs refresh status via
943+
* `room.getTimelineNeedsRefresh()`.
944+
*/
933945
public async refreshLiveTimeline(): Promise<void> {
934946
const liveTimelineBefore = this.getLiveTimeline();
935947
const forwardPaginationToken = liveTimelineBefore.getPaginationToken(EventTimeline.FORWARDS);
936948
const eventsBefore = liveTimelineBefore.getEvents();
937949
const mostRecentEventInTimeline = eventsBefore[eventsBefore.length - 1];
950+
logger.log(`[refreshLiveTimeline] for room ${this.roomId} at mostRecentEventInTimeline=${mostRecentEventInTimeline.getId()} forwardPaginationToken+${forwardPaginationToken}`)
938951

939952
// Empty out all of `this.timelineSets` but still keeps the same
940953
// `timelineSet` references around so the React code updates properly
@@ -944,81 +957,37 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
944957
// call `/context` and create a new timeline instead of returning the
945958
// same one.
946959
this.resetLiveTimeline(null, null);
947-
//this.resetLiveTimeline(forwardPaginationToken, forwardPaginationToken);
948960

949961
// Get a reference to the emptied out `timelineSet`
950962
//
951-
// TODO: Do we want to use `this.getLiveTimeline().getTimelineSet()` instead?
952-
// I think it's the same thing but what's more right?
963+
// TODO: Do we want to use `this.getLiveTimeline().getTimelineSet()`
964+
// instead? I think it's the same thing but what's more right?
953965
const timelineSet = this.getUnfilteredTimelineSet();
954-
955-
console.log(`refreshLiveTimeline: after resetLiveTimeline timelineSets=${this.getTimelineSets().length} getUnfilteredTimelineSet=`, timelineSet.getTimelines().length, timelineSet.getTimelines().map((timeline) => {
956-
return timeline.getEvents().length;
957-
}));
958966

959967
// Use `client.getEventTimeline(...)` to construct a new timeline from a
960968
// `/context` response state and events for the most recent event before
961-
// we reset everything. The `timelineSet` needs to be empty in order for
962-
// this function to call `/context`
969+
// we reset everything. The `timelineSet` we pass in needs to be empty
970+
// in order for this function to call `/context` and generate a new
971+
// timeline.
963972
const newTimeline = await this.client.getEventTimeline(timelineSet, mostRecentEventInTimeline.getId());
964-
console.log('refreshLiveTimeline: after getEventTimeline', timelineSet.getTimelines().length, timelineSet.getTimelines().map((timeline) => {
965-
return timeline.getEvents().length;
966-
}));
967973
// Set the pagination token back to the live sync token instead of using
968-
// the /context historical token so that it matches the next response from `/sync`
969-
// and we can properly continue the timeline.
974+
// the `/context` historical token so that it matches the next response
975+
// from `/sync` and we can properly continue the timeline.
970976
newTimeline.setPaginationToken(forwardPaginationToken, EventTimeline.FORWARDS);
971977

978+
// Set our new fresh timeline as the live timeline to continue syncing
979+
// forwards and back paginating from.
972980
timelineSet.setLiveTimeline(newTimeline);
973-
//timelineSet.getLiveTimeline().setNeighbouringTimeline(newTimeline, EventTimeline.FORWARDS);
974-
// Fixup `this.oldstate` so that `scrollback` has the pagination tokens available
981+
// Fixup `this.oldstate` so that `scrollback` has the pagination tokens
982+
// available
975983
this.fixUpLegacyTimelineFields();
976984

977-
// TODO: Set timelineNeedsRefresh = false
978-
979-
// const liveTimeline = this.getLiveTimeline();
980-
// liveTimeline.setPaginationToken(forwardPaginationToken, EventTimeline.BACKWARDS);
981-
// liveTimeline.setPaginationToken(forwardPaginationToken, EventTimeline.FORWARDS);
982-
// await new Promise((resolve) => {
983-
// setTimeout(async () => {
984-
// await this.client.scrollback(this, 30);
985-
// resolve(null);
986-
// }, 2000);
987-
// });
988-
//await this.client.scrollback(this, 30);
989-
this.emit(RoomEvent.TimelineRefresh, this, timelineSet);
990-
991-
// const timelineSet = new EventTimelineSet(this, this.opts);
992-
993-
// const liveTimeline = this.getLiveTimeline();
994-
// const events = liveTimeline.getEvents();
995-
// const mostRecentEventInTimeline = events[events.length - 1];
996-
997-
// // This will create a timeline with the given event and add it to the timelineSet
998-
// const newTimeline = await this.client.getEventTimeline(timelineSet, mostRecentEventInTimeline.getId());
985+
// The timeline has now been refreshed ✅
986+
this.setTimelineNeedsRefresh(false);
999987

1000-
// console.log('refreshTimeline: timelineSet',
1001-
// timelineSet,
1002-
// timelineSet.getTimelines().map((timeline) => {
1003-
// return timeline.getEvents().length;
1004-
// }),
1005-
// );
1006-
1007-
// // Since timelineSets is a readonly property, clear it out this way
1008-
// this.timelineSets.length = 0;
1009-
// // Keep track of the new timelineSet
1010-
// this.timelineSets.push(timelineSet);
1011-
// // Set our new timeline as the liveTimeline
1012-
// timelineSet.setLiveTimeline(newTimeline);
1013-
// // Fixup `this.oldstate` so that `scrollback` has the pagination tokens available
1014-
// this.fixUpLegacyTimelineFields();
1015-
1016-
1017-
// //this.emit(RoomEvent.Timeline, event, this.room, Boolean(toStartOfTimeline), false, data);
1018-
// // setTimeout(() => {
1019-
// // this.emit(RoomEvent.TimelineReset, this, timelineSet, true);
1020-
// // }, 1000);
1021-
// this.emit(RoomEvent.TimelineRefresh, this, timelineSet);
988+
// Emit an event which clients can react to and re-load the timeline
989+
// from the SDK
990+
this.emit(RoomEvent.TimelineRefresh, this, timelineSet);
1022991
}
1023992

1024993
/**
@@ -1048,11 +1017,6 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
10481017
* @private
10491018
*/
10501019
private fixUpLegacyTimelineFields(): void {
1051-
console.log(
1052-
'fixUpLegacyTimelineFields',
1053-
this.getLiveTimeline().getState(EventTimeline.BACKWARDS),
1054-
this.getLiveTimeline().getState(EventTimeline.FORWARDS)
1055-
);
10561020
// maintain this.timeline as a reference to the live timeline,
10571021
// and this.oldState and this.currentState as references to the
10581022
// state at the start and end of that timeline. These are more

0 commit comments

Comments
 (0)