Add support for blocked relays

This commit is contained in:
Jon Staab
2026-01-16 13:10:48 -08:00
parent 3f914d02cc
commit 87bb62b359
6 changed files with 88 additions and 68 deletions
-40
View File
@@ -52,10 +52,8 @@ import {
removeFromListByPredicate,
getTag,
getListTags,
getRelayTags,
getRelayTagValues,
toNostrURI,
getRelaysFromList,
RelayMode,
getAddress,
getTagValue,
@@ -80,8 +78,6 @@ import {
publishThunk,
tagEvent,
tagEventForReaction,
userRelayList,
userMessagingRelayList,
nip44EncryptToSelf,
dropSession,
tagEventForComment,
@@ -208,42 +204,6 @@ export const removeRoomMembership = async (url: string, h: string) => {
return publishThunk({event, relays})
}
export const setRelayPolicy = (url: string, read: boolean, write: boolean) => {
const list = get(userRelayList) || makeList({kind: RELAYS})
const tags = getRelayTags(getListTags(list)).filter(t => normalizeRelayUrl(t[1]) !== url)
if (read && write) {
tags.push(["r", url])
} else if (read) {
tags.push(["r", url, "read"])
} else if (write) {
tags.push(["r", url, "write"])
}
return publishThunk({
event: makeEvent(list.kind, {tags}),
relays: [url, ...INDEXER_RELAYS, ...Router.get().FromUser().getUrls(), ...get(userSpaceUrls)],
})
}
export const setMessagingRelayPolicy = (url: string, enabled: boolean) => {
const list = get(userMessagingRelayList) || makeList({kind: MESSAGING_RELAYS})
// Only update messaging policies if they already exist or we're adding them
if (enabled || getRelaysFromList(list).includes(url)) {
const tags = getRelayTags(getListTags(list)).filter(t => normalizeRelayUrl(t[1]) !== url)
if (enabled) {
tags.push(["relay", url])
}
return publishThunk({
event: makeEvent(list.kind, {tags}),
relays: [...INDEXER_RELAYS, ...Router.get().FromUser().getUrls(), ...get(userSpaceUrls)],
})
}
}
// Relay access
export const canEnforceNip70 = async (url: string) => {
+9 -7
View File
@@ -41,6 +41,7 @@ import {
loadRelayList,
loadMessagingRelayList,
loadBlossomServerList,
loadBlockedRelayList,
loadFollowList,
loadMuteList,
loadProfile,
@@ -215,6 +216,7 @@ const syncUserData = () => {
loadAlerts($userRelayList.event.pubkey)
loadAlertStatuses($userRelayList.event.pubkey)
loadBlossomServerList($userRelayList.event.pubkey)
loadBlockedRelayList($userRelayList.event.pubkey)
loadFollowList($userRelayList.event.pubkey)
loadGroupList($userRelayList.event.pubkey)
loadMuteList($userRelayList.event.pubkey)
@@ -229,13 +231,13 @@ const syncUserData = () => {
await sleep(1000)
await Promise.all(
pubkeys.map(async pk => {
await loadRelayList(pk)
await loadGroupList(pk)
await loadProfile(pk)
await loadFollowList(pk)
await loadMuteList(pk)
}),
pubkeys.flatMap(pk => [
loadRelayList(pk),
loadGroupList(pk),
loadProfile(pk),
loadFollowList(pk),
loadMuteList(pk),
]),
)
}
})