add support to bluesky client forks / bluesky clients that use the same structure as social-app #7

closed
opened by aylac.top targeting main from aylac.top/pdsls: main

it adds a file with a list of some (can easily be extended) bluesky clients. modifies the matching on search so that it treats those the same as bsky.app is treated.

might've gone a bit overboard on the reorganising of the if else chain in there to try to make it try to evaluate as few things as it can, i can tone that back if you want.

Changed files
+30 -13
src
components
utils
+16 -13
src/components/search.tsx
··· 2 2 import { A, useLocation, useNavigate } from "@solidjs/router"; 3 3 import { createResource, createSignal, For, onCleanup, onMount, Show } from "solid-js"; 4 4 import { isTouchDevice } from "../layout"; 5 + import { BskyClient, bskyClients } from "../utils/bsky-clients"; 5 6 import { createDebouncedValue } from "../utils/hooks/debounced"; 6 7 7 8 export const [showSearch, setShowSearch] = createSignal(false); ··· 68 69 setShowSearch(false); 69 70 if (input === "me" && localStorage.getItem("lastSignedIn") !== null) { 70 71 navigate(`/at://${localStorage.getItem("lastSignedIn")}`); 71 - } else if ( 72 - !input.startsWith("https://bsky.app/") && 73 - (input.startsWith("https://") || input.startsWith("http://")) 74 - ) { 75 - navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`); 76 72 } else if (search()?.length) { 77 73 navigate(`/at://${search()![0].did}`); 74 + } else if (input.startsWith("https://") || input.startsWith("http://")) { 75 + const host = input.slice(0, input.indexOf("/profile/", 8)) as BskyClient; 76 + if (!bskyClients.has(host)) { 77 + navigate(`/${input.replace("https://", "").replace("http://", "").replace("/", "")}`); 78 + } else { 79 + const uri = input 80 + .replace("at://", "") 81 + .replace(`${host}/profile/`, "") 82 + .replace("/post/", "/app.bsky.feed.post/"); 83 + const uriParts = uri.split("/"); 84 + navigate( 85 + `/at://${uriParts[0]}${uriParts.length > 1 ? `/${uriParts.slice(1).join("/")}` : ""}`, 86 + ); 87 + } 78 88 } else { 79 - const uri = input 80 - .replace("at://", "") 81 - .replace("https://bsky.app/profile/", "") 82 - .replace("/post/", "/app.bsky.feed.post/"); 83 - const uriParts = uri.split("/"); 84 - navigate( 85 - `/at://${uriParts[0]}${uriParts.length > 1 ? `/${uriParts.slice(1).join("/")}` : ""}`, 86 - ); 89 + navigate(`/${input}`); 87 90 } 88 91 setShowSearch(false); 89 92 };
+14
src/utils/bsky-clients.ts
··· 1 + export type BskyClient = `${"http" | "https"}://${string}`; 2 + type BskyClientSet = Set<BskyClient>; 3 + 4 + export const bskyClients: BskyClientSet = new Set<BskyClient>([ 5 + "http://localhost:19006", 6 + "https://blacksky.community", 7 + "https://bsky.app", 8 + "https://catsky.social", 9 + "https://deer.aylac.top", 10 + "https://deer-social-ayla.pages.dev", 11 + "https://deer.social", 12 + "https://main.bsky.dev", 13 + "https://social.daniela.lol", 14 + ]);