Skip to content

Commit

Permalink
Merge pull request #72 from verji/jts/1989-invite-suggestions
Browse files Browse the repository at this point in the history
Jts/1989 invite suggestions
  • Loading branch information
JohnSimonsen authored Aug 20, 2024
2 parents 9eb9448 + 6efa567 commit 105311a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/components/views/dialogs/InviteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import { NonEmptyArray } from "../../../@types/common";
import { SdkContextClass } from "../../../contexts/SDKContext";
import { UserProfilesStore } from "../../../stores/UserProfilesStore";
import { Key } from "../../../Keyboard";
import SpaceStore from "../../../stores/spaces/SpaceStore";

// we have a number of types defined from the Matrix spec which can't reasonably be altered here.
/* eslint-disable camelcase */
Expand Down Expand Up @@ -425,10 +426,20 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
private encryptionByDefault = false;
private profilesStore: UserProfilesStore;
private allowOnboardingFlag = false;
// Verji
private spaceMembers = [] as RoomMember[];
private spaceMemberIds = [] as string[];
// Verji End

public constructor(props: Props) {
super(props);

// Verji Start - generate a list of userId's which are members in currently active space
this.spaceMembers = SpaceStore.instance.activeSpaceRoom?.getJoinedMembers() ?? ([] as RoomMember[]);
this.spaceMembers.forEach((m) => {
console.log(m);
this.spaceMemberIds.push(m.userId);
});
// Verji end
if (props.kind === InviteKind.Invite && !props.roomId) {
throw new Error("When using InviteKind.Invite a roomId is required for an InviteDialog");
} else if (props.kind === InviteKind.CallTransfer && !props.call) {
Expand Down Expand Up @@ -458,7 +469,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
targetEmails: [], // Verji
filterText: this.props.initialText || "",
// Mutates alreadyInvited set so that buildSuggestions doesn't duplicate any users
recents: InviteDialog.buildRecents(excludedIds),
recents: InviteDialog.buildRecents(excludedIds, this.spaceMemberIds), //VERJI add param spaceMemberIds
numRecentsShown: INITIAL_ROOMS_SHOWN,
suggestions: this.buildSuggestions(excludedIds),
numSuggestionsShown: INITIAL_ROOMS_SHOWN,
Expand Down Expand Up @@ -523,7 +534,8 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
externals.forEach((id) => excludedTargetIds.add(id));
}

public static buildRecents(excludedTargetIds: Set<string>): Result[] {
// VERJI added param activeSpaceMembers - used to fileter the recents based on membership in space
public static buildRecents(excludedTargetIds: Set<string>, activeSpaceMembers: string[]): Result[] {
const rooms = DMRoomMap.shared().getUniqueRoomsWithIndividuals(); // map of userId => js-sdk Room

// Also pull in all the rooms tagged as DefaultTagID.DM so we don't miss anything. Sometimes the
Expand Down Expand Up @@ -553,6 +565,15 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
continue;
}

// Verji Start - filter out users not in space
if (!activeSpaceMembers.includes(userId)) {
logger.warn(
`[Invite:Recents] Excluding ${userId} from recents because, the user is not a space member`,
);
continue;
}
// Verji End

const room = rooms[userId];
const roomMember = room.getMember(userId);
if (!roomMember) {
Expand Down Expand Up @@ -603,6 +624,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
return Object.values(memberScores)
.map(({ member }) => member)
.filter((member) => !excludedTargetIds.has(member.userId))
.filter((member) => this.spaceMemberIds.includes(member.userId)) // Verji - add another layer of filtering, to only include members which are a member of space
.sort(memberComparator)
.map((member) => ({ userId: member.userId, user: toMember(member) }));
}
Expand Down

0 comments on commit 105311a

Please sign in to comment.