mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
merge initial & incremental sync
This commit is contained in:
parent
b15136a9e8
commit
f0e5757692
@ -1,10 +1,20 @@
|
||||
import {parseRooms} from "./common";
|
||||
import {RequestAbortError} from "../network";
|
||||
import {HomeServerError} from "../error";
|
||||
import {RequestAbortError} from "./network.js";
|
||||
import {HomeServerError, StorageError} from "./error.js";
|
||||
|
||||
const INCREMENTAL_TIMEOUT = 30;
|
||||
|
||||
export class IncrementalSync {
|
||||
function parseRooms(responseSections, roomMapper) {
|
||||
return ["join", "invite", "leave"].map(membership => {
|
||||
const membershipSection = responseSections[membership];
|
||||
const results = Object.entries(membershipSection).map(([roomId, roomResponse]) => {
|
||||
const room = roomMapper(roomId, membership);
|
||||
return room.processInitialSync(roomResponse);
|
||||
});
|
||||
return results;
|
||||
}).reduce((allResults, sectionResults) => allResults.concat(sectionResults), []);
|
||||
}
|
||||
|
||||
export class Sync {
|
||||
constructor(network, session, storage) {
|
||||
this._network = network;
|
||||
this._session = session;
|
@ -1,10 +0,0 @@
|
||||
export function parseRooms(responseSections, roomMapper) {
|
||||
return ["join", "invite", "leave"].map(membership => {
|
||||
const membershipSection = responseSections[membership];
|
||||
const results = Object.entries(membershipSection).map(([roomId, roomResponse]) => {
|
||||
const room = roomMapper(roomId, membership);
|
||||
return room.processInitialSync(roomResponse);
|
||||
});
|
||||
return results;
|
||||
}).reduce((allResults, sectionResults) => allResults.concat(sectionResults), []);
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
import {parseRooms} from "./common";
|
||||
|
||||
// TODO make abortable
|
||||
export async function initialSync(network, session) {
|
||||
const response = await network.sync().response();
|
||||
const rooms = await createRooms(response.rooms, session);
|
||||
const sessionData = {syncToken: response.next_batch};
|
||||
const accountData = response.account_data;
|
||||
await session.applySync(rooms, response.next_batch, response.account_data);
|
||||
}
|
||||
|
||||
function createRooms(responseSections, session) {
|
||||
const roomPromises = parseRooms(responseSections, (roomId, roomResponse, membership) => {
|
||||
const room = await session.createRoom(roomId);
|
||||
await room.initialSync(roomResponse, membership);
|
||||
return room;
|
||||
});
|
||||
return Promise.all(roomPromises);
|
||||
}
|
Loading…
Reference in New Issue
Block a user