mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Merge pull request #132 from matrix-org/gnuxie/remove-messages-sync
Use `rooms/initialSync` instead of `sync` to fetch room history. See https://github.com/matrix-org/synapse/issues/10842.
This commit is contained in:
commit
7b7130b39f
22
src/utils.ts
22
src/utils.ts
@ -122,11 +122,14 @@ export async function getMessagesByUserIn(client: MatrixClient, sender: string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialSync() {
|
/**
|
||||||
const qs = {
|
* Note: `rooms/initialSync` is deprecated. However, there is no replacement for this API for the time being.
|
||||||
filter: JSON.stringify(filter),
|
* While previous versions of this function used `/sync`, experience shows that it can grow extremely
|
||||||
};
|
* slow (4-5 minutes long) when we need to sync many large rooms, which leads to timeouts and
|
||||||
return client.doRequest("GET", "/_matrix/client/r0/sync", qs);
|
* breakage in Mjolnir, see https://github.com/matrix-org/synapse/issues/10842.
|
||||||
|
*/
|
||||||
|
function roomInitialSync() {
|
||||||
|
return client.doRequest("GET", `/_matrix/client/r0/rooms/${encodeURIComponent(roomId)}/initialSync`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function backfill(from: string) {
|
function backfill(from: string) {
|
||||||
@ -140,14 +143,15 @@ export async function getMessagesByUserIn(client: MatrixClient, sender: string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do an initial sync first to get the batch token
|
// Do an initial sync first to get the batch token
|
||||||
const response = await initialSync();
|
const response = await roomInitialSync();
|
||||||
if (!response) return [];
|
if (!response) return [];
|
||||||
|
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
|
||||||
const timeline = (((response['rooms'] || {})['join'] || {})[roomId] || {})['timeline'] || {};
|
const timeline = (response['messages'] || {})
|
||||||
const syncedMessages = timeline['events'] || [];
|
const syncedMessages = timeline['chunk'] || [];
|
||||||
let token = timeline['prev_batch'] || response['next_batch'];
|
// The start of the chunk has the oldest events.
|
||||||
|
let token = timeline['start'];
|
||||||
let bfMessages = {chunk: syncedMessages, end: token};
|
let bfMessages = {chunk: syncedMessages, end: token};
|
||||||
do {
|
do {
|
||||||
const messages: any[] = [];
|
const messages: any[] = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user