Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jts/1989 invite suggestions #72

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading