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:
parent
7be7b30d52
commit
aae8fc2f17
27 changed files with 202 additions and 50 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { ExtendedKind, SEARCHABLE_RELAY_URLS } from '@/constants'
|
||||
import { ExtendedKind } from '@/constants'
|
||||
import {
|
||||
compareEvents,
|
||||
getReplaceableCoordinate,
|
||||
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from '@/lib/event'
|
||||
import { getProfileFromEvent, getRelayListFromEvent } from '@/lib/event-metadata'
|
||||
import { formatPubkey, isValidPubkey, pubkeyToNpub, userIdToPubkey } from '@/lib/pubkey'
|
||||
import { filterOutBigRelays, getDefaultRelayUrls } from '@/lib/relay'
|
||||
import { filterOutBigRelays, getDefaultRelayUrls, getSearchRelayUrls } from '@/lib/relay'
|
||||
import { SmartPool } from '@/lib/smart-pool'
|
||||
import { getPubkeysFromPTags, getServersFromServerTags, tagNameEquals } from '@/lib/tag'
|
||||
import { mergeTimelines } from '@/lib/timeline'
|
||||
|
|
@ -159,7 +159,7 @@ class ClientService extends EventTarget {
|
|||
|
||||
async determineRelaysByFilter(filter: Filter) {
|
||||
if (filter.search) {
|
||||
return SEARCHABLE_RELAY_URLS
|
||||
return getSearchRelayUrls()
|
||||
} else if (filter.authors?.length) {
|
||||
const relayLists = await this.fetchRelayLists(filter.authors)
|
||||
return Array.from(new Set(relayLists.flatMap((list) => list.write.slice(0, 5))))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue