mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
emit after txn has been committed
to keep txn open for as short as possible, and avoid any errors caused as part of emit aborting txn
This commit is contained in:
parent
c0bd8fed82
commit
5cafb92fee
@ -21,7 +21,7 @@
|
|||||||
- DONE: build a very basic interface with
|
- DONE: build a very basic interface with
|
||||||
- DONE: a start/stop sync button
|
- DONE: a start/stop sync button
|
||||||
- DONE: a room list sorted alphabetically
|
- DONE: a room list sorted alphabetically
|
||||||
- do some preprocessing on sync response which can then be used by persister, summary, timeline
|
- DONE: do some preprocessing on sync response which can then be used by persister, summary, timeline
|
||||||
- support timeline
|
- support timeline
|
||||||
- clicking on a room list, you see messages (userId -> body)
|
- clicking on a room list, you see messages (userId -> body)
|
||||||
- send messages
|
- send messages
|
||||||
|
@ -12,9 +12,13 @@ export default class Room extends EventEmitter {
|
|||||||
this._emitCollectionChange = emitCollectionChange;
|
this._emitCollectionChange = emitCollectionChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
async applySync(roomResponse, membership, txn) {
|
persistSync(roomResponse, membership, txn) {
|
||||||
const changed = this._summary.applySync(roomResponse, membership, txn);
|
const changed = this._summary.applySync(roomResponse, membership, txn);
|
||||||
this._persister.persistSync(roomResponse, txn);
|
this._persister.persistSync(roomResponse, txn);
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
emitSync(changed) {
|
||||||
if (changed) {
|
if (changed) {
|
||||||
this.emit("change");
|
this.emit("change");
|
||||||
(this._emitCollectionChange)(this);
|
(this._emitCollectionChange)(this);
|
||||||
|
@ -76,10 +76,11 @@ export default class Sync extends EventEmitter {
|
|||||||
storeNames.roomTimeline,
|
storeNames.roomTimeline,
|
||||||
storeNames.roomState,
|
storeNames.roomState,
|
||||||
]);
|
]);
|
||||||
try {
|
const roomChanges = [];
|
||||||
this._session.applySync(syncToken, response.account_data, syncTxn);
|
try {
|
||||||
// to_device
|
this._session.applySync(syncToken, response.account_data, syncTxn);
|
||||||
// presence
|
// to_device
|
||||||
|
// presence
|
||||||
if (response.rooms) {
|
if (response.rooms) {
|
||||||
parseRooms(response.rooms, (roomId, roomResponse, membership) => {
|
parseRooms(response.rooms, (roomId, roomResponse, membership) => {
|
||||||
let room = this._session.rooms.get(roomId);
|
let room = this._session.rooms.get(roomId);
|
||||||
@ -87,7 +88,8 @@ export default class Sync extends EventEmitter {
|
|||||||
room = this._session.createRoom(roomId);
|
room = this._session.createRoom(roomId);
|
||||||
}
|
}
|
||||||
console.log(` * applying sync response to room ${roomId} ...`);
|
console.log(` * applying sync response to room ${roomId} ...`);
|
||||||
room.applySync(roomResponse, membership, syncTxn);
|
const changes = room.persistSync(roomResponse, membership, syncTxn);
|
||||||
|
roomChanges.push({room, changes});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
@ -104,6 +106,11 @@ export default class Sync extends EventEmitter {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new StorageError("unable to commit sync tranaction", err);
|
throw new StorageError("unable to commit sync tranaction", err);
|
||||||
}
|
}
|
||||||
|
// emit room related events after txn has been closed
|
||||||
|
for(let {room, changes} of roomChanges) {
|
||||||
|
room.emitSync(changes);
|
||||||
|
}
|
||||||
|
|
||||||
return syncToken;
|
return syncToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user