EventIndex: Add a checkpoint if a room turns into a encrypted one.
This commit is contained in:
parent
b35cde4546
commit
39bcd8d56d
1 changed files with 54 additions and 15 deletions
|
@ -182,6 +182,14 @@ export default class EventIndex extends EventEmitter {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ev.getType() === "m.room.encryption") {
|
||||||
|
console.log("EventIndex: Adding checkpoint for newly encrypted room",
|
||||||
|
room.roomId);
|
||||||
|
|
||||||
|
this.addRoomCheckpoint(room.roomId, true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If the event is not yet decrypted mark it for the
|
// If the event is not yet decrypted mark it for the
|
||||||
// Event.decrypted callback.
|
// Event.decrypted callback.
|
||||||
if (ev.isBeingDecrypted()) {
|
if (ev.isBeingDecrypted()) {
|
||||||
|
@ -234,26 +242,12 @@ export default class EventIndex extends EventEmitter {
|
||||||
*/
|
*/
|
||||||
onTimelineReset = async (room, timelineSet, resetAllTimelines) => {
|
onTimelineReset = async (room, timelineSet, resetAllTimelines) => {
|
||||||
if (room === null) return;
|
if (room === null) return;
|
||||||
|
|
||||||
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
|
||||||
if (!MatrixClientPeg.get().isRoomEncrypted(room.roomId)) return;
|
if (!MatrixClientPeg.get().isRoomEncrypted(room.roomId)) return;
|
||||||
|
|
||||||
const timeline = room.getLiveTimeline();
|
|
||||||
const token = timeline.getPaginationToken("b");
|
|
||||||
|
|
||||||
const backwardsCheckpoint = {
|
|
||||||
roomId: room.roomId,
|
|
||||||
token: token,
|
|
||||||
fullCrawl: false,
|
|
||||||
direction: "b",
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log("EventIndex: Added checkpoint because of a limited timeline",
|
console.log("EventIndex: Added checkpoint because of a limited timeline",
|
||||||
backwardsCheckpoint);
|
backwardsCheckpoint);
|
||||||
|
|
||||||
await indexManager.addCrawlerCheckpoint(backwardsCheckpoint);
|
this.addRoomCheckpoint(room.roomId, false);
|
||||||
|
|
||||||
this.crawlerCheckpoints.push(backwardsCheckpoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -319,6 +313,51 @@ export default class EventIndex extends EventEmitter {
|
||||||
this.emit("changedCheckpoint", this.currentRoom());
|
this.emit("changedCheckpoint", this.currentRoom());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addEventsFromLiveTimeline(timeline) {
|
||||||
|
let events = timeline.getEvents();
|
||||||
|
|
||||||
|
for (let i = 0; i < events.length; i++) {
|
||||||
|
const ev = events[i];
|
||||||
|
await this.addLiveEventToIndex(ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async addRoomCheckpoint(roomId, fullCrawl = false) {
|
||||||
|
const indexManager = PlatformPeg.get().getEventIndexingManager();
|
||||||
|
const client = MatrixClientPeg.get();
|
||||||
|
const room = client.getRoom(roomId);
|
||||||
|
|
||||||
|
if (!room) return;
|
||||||
|
|
||||||
|
const timeline = room.getLiveTimeline();
|
||||||
|
let token = timeline.getPaginationToken("b");
|
||||||
|
|
||||||
|
if(!token) {
|
||||||
|
// The room doesn't contain any tokens, meaning the live timeline
|
||||||
|
// contains all the events, add those to the index.
|
||||||
|
await this.addEventsFromLiveTimeline(timeline);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkpoint = {
|
||||||
|
roomId: room.roomId,
|
||||||
|
token: token,
|
||||||
|
fullCrawl: fullCrawl,
|
||||||
|
direction: "b",
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("EventIndex: Adding checkpoint", checkpoint);
|
||||||
|
|
||||||
|
try{
|
||||||
|
await indexManager.addCrawlerCheckpoint(checkpoint);
|
||||||
|
} catch (e) {
|
||||||
|
console.log("EventIndex: Error adding new checkpoint for room",
|
||||||
|
room.roomId, checkpoint, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.crawlerCheckpoints.push(checkpoint);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main crawler loop.
|
* The main crawler loop.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue