Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
diff --git a/src/lib/components/DetectedUserListItem.tsx b/src/lib/components/DetectedUserListItem.tsx index 7466377..355dd7c 100644 --- a/src/lib/components/DetectedUserListItem.tsx +++ b/src/lib/components/DetectedUserListItem.tsx @@ -1,10 +1,10 @@ +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import React from "react"; import { match } from "ts-pattern"; import type { BskyUser } from "~types"; import { ACTION_MODE } from "../constants"; import DetectedUserSource from "./DetectedUserSource"; import UserCard from "./UserCard"; -import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; export type Props = { user: BskyUser; actionMode: (typeof ACTION_MODE)[keyof typeof ACTION_MODE]; diff --git a/src/lib/components/DetectedUserSource.tsx b/src/lib/components/DetectedUserSource.tsx index f23a3cb..ae27c49 100644 --- a/src/lib/components/DetectedUserSource.tsx +++ b/src/lib/components/DetectedUserSource.tsx @@ -1,8 +1,8 @@ +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import React from "react"; import type { BskyUser } from "~types"; import { MATCH_TYPE_LABEL_AND_COLOR } from "../constants"; import { UserInfo, UserProfile } from "./UserCard"; -import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; type DetectedUserSourceProps = { user: BskyUser; diff --git a/src/lib/reSearchBskyUsers.ts b/src/lib/reSearchBskyUsers.ts new file mode 100644 index 0000000..138fca7 --- /dev/null +++ b/src/lib/reSearchBskyUsers.ts @@ -0,0 +1,55 @@ +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; +import { isOneSymbol } from "~lib/utils"; +import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; +import { isImpersonationUser } from "./bskyHelpers"; + +export const reSearchBskyUser = async ({ + client, + userData, +}: { + client: BskyServiceWorkerClient; + userData: { + accountName: string; + displayName: string; + }; +}): Promise<ProfileView[]> => { + const searchTerms = [ + userData.accountName, + userData.displayName, + userData.accountName.replaceAll("_", ""), + userData.displayName.replaceAll("_", ""), + ]; + const uniqueSearchTerms = new Set(searchTerms); + + const searchResultDidSet = new Set<string>(); + const searchResults: ProfileView[] = []; + + for (const term of uniqueSearchTerms) { + // one symbol is not a valid search term for bsky + if (!term || isOneSymbol(term)) { + continue; + } + try { + const results = await client.searchUser({ + term, + limit: 3, + }); + + for (const result of results) { + // skip impersonation users + if (isImpersonationUser(result)) { + continue; + } + if (searchResultDidSet.has(result.did)) { + continue; + } + searchResultDidSet.add(result.did); + searchResults.push(result); + } + } catch (e) { + console.error(e); + } + } + + return searchResults; +}; diff --git a/src/lib/searchBskyUsers.ts b/src/lib/searchBskyUsers.ts index 34c2f13..45b0f40 100644 --- a/src/lib/searchBskyUsers.ts +++ b/src/lib/searchBskyUsers.ts @@ -1,8 +1,8 @@ import { isSimilarUser } from "~lib/bskyHelpers"; import { isOneSymbol } from "~lib/utils"; import type { CrawledUserInfo } from "~types"; -import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; import { isImpersonationUser } from "./bskyHelpers"; +import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; export const searchBskyUser = async ({ client, diff --git a/src/options.tsx b/src/options.tsx index 662171b..87fba17 100644 --- a/src/options.tsx +++ b/src/options.tsx @@ -4,9 +4,9 @@ import { ToastContainer, toast } from "react-toastify"; import useConfirm from "~lib/components/ConfirmDialog"; import Sidebar from "~lib/components/Sidebar"; import "react-toastify/dist/ReactToastify.css"; +import React from "react"; import DetectedUserListItem from "~lib/components/DetectedUserListItem"; import Modal from "~lib/components/Modal"; -import React from "react"; import UserCard from "~lib/components/UserCard"; const Option = () => {
- Loading branch information