You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-19 16:42:09 +03:00
Handle ephemeral and account_data events
This commit is contained in:
61
lib/sync.js
61
lib/sync.js
@@ -277,10 +277,18 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
|||||||
var room = joinObj.room;
|
var room = joinObj.room;
|
||||||
var stateEvents = self._mapSyncEventsFormat(joinObj.state, room);
|
var stateEvents = self._mapSyncEventsFormat(joinObj.state, room);
|
||||||
var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room);
|
var timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room);
|
||||||
|
var ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral);
|
||||||
|
var accountDataEvents = self._mapSyncEventsFormat(joinObj.account_data);
|
||||||
|
|
||||||
|
if (joinObj.timeline.limited) {
|
||||||
|
// nuke the timeline so we don't get holes
|
||||||
|
room.timeline = [];
|
||||||
|
}
|
||||||
self._processRoomEvents(
|
self._processRoomEvents(
|
||||||
room, stateEvents, timelineEvents, joinObj.timeline.prev_batch
|
room, stateEvents, timelineEvents, joinObj.timeline.prev_batch
|
||||||
);
|
);
|
||||||
// TODO: Receipts, Typing, Tags from ephermeral + account_data
|
room.addEvents(ephemeralEvents);
|
||||||
|
room.addEvents(accountDataEvents);
|
||||||
room.recalculate(client.credentials.userId);
|
room.recalculate(client.credentials.userId);
|
||||||
if (joinObj.isBrandNewRoom) {
|
if (joinObj.isBrandNewRoom) {
|
||||||
client.store.storeRoom(room);
|
client.store.storeRoom(room);
|
||||||
@@ -296,57 +304,6 @@ SyncApi.prototype._sync = function(syncOptions, attempt) {
|
|||||||
console.error("Caught /sync error:");
|
console.error("Caught /sync error:");
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
var i, j;
|
|
||||||
// intercept the results and put them into our store
|
|
||||||
if (!(client.store instanceof StubStore)) {
|
|
||||||
// group receipts by room ID.
|
|
||||||
var receiptsByRoom = {};
|
|
||||||
data.receipts = data.receipts || [];
|
|
||||||
utils.forEach(data.receipts.map(client.getEventMapper()),
|
|
||||||
function(receiptEvent) {
|
|
||||||
if (!receiptsByRoom[receiptEvent.getRoomId()]) {
|
|
||||||
receiptsByRoom[receiptEvent.getRoomId()] = [];
|
|
||||||
}
|
|
||||||
receiptsByRoom[receiptEvent.getRoomId()].push(receiptEvent);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
for (i = 0; i < data.rooms.length; i++) {
|
|
||||||
|
|
||||||
_processRoomEvents(
|
|
||||||
client, room, data.rooms[i].state, data.rooms[i].messages
|
|
||||||
);
|
|
||||||
|
|
||||||
var receipts = receiptsByRoom[room.roomId] || [];
|
|
||||||
for (j = 0; j < receipts.length; j++) {
|
|
||||||
room.addReceipt(receipts[j]);
|
|
||||||
}
|
|
||||||
|
|
||||||
var privateUserData = data.rooms[i].account_data || [];
|
|
||||||
var privateUserDataEvents =
|
|
||||||
utils.map(privateUserData, client.getEventMapper());
|
|
||||||
for (j = 0; j < privateUserDataEvents.length; j++) {
|
|
||||||
var event = privateUserDataEvents[j];
|
|
||||||
if (event.getType() === "m.tag") {
|
|
||||||
room.addTags(event);
|
|
||||||
}
|
|
||||||
// XXX: unhandled private user data event - we should probably
|
|
||||||
// put it somewhere useful once the API has settled
|
|
||||||
}
|
|
||||||
|
|
||||||
// cache the name/summary/etc prior to storage since we don't
|
|
||||||
// know how the store will serialise the Room.
|
|
||||||
room.recalculate(client.credentials.userId);
|
|
||||||
|
|
||||||
client.store.storeRoom(room);
|
|
||||||
client.emit("Room", room);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// emit synced events
|
// emit synced events
|
||||||
if (!syncOptions.hasSyncedBefore) {
|
if (!syncOptions.hasSyncedBefore) {
|
||||||
|
Reference in New Issue
Block a user