From f2d4160db8005381f3cd053746d8aba4f7a262b5 Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Mon, 18 Nov 2024 11:22:30 +0900 Subject: [PATCH 1/2] fix: skip searching users with the "impersonation" label. --- src/lib/constants.ts | 6 +++++- src/lib/searchBskyUsers.ts | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 542e2e6..d29e467 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -100,4 +100,8 @@ export const DOCUMENT_LINK = { "https://www.sky-follower-bridge.dev/troubleshooting.html#page-errors", } as const; -export const BSKY_DOMAIN = process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social"; \ No newline at end of file +export const BSKY_DOMAIN = process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social"; + +export const BSKY_PROFILE_LABEL = { + IMPERSONATION: "impersonation", +} as const; diff --git a/src/lib/searchBskyUsers.ts b/src/lib/searchBskyUsers.ts index 15b27e4..a49d7d0 100644 --- a/src/lib/searchBskyUsers.ts +++ b/src/lib/searchBskyUsers.ts @@ -2,6 +2,12 @@ import { isSimilarUser } from "~lib/bskyHelpers"; import type { getAccountNameAndDisplayName } from "~lib/domHelpers"; import { isOneSymbol } from "~lib/utils"; import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; +import { BSKY_PROFILE_LABEL } from "./constants"; +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; + +const isImpersonationUser = (user: ProfileView) => { + return user.labels.some((label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION); +} export const searchBskyUser = async ({ client, @@ -25,11 +31,17 @@ export const searchBskyUser = async ({ } try { const searchResults = await client.searchUser({ - term: term, + term, limit: 3, }); for (const searchResult of searchResults) { + + // skip impersonation users + if (isImpersonationUser(searchResult)) { + continue; + } + const { isSimilar: isUserFound, type } = isSimilarUser( // TODO: simplify { From d2709d3397a859135dc2e974f0bf5cf84fe1b5bf Mon Sep 17 00:00:00 2001 From: kawamataryo Date: Mon, 18 Nov 2024 11:25:19 +0900 Subject: [PATCH 2/2] fix: format --- src/lib/constants.ts | 3 ++- src/lib/domHelpers.ts | 4 +++- src/lib/searchBskyUsers.ts | 9 +++++---- src/popup.tsx | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d29e467..ef3b219 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -100,7 +100,8 @@ export const DOCUMENT_LINK = { "https://www.sky-follower-bridge.dev/troubleshooting.html#page-errors", } as const; -export const BSKY_DOMAIN = process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social"; +export const BSKY_DOMAIN = + process.env.PLASMO_PUBLIC_BSKY_DOMAIN || "bsky.social"; export const BSKY_PROFILE_LABEL = { IMPERSONATION: "impersonation", diff --git a/src/lib/domHelpers.ts b/src/lib/domHelpers.ts index 929ff72..f1fd28f 100644 --- a/src/lib/domHelpers.ts +++ b/src/lib/domHelpers.ts @@ -29,7 +29,9 @@ export const getAccountNameAndDisplayName = (userCell: Element) => { const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-"); const twDisplayName = displayNameEl?.textContent; const bskyHandle = - userCell.textContent?.match(new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`))?.[1] ?? + userCell.textContent?.match( + new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`), + )?.[1] ?? userCell.textContent ?.match(/bsky\.app\/profile\/([^/\s]+)…?/)?.[1] ?.replace("…", "") ?? diff --git a/src/lib/searchBskyUsers.ts b/src/lib/searchBskyUsers.ts index a49d7d0..7b91cce 100644 --- a/src/lib/searchBskyUsers.ts +++ b/src/lib/searchBskyUsers.ts @@ -1,13 +1,15 @@ +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import { isSimilarUser } from "~lib/bskyHelpers"; import type { getAccountNameAndDisplayName } from "~lib/domHelpers"; import { isOneSymbol } from "~lib/utils"; import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; import { BSKY_PROFILE_LABEL } from "./constants"; -import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; const isImpersonationUser = (user: ProfileView) => { - return user.labels.some((label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION); -} + return user.labels.some( + (label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION, + ); +}; export const searchBskyUser = async ({ client, @@ -36,7 +38,6 @@ export const searchBskyUser = async ({ }); for (const searchResult of searchResults) { - // skip impersonation users if (isImpersonationUser(searchResult)) { continue; diff --git a/src/popup.tsx b/src/popup.tsx index d2f972b..26e588e 100644 --- a/src/popup.tsx +++ b/src/popup.tsx @@ -7,6 +7,7 @@ import { sendToBackground, sendToContentScript } from "@plasmohq/messaging"; import { AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE, + BSKY_DOMAIN, DOCUMENT_LINK, MAX_RELOAD_COUNT, MESSAGE_NAMES, @@ -14,7 +15,6 @@ import { RATE_LIMIT_ERROR_MESSAGE, STORAGE_KEYS, TARGET_URLS_REGEX, - BSKY_DOMAIN, } from "~lib/constants"; function IndexPopup() {