Skip to content

Commit

Permalink
[from now] 2024/11/30 20:44:28
Browse files Browse the repository at this point in the history
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
kawamataryo committed Nov 30, 2024
1 parent cfd3827 commit 632a6f1
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/components/DetectedUserListItem.tsx
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/DetectedUserSource.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
55 changes: 55 additions & 0 deletions src/lib/reSearchBskyUsers.ts
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion src/lib/searchBskyUsers.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 632a6f1

Please sign in to comment.