You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-29 16:43:09 +03:00
make /notification pagination actually work
This commit is contained in:
@@ -1793,6 +1793,38 @@ MatrixClient.prototype.paginateEventTimeline = function(eventTimeline, opts) {
|
||||
return promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset the notifTimelineSet entirely, paginating in some historical notifs as
|
||||
* a starting point for subsequent pagination.
|
||||
*/
|
||||
MatrixClient.prototype.resetNotifTimelineSet = function() {
|
||||
if (!this._notifTimelineSet) {
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: This thing is a total hack, and results in duplicate events being
|
||||
// added to the timeline both from /sync and /notifications, and lots of
|
||||
// slow and wasteful processing and pagination. The correct solution is to
|
||||
// extend /messages or /search or something to filter on notifications.
|
||||
|
||||
// use the fictitious token 'end'. in practice we would ideally give it
|
||||
// the oldest backwards pagination token from /sync, but /sync doesn't
|
||||
// know about /notifications, so we have no choice but to start paginating
|
||||
// from the current point in time. This may well overlap with historical
|
||||
// notifs which are then inserted into the timeline by /sync responses.
|
||||
this._notifTimelineSet.resetLiveTimeline('end', true);
|
||||
|
||||
// we could try to paginate a single event at this point in order to get
|
||||
// a more valid pagination token, but it just ends up with an out of order
|
||||
// timeline. given what a mess this is and given we're going to have duplicate
|
||||
// events anyway, just leave it with the dummy token for now.
|
||||
/*
|
||||
this.paginateNotifTimeline(this._notifTimelineSet.getLiveTimeline(), {
|
||||
backwards: true,
|
||||
limit: 1
|
||||
});
|
||||
*/
|
||||
};
|
||||
|
||||
/**
|
||||
* Take an EventTimeline, and backfill results from the notifications API.
|
||||
@@ -1853,11 +1885,14 @@ MatrixClient.prototype.paginateNotifTimeline = function(eventTimeline, opts) {
|
||||
for (var i = 0; i < res.notifications.length; i++) {
|
||||
var notification = res.notifications[i];
|
||||
var event = self.getEventMapper()(notification.event);
|
||||
event.setPushActions(notification.actions);
|
||||
event.setPushActions(
|
||||
PushProcessor.actionListToActionsObject(notification.actions)
|
||||
);
|
||||
event.event.room_id = notification.room_id; // XXX: gutwrenching
|
||||
matrixEvents[i] = event;
|
||||
}
|
||||
|
||||
eventTimeline.getEventTimelineSet()
|
||||
eventTimeline.getTimelineSet()
|
||||
.addEventsToTimeline(matrixEvents, backwards, eventTimeline, token);
|
||||
|
||||
// if we've hit the end of the timeline, we need to stop trying to
|
||||
|
||||
Reference in New Issue
Block a user