Skip to content

Commit

Permalink
Merge pull request #695 from matrix-org/dbkr/hide_replaced_rooms
Browse files Browse the repository at this point in the history
Add getVisibleRooms()
  • Loading branch information
dbkr authored Aug 23, 2018
2 parents dffe0b3 + 7c66f91 commit 8c3d1df
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,37 @@ MatrixClient.prototype.getRooms = function() {
return this.store.getRooms();
};

/**
* Retrieve all rooms that should be displayed to the user
* This is essentially getRooms() with some rooms filtered out, eg. old versions
* of rooms that have been replaced or (in future) other rooms that have been
* marked at the protocol level as not to be displayed to the user.
* @return {Room[]} A list of rooms, or an empty list if there is no data store.
*/
MatrixClient.prototype.getVisibleRooms = function() {
const allRooms = this.store.getRooms();

const replacedRooms = new Set();
for (const r of allRooms) {
const createEvent = r.currentState.getStateEvents('m.room.create', '');
// invites are included in this list and we don't know their create events yet
if (createEvent) {
const predecessor = createEvent.getContent()['predecessor'];
if (predecessor && predecessor['room_id']) {
replacedRooms.add(predecessor['room_id']);
}
}
}

return allRooms.filter((r) => {
const tombstone = r.currentState.getStateEvents('m.room.tombstone', '');
if (tombstone && replacedRooms.has(r.roomId)) {
return false;
}
return true;
});
};

/**
* Retrieve a user.
* @param {string} userId The user ID to retrieve.
Expand Down

0 comments on commit 8c3d1df

Please sign in to comment.