Skip to content

Commit

Permalink
fix left/banned member showing in autocomplete (#2194)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbura authored Feb 10, 2025
1 parent 56b7541 commit 7b4f684
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getMxIdLocalPart, getMxIdServer, validMxId } from '../../../utils/matri
import { getMemberDisplayName, getMemberSearchStr } from '../../../utils/room';
import { UserAvatar } from '../../user-avatar';
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
import { Membership } from '../../../../types/matrix/room';

type MentionAutoCompleteHandler = (userId: string, name: string) => void;

Expand Down Expand Up @@ -67,6 +68,11 @@ type UserMentionAutocompleteProps = {
requestClose: () => void;
};

const withAllowedMembership = (member: RoomMember): boolean =>
member.membership === Membership.Join ||
member.membership === Membership.Invite ||
member.membership === Membership.Knock;

const SEARCH_OPTIONS: UseAsyncSearchOptions = {
limit: 20,
matchOptions: {
Expand All @@ -91,7 +97,9 @@ export function UserMentionAutocomplete({
const members = useRoomMembers(mx, roomId);

const [result, search, resetSearch] = useAsyncSearch(members, getRoomMemberStr, SEARCH_OPTIONS);
const autoCompleteMembers = result ? result.items : members.slice(0, 20);
const autoCompleteMembers = (result ? result.items : members.slice(0, 20)).filter(
withAllowedMembership
);

useEffect(() => {
if (query.text) search(query.text);
Expand Down

0 comments on commit 7b4f684

Please sign in to comment.