(
args: {
query: string;
limit?: number;
cursor?: string | null;
},
config: E2eConfig | undefined,
)
| 4788 | } |
| 4789 | |
| 4790 | async function handleSearchUsers( |
| 4791 | args: { |
| 4792 | query: string; |
| 4793 | limit?: number; |
| 4794 | cursor?: string | null; |
| 4795 | }, |
| 4796 | config: E2eConfig | undefined, |
| 4797 | ) { |
| 4798 | const userSearchDelayMs = config?.mock?.userSearchDelayMs ?? 0; |
| 4799 | if (userSearchDelayMs > 0) { |
| 4800 | await new Promise<void>((resolve) => { |
| 4801 | window.setTimeout(resolve, userSearchDelayMs); |
| 4802 | }); |
| 4803 | } |
| 4804 | |
| 4805 | const identity = getIdentity(config); |
| 4806 | if (!identity) { |
| 4807 | const normalizedQuery = args.query.trim().toLowerCase(); |
| 4808 | |
| 4809 | const limit = args.limit ?? 8; |
| 4810 | const page = Math.max(Number(args.cursor ?? 1) || 1, 1); |
| 4811 | const allResults = listMockProfiles() |
| 4812 | .filter((profile) => { |
| 4813 | if (normalizedQuery.length === 0) { |
| 4814 | return true; |
| 4815 | } |
| 4816 | |
| 4817 | const displayName = profile.display_name?.toLowerCase() ?? ""; |
| 4818 | const nip05Handle = profile.nip05_handle?.toLowerCase() ?? ""; |
| 4819 | const pubkey = profile.pubkey.toLowerCase(); |
| 4820 | return ( |
| 4821 | displayName.includes(normalizedQuery) || |
| 4822 | nip05Handle.includes(normalizedQuery) || |
| 4823 | pubkey.includes(normalizedQuery) |
| 4824 | ); |
| 4825 | }) |
| 4826 | .sort((left, right) => { |
| 4827 | const leftName = left.display_name ?? left.nip05_handle ?? left.pubkey; |
| 4828 | const rightName = |
| 4829 | right.display_name ?? right.nip05_handle ?? right.pubkey; |
| 4830 | return leftName.localeCompare(rightName); |
| 4831 | }); |
| 4832 | const results = allResults |
| 4833 | .slice((page - 1) * limit, page * limit) |
| 4834 | .map((profile) => ({ |
| 4835 | pubkey: profile.pubkey, |
| 4836 | display_name: profile.display_name, |
| 4837 | avatar_url: profile.avatar_url, |
| 4838 | nip05_handle: profile.nip05_handle, |
| 4839 | owner_pubkey: profile.owner_pubkey, |
| 4840 | is_agent: profile.is_agent ?? false, |
| 4841 | })); |
| 4842 | |
| 4843 | return { |
| 4844 | users: results, |
| 4845 | next_cursor: page * limit < allResults.length ? String(page + 1) : null, |
| 4846 | } satisfies RawSearchUsersResponse; |
| 4847 | } |
no test coverage detected