Merge pull request #109 from kawamataryo/filter-impersonation-user

fix: skip searching users with the "impersonation" label.
This commit is contained in:
ryo 2024-11-18 11:26:19 +09:00 committed by GitHub
commit 659fb86ef4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 4 deletions

View File

@ -100,4 +100,9 @@ export const DOCUMENT_LINK = {
"https://www.sky-follower-bridge.dev/troubleshooting.html#page-errors", "https://www.sky-follower-bridge.dev/troubleshooting.html#page-errors",
} as const; } 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",
} as const;

View File

@ -29,7 +29,9 @@ export const getAccountNameAndDisplayName = (userCell: Element) => {
const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-"); const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-");
const twDisplayName = displayNameEl?.textContent; const twDisplayName = displayNameEl?.textContent;
const bskyHandle = const bskyHandle =
userCell.textContent?.match(new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`))?.[1] ?? userCell.textContent?.match(
new RegExp(`([^/\\s]+\\.${BSKY_DOMAIN})`),
)?.[1] ??
userCell.textContent userCell.textContent
?.match(/bsky\.app\/profile\/([^/\s]+)…?/)?.[1] ?.match(/bsky\.app\/profile\/([^/\s]+)…?/)?.[1]
?.replace("…", "") ?? ?.replace("…", "") ??

View File

@ -1,7 +1,15 @@
import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs";
import { isSimilarUser } from "~lib/bskyHelpers"; import { isSimilarUser } from "~lib/bskyHelpers";
import type { getAccountNameAndDisplayName } from "~lib/domHelpers"; import type { getAccountNameAndDisplayName } from "~lib/domHelpers";
import { isOneSymbol } from "~lib/utils"; import { isOneSymbol } from "~lib/utils";
import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient";
import { BSKY_PROFILE_LABEL } from "./constants";
const isImpersonationUser = (user: ProfileView) => {
return user.labels.some(
(label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION,
);
};
export const searchBskyUser = async ({ export const searchBskyUser = async ({
client, client,
@ -25,11 +33,16 @@ export const searchBskyUser = async ({
} }
try { try {
const searchResults = await client.searchUser({ const searchResults = await client.searchUser({
term: term, term,
limit: 3, limit: 3,
}); });
for (const searchResult of searchResults) { for (const searchResult of searchResults) {
// skip impersonation users
if (isImpersonationUser(searchResult)) {
continue;
}
const { isSimilar: isUserFound, type } = isSimilarUser( const { isSimilar: isUserFound, type } = isSimilarUser(
// TODO: simplify // TODO: simplify
{ {

View File

@ -7,6 +7,7 @@ import { sendToBackground, sendToContentScript } from "@plasmohq/messaging";
import { import {
AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE, AUTH_FACTOR_TOKEN_REQUIRED_ERROR_MESSAGE,
BSKY_DOMAIN,
DOCUMENT_LINK, DOCUMENT_LINK,
MAX_RELOAD_COUNT, MAX_RELOAD_COUNT,
MESSAGE_NAMES, MESSAGE_NAMES,
@ -14,7 +15,6 @@ import {
RATE_LIMIT_ERROR_MESSAGE, RATE_LIMIT_ERROR_MESSAGE,
STORAGE_KEYS, STORAGE_KEYS,
TARGET_URLS_REGEX, TARGET_URLS_REGEX,
BSKY_DOMAIN,
} from "~lib/constants"; } from "~lib/constants";
function IndexPopup() { function IndexPopup() {