Read supportedmethods for the logged in pubkey rather than for the relay
This commit is contained in:
parent
f613e7cadd
commit
0420c59c5a
2 changed files with 18 additions and 7 deletions
|
|
@ -383,8 +383,8 @@ export class Access {
|
||||||
sleep(300),
|
sleep(300),
|
||||||
])
|
])
|
||||||
|
|
||||||
// The relay reports methods relay-wide rather than per-user, so a listed method can
|
// A relay that reports methods relay-wide rather than per-user can still come back
|
||||||
// still come back "blocked" for this particular user — treat that as having no claim.
|
// "blocked" for this particular user — treat that as having no claim.
|
||||||
if (methods?.includes("createclaim")) {
|
if (methods?.includes("createclaim")) {
|
||||||
const {result: claims} = await management.listClaims()
|
const {result: claims} = await management.listClaims()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import {derived, readable, writable} from "svelte/store"
|
import {derived, readable, writable} from "svelte/store"
|
||||||
import {ago, MINUTE, now, simpleCache} from "@welshman/lib"
|
import {ago, MINUTE, now, simpleCache} from "@welshman/lib"
|
||||||
import {ROOM_CREATE_PERMISSION, hexTags, tagValues} from "@welshman/util"
|
import {ROOM_CREATE_PERMISSION, hexTags, tagValues} from "@welshman/util"
|
||||||
import {relayManagement, user} from "@app/core"
|
import {fromApp, relayManagement, user} from "@app/core"
|
||||||
import {deriveEventsForUrl} from "@app/repository"
|
import {deriveEventsForUrl} from "@app/repository"
|
||||||
|
|
||||||
export type BannedPubkeyItem = {
|
export type BannedPubkeyItem = {
|
||||||
|
|
@ -21,11 +21,11 @@ export const deriveSpaceBannedPubkeyItems = (url: string) => {
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deriveSpaceSupportedMethods = simpleCache(([url]: [string | undefined]) => {
|
const deriveSupportedMethodsForPubkey = simpleCache(([, url]: [pubkey: string, url: string]) => {
|
||||||
let checkedAt = 0
|
let checkedAt = 0
|
||||||
|
|
||||||
return readable<string[]>([], set => {
|
return readable<string[]>([], set => {
|
||||||
if (url && checkedAt < ago(5, MINUTE)) {
|
if (checkedAt < ago(5, MINUTE)) {
|
||||||
checkedAt = now()
|
checkedAt = now()
|
||||||
|
|
||||||
relayManagement
|
relayManagement
|
||||||
|
|
@ -41,10 +41,21 @@ export const deriveSpaceSupportedMethods = simpleCache(([url]: [string | undefin
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// The request is signed as the logged in user and answered for that pubkey, so the methods
|
||||||
|
// belong to a user as much as to a url and logging in has to swap them out.
|
||||||
|
export const deriveSpaceSupportedMethods = (url?: string) =>
|
||||||
|
fromApp($app => {
|
||||||
|
if (url && $app.user) {
|
||||||
|
return deriveSupportedMethodsForPubkey($app.user.pubkey, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
return readable<string[]>([])
|
||||||
|
})
|
||||||
|
|
||||||
// User
|
// User
|
||||||
|
|
||||||
// A relay answers supportedmethods with everything it implements rather than with what the
|
// Holding any management method at all is what makes someone staff here. A relay that still
|
||||||
// caller may use, so all this can tell us is that the call wasn't refused outright.
|
// answers relay-wide tells us only that the call wasn't refused outright.
|
||||||
export const deriveUserIsSpaceAdmin = (url?: string) =>
|
export const deriveUserIsSpaceAdmin = (url?: string) =>
|
||||||
derived(deriveSpaceSupportedMethods(url), $methods => $methods.length > 0)
|
derived(deriveSpaceSupportedMethods(url), $methods => $methods.length > 0)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue