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

Commit

Permalink
Allow finding group DMs by members in spotlight
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Jun 28, 2022
1 parent 8b84195 commit aca1ed0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
34 changes: 25 additions & 9 deletions src/components/views/dialogs/spotlight/SpotlightDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,33 @@ const toPublicRoomResult = (publicRoom: IPublicRoomsChunkRoom): IPublicRoomResul
});

const toRoomResult = (room: Room): IRoomResult => {
const myUserId = MatrixClientPeg.get().getUserId();
const otherUserId = DMRoomMap.shared().getUserIdForRoomId(room.roomId);

if (otherUserId) {
return {
room,
section: Section.People,
filter: [Filter.People],
query: [
otherUserId.toLowerCase(),
room.getMember(otherUserId)?.name.toLowerCase(),
].filter(Boolean),
};
const otherMembers = room.getMembers().filter(it => it.userId !== myUserId);
const query = [
...otherMembers.map(it => it.name.toLowerCase()),
...otherMembers.map(it => it.userId.toLowerCase()),
].filter(Boolean);

// if we’ve got more than 2 users, don’t treat it like a regular DM
const isGroupDm = room.getMembers().length > 2;
if (isGroupDm) {
return {
room,
section: Section.Rooms,
filter: [],
query,
};
} else {
return {
room,
section: Section.People,
filter: [Filter.People],
query,
};
}
} else if (room.isSpaceRoom()) {
return {
room,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/i18n-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ export function roomContextDetailsText(room: Room): string {
if (room.isSpaceRoom()) return undefined;

const dmPartner = DMRoomMap.shared().getUserIdForRoomId(room.roomId);
if (dmPartner) {
// if we’ve got more than 2 users, don’t treat it like a regular DM
const isGroupDm = room.getMembers().length > 2;
if (dmPartner && !isGroupDm) {
return dmPartner;
}

Expand Down

0 comments on commit aca1ed0

Please sign in to comment.