You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-11-07 10:46:24 +03:00
List common rooms in MemberInfo
This commit is contained in:
@@ -21,18 +21,13 @@ limitations under the License.
|
||||
*/
|
||||
export default class DMRoomMap {
|
||||
constructor(matrixClient) {
|
||||
this.roomToUser = null;
|
||||
|
||||
const mDirectEvent = matrixClient.getAccountData('m.direct');
|
||||
if (!mDirectEvent) {
|
||||
this.userToRooms = {};
|
||||
this.roomToUser = {};
|
||||
} else {
|
||||
this.userToRooms = mDirectEvent.getContent();
|
||||
this.roomToUser = {};
|
||||
for (const user of Object.keys(this.userToRooms)) {
|
||||
for (const roomId of this.userToRooms[user]) {
|
||||
this.roomToUser[roomId] = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +36,24 @@ export default class DMRoomMap {
|
||||
}
|
||||
|
||||
getUserIdForRoomId(roomId) {
|
||||
if (this.roomToUser == null) {
|
||||
// we lazily populate roomToUser so you can use
|
||||
// this class just to call getDMRoomsForUserId
|
||||
// which doesn't do very much, but is a fairly
|
||||
// convenient wrapper and there's no point
|
||||
// iterating through the map if getUserIdForRoomId()
|
||||
// is never called.
|
||||
this._populateRoomToUser();
|
||||
}
|
||||
return this.roomToUser[roomId];
|
||||
}
|
||||
|
||||
_populateRoomToUser() {
|
||||
this.roomToUser = {};
|
||||
for (const user of Object.keys(this.userToRooms)) {
|
||||
for (const roomId of this.userToRooms[user]) {
|
||||
this.roomToUser[roomId] = user;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user