Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4997 from matrix-org/t3chguy/fix/14526
Browse files Browse the repository at this point in the history
Fix filtering by community not showing DM rooms with community members
  • Loading branch information
t3chguy authored Jul 16, 2020
2 parents b1d57ca + 3498922 commit 725fa7d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/stores/room-list/filters/CommunityFilterCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import { EventEmitter } from "events";
import GroupStore from "../../GroupStore";
import { arrayHasDiff } from "../../../utils/arrays";
import { IDestroyable } from "../../../utils/IDestroyable";
import DMRoomMap from "../../../utils/DMRoomMap";

/**
* A filter condition for the room list which reveals rooms which
* are a member of a given community.
*/
export class CommunityFilterCondition extends EventEmitter implements IFilterCondition, IDestroyable {
private roomIds: string[] = [];
private userIds: string[] = [];

constructor(private community: Group) {
super();
Expand All @@ -43,15 +45,19 @@ export class CommunityFilterCondition extends EventEmitter implements IFilterCon
}

public isVisible(room: Room): boolean {
return this.roomIds.includes(room.roomId);
return this.roomIds.includes(room.roomId) ||
this.userIds.includes(DMRoomMap.shared().getUserIdForRoomId(room.roomId));
}

private onStoreUpdate = async (): Promise<any> => {
// We don't actually know if the room list changed for the community, so just
// check it again.
// We don't actually know if the room list changed for the community, so just check it again.
const beforeRoomIds = this.roomIds;
this.roomIds = (await GroupStore.getGroupRooms(this.community.groupId)).map(r => r.roomId);
if (arrayHasDiff(beforeRoomIds, this.roomIds)) {

const beforeUserIds = this.userIds;
this.userIds = (await GroupStore.getGroupMembers(this.community.groupId)).map(u => u.userId);

if (arrayHasDiff(beforeRoomIds, this.roomIds) || arrayHasDiff(beforeUserIds, this.userIds)) {
this.emit(FILTER_CHANGED);
}
};
Expand Down

0 comments on commit 725fa7d

Please sign in to comment.