mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-04-10 14:11:22 -06:00
fix: change search logic
This commit is contained in:
parent
ed98361201
commit
9141ef69d8
@ -1,7 +1,8 @@
|
||||
import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs";
|
||||
import { BSKY_USER_MATCH_TYPE } from "./constants";
|
||||
|
||||
type Names = {
|
||||
type xUserInfo = {
|
||||
bskyHandleInDescription: string;
|
||||
accountName: string;
|
||||
accountNameRemoveUnderscore: string;
|
||||
accountNameReplaceUnderscore: string;
|
||||
@ -9,7 +10,7 @@ type Names = {
|
||||
};
|
||||
|
||||
export const isSimilarUser = (
|
||||
names: Names,
|
||||
xUserInfo: xUserInfo,
|
||||
bskyProfile: ProfileView | undefined,
|
||||
): {
|
||||
isSimilar: boolean;
|
||||
@ -22,12 +23,31 @@ export const isSimilarUser = (
|
||||
};
|
||||
}
|
||||
|
||||
const lowerCaseNames = Object.entries(names).reduce<Names>(
|
||||
// this is to handle the case where the user has a bsky handle in their description
|
||||
if (xUserInfo.bskyHandleInDescription) {
|
||||
const formattedBskyHandle = bskyProfile.handle.replace("@", "");
|
||||
const formattedBskyHandleInDescription =
|
||||
xUserInfo.bskyHandleInDescription.replace("@", "");
|
||||
if (
|
||||
formattedBskyHandle === formattedBskyHandleInDescription ||
|
||||
formattedBskyHandle.includes(formattedBskyHandleInDescription)
|
||||
) {
|
||||
return {
|
||||
isSimilar: true,
|
||||
type: BSKY_USER_MATCH_TYPE.HANDLE,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const lowerCaseNames = Object.entries(xUserInfo).reduce<xUserInfo>(
|
||||
(acc, [key, value]) => {
|
||||
if (!value) {
|
||||
return acc;
|
||||
}
|
||||
acc[key] = value.toLowerCase();
|
||||
return acc;
|
||||
},
|
||||
{} as Names,
|
||||
{} as xUserInfo,
|
||||
);
|
||||
|
||||
const bskyHandle = bskyProfile.handle
|
||||
|
@ -25,10 +25,16 @@ export const getAccountNameAndDisplayName = (userCell: Element) => {
|
||||
const twAccountNameRemoveUnderscore = twAccountName.replaceAll("_", ""); // bsky does not allow underscores in handle, so remove them.
|
||||
const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-");
|
||||
const twDisplayName = displayNameEl?.textContent;
|
||||
const bskyHandle =
|
||||
userCell.textContent?.match(/([^/\s]+\.bsky\.social)/)?.[1] ??
|
||||
userCell.textContent?.match(/bsky\.app\/profile\/([^/\s]+)…/)?.[1] ??
|
||||
null;
|
||||
|
||||
return {
|
||||
twAccountName,
|
||||
twDisplayName,
|
||||
twAccountNameRemoveUnderscore,
|
||||
twAccountNameReplaceUnderscore,
|
||||
bskyHandle,
|
||||
};
|
||||
};
|
||||
|
@ -11,6 +11,7 @@ export const searchBskyUser = async ({
|
||||
userData: ReturnType<typeof getAccountNameAndDisplayName>;
|
||||
}) => {
|
||||
const searchTerms = [
|
||||
...(userData.bskyHandle ? [userData.bskyHandle] : []),
|
||||
userData.twAccountNameRemoveUnderscore,
|
||||
userData.twAccountNameReplaceUnderscore,
|
||||
userData.twDisplayName,
|
||||
@ -31,6 +32,7 @@ export const searchBskyUser = async ({
|
||||
const { isSimilar: isUserFound, type } = isSimilarUser(
|
||||
// TODO: simplify
|
||||
{
|
||||
bskyHandleInDescription: userData.bskyHandle,
|
||||
accountName: userData.twAccountName,
|
||||
accountNameRemoveUnderscore: userData.twAccountNameRemoveUnderscore,
|
||||
accountNameReplaceUnderscore:
|
||||
|
Loading…
x
Reference in New Issue
Block a user