feat: add customizable search relays setting

Replace hardcoded SEARCHABLE_RELAY_URLS with user-configurable search
relays stored in localStorage. Add SearchRelaysSetting UI in System
settings page with add/remove/reset functionality.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
codytseng 2026-03-12 23:19:47 +08:00
parent 7be7b30d52
commit aae8fc2f17
27 changed files with 202 additions and 50 deletions

View file

@ -8,6 +8,7 @@ import {
NOTIFICATION_LIST_STYLE,
NSFW_DISPLAY_POLICY,
PROFILE_PICTURE_AUTO_LOAD_POLICY,
SEARCHABLE_RELAY_URLS,
StorageKey,
TPrimaryColor
} from '@/constants'
@ -66,6 +67,7 @@ class LocalStorageService {
private quickReactionEmoji: string | TEmoji = '+'
private nsfwDisplayPolicy: TNsfwDisplayPolicy = NSFW_DISPLAY_POLICY.HIDE_CONTENT
private defaultRelayUrls: string[] = BIG_RELAY_URLS
private searchRelayUrls: string[] = SEARCHABLE_RELAY_URLS
private mutedWords: string[] = []
private minTrustScore: number = 0
private minTrustScoreMap: Record<string, number> = {}
@ -310,6 +312,22 @@ class LocalStorageService {
}
}
const searchRelayUrlsStr = window.localStorage.getItem(StorageKey.SEARCH_RELAY_URLS)
if (searchRelayUrlsStr) {
try {
const urls = JSON.parse(searchRelayUrlsStr)
if (
Array.isArray(urls) &&
urls.length > 0 &&
urls.every((url) => typeof url === 'string')
) {
this.searchRelayUrls = urls
}
} catch {
// Invalid JSON, use default
}
}
const mutedWordsStr = window.localStorage.getItem(StorageKey.MUTED_WORDS)
if (mutedWordsStr) {
try {
@ -691,6 +709,15 @@ class LocalStorageService {
window.localStorage.setItem(StorageKey.DEFAULT_RELAY_URLS, JSON.stringify(urls))
}
getSearchRelayUrls() {
return this.searchRelayUrls
}
setSearchRelayUrls(urls: string[]) {
this.searchRelayUrls = urls
window.localStorage.setItem(StorageKey.SEARCH_RELAY_URLS, JSON.stringify(urls))
}
getMutedWords() {
return this.mutedWords
}