1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-28 05:03:59 +03:00

introduce Room.myMembership event

As you don't always have your own member with lazy loading
of members enabled, looking at the sync response section
where a room appears is the most reliable way of determining
the syncing user's membership in a room.

Before we already used this to read the
current room membership with `room.getMyMembership()`,
but we were still using the `RoomMember.membership` event
to detect when the syncing user's membership changed.

This event will help make those checks work well with LL enabled.
This commit is contained in:
Bruno Windels
2018-09-17 18:20:49 +02:00
parent 47a1adc864
commit eb690e14e4
2 changed files with 20 additions and 12 deletions

View File

@@ -123,6 +123,7 @@ SyncApi.prototype.createRoom = function(roomId) {
"Room.timelineReset",
"Room.localEchoUpdated",
"Room.accountData",
"Room.myMembership",
]);
this._registerStateListeners(room);
return room;
@@ -976,9 +977,10 @@ SyncApi.prototype._processSyncResponse = async function(
// Handle invites
inviteRooms.forEach(function(inviteObj) {
const room = inviteObj.room;
room.setSyncedMembership("invite");
const stateEvents =
self._mapSyncEventsFormat(inviteObj.invite_state, room);
room.updateMyMembership("invite");
self._processRoomEvents(room, stateEvents);
if (inviteObj.isBrandNewRoom) {
room.recalculate();
@@ -993,7 +995,6 @@ SyncApi.prototype._processSyncResponse = async function(
// Handle joins
await Promise.mapSeries(joinRooms, async function(joinObj) {
const room = joinObj.room;
room.setSyncedMembership("join");
const stateEvents = self._mapSyncEventsFormat(joinObj.state, room);
const timelineEvents = self._mapSyncEventsFormat(joinObj.timeline, room);
const ephemeralEvents = self._mapSyncEventsFormat(joinObj.ephemeral);
@@ -1009,6 +1010,8 @@ SyncApi.prototype._processSyncResponse = async function(
);
}
room.updateMyMembership("join");
joinObj.timeline = joinObj.timeline || {};
if (joinObj.isBrandNewRoom) {
@@ -1116,8 +1119,6 @@ SyncApi.prototype._processSyncResponse = async function(
// Handle leaves (e.g. kicked rooms)
leaveRooms.forEach(function(leaveObj) {
const room = leaveObj.room;
room.setSyncedMembership("leave");
const stateEvents =
self._mapSyncEventsFormat(leaveObj.state, room);
const timelineEvents =
@@ -1125,6 +1126,8 @@ SyncApi.prototype._processSyncResponse = async function(
const accountDataEvents =
self._mapSyncEventsFormat(leaveObj.account_data);
room.updateMyMembership("leave");
self._processRoomEvents(room, stateEvents, timelineEvents);
room.addAccountData(accountDataEvents);
@@ -1145,8 +1148,6 @@ SyncApi.prototype._processSyncResponse = async function(
accountDataEvents.forEach(function(e) {
client.emit("event", e);
});
room.onLeft();
});
// update the notification timeline, if appropriate.