mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-04-23 20:12: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 type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs";
|
||||||
import { BSKY_USER_MATCH_TYPE } from "./constants";
|
import { BSKY_USER_MATCH_TYPE } from "./constants";
|
||||||
|
|
||||||
type Names = {
|
type xUserInfo = {
|
||||||
|
bskyHandleInDescription: string;
|
||||||
accountName: string;
|
accountName: string;
|
||||||
accountNameRemoveUnderscore: string;
|
accountNameRemoveUnderscore: string;
|
||||||
accountNameReplaceUnderscore: string;
|
accountNameReplaceUnderscore: string;
|
||||||
@ -9,7 +10,7 @@ type Names = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const isSimilarUser = (
|
export const isSimilarUser = (
|
||||||
names: Names,
|
xUserInfo: xUserInfo,
|
||||||
bskyProfile: ProfileView | undefined,
|
bskyProfile: ProfileView | undefined,
|
||||||
): {
|
): {
|
||||||
isSimilar: boolean;
|
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]) => {
|
(acc, [key, value]) => {
|
||||||
|
if (!value) {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
acc[key] = value.toLowerCase();
|
acc[key] = value.toLowerCase();
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
{} as Names,
|
{} as xUserInfo,
|
||||||
);
|
);
|
||||||
|
|
||||||
const bskyHandle = bskyProfile.handle
|
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 twAccountNameRemoveUnderscore = twAccountName.replaceAll("_", ""); // bsky does not allow underscores in handle, so remove them.
|
||||||
const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-");
|
const twAccountNameReplaceUnderscore = twAccountName.replaceAll("_", "-");
|
||||||
const twDisplayName = displayNameEl?.textContent;
|
const twDisplayName = displayNameEl?.textContent;
|
||||||
|
const bskyHandle =
|
||||||
|
userCell.textContent?.match(/([^/\s]+\.bsky\.social)/)?.[1] ??
|
||||||
|
userCell.textContent?.match(/bsky\.app\/profile\/([^/\s]+)…/)?.[1] ??
|
||||||
|
null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
twAccountName,
|
twAccountName,
|
||||||
twDisplayName,
|
twDisplayName,
|
||||||
twAccountNameRemoveUnderscore,
|
twAccountNameRemoveUnderscore,
|
||||||
twAccountNameReplaceUnderscore,
|
twAccountNameReplaceUnderscore,
|
||||||
|
bskyHandle,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,7 @@ export const searchBskyUser = async ({
|
|||||||
userData: ReturnType<typeof getAccountNameAndDisplayName>;
|
userData: ReturnType<typeof getAccountNameAndDisplayName>;
|
||||||
}) => {
|
}) => {
|
||||||
const searchTerms = [
|
const searchTerms = [
|
||||||
|
...(userData.bskyHandle ? [userData.bskyHandle] : []),
|
||||||
userData.twAccountNameRemoveUnderscore,
|
userData.twAccountNameRemoveUnderscore,
|
||||||
userData.twAccountNameReplaceUnderscore,
|
userData.twAccountNameReplaceUnderscore,
|
||||||
userData.twDisplayName,
|
userData.twDisplayName,
|
||||||
@ -31,6 +32,7 @@ export const searchBskyUser = async ({
|
|||||||
const { isSimilar: isUserFound, type } = isSimilarUser(
|
const { isSimilar: isUserFound, type } = isSimilarUser(
|
||||||
// TODO: simplify
|
// TODO: simplify
|
||||||
{
|
{
|
||||||
|
bskyHandleInDescription: userData.bskyHandle,
|
||||||
accountName: userData.twAccountName,
|
accountName: userData.twAccountName,
|
||||||
accountNameRemoveUnderscore: userData.twAccountNameRemoveUnderscore,
|
accountNameRemoveUnderscore: userData.twAccountNameRemoveUnderscore,
|
||||||
accountNameReplaceUnderscore:
|
accountNameReplaceUnderscore:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user