- commit
- 453e022c841649228706b37f68322aa3c639b667
- parent
- b86c9274ad9dd5fc2320c7aa923dc4ca30eba6df
- author
- Dami <dami.etoile@gmail.com>
| M | src/ | 27 | +++++++++++++++++++++++++++ |
@@ -447,6 +447,33 @@ export class Settings {
447447 isAllowed(pubkey: string) {448448 return this.memberSet.has(pubkey) || this.isOwner(pubkey);449449 }450+451+ // ---- the read rule ----452+453+ // mayRead applies the read rule to whoever is asking, given the pubkeys454+ // they have proved: "" admits, else the reason. This is the one gate every455+ // door that shows events, files, names or presence goes through, on the456+ // socket and over HTTP alike.457+ mayRead(pubkeys: string[]): string {458+ switch (this.policy.reads) {459+ case "open":460+ return "";461+ case "auth":462+ return pubkeys.length ? "" : "auth-required: this relay requires authentication";463+ case "members":464+ if (pubkeys.some((pk) => this.isAllowed(pk))) return "";465+ return pubkeys.length ? "restricted: this relay only serves its members" : "auth-required: this relay requires authentication";466+ }467+ }468+469+ // mayList says whether the member directory, names and counts, may be470+ // shown to this caller: to anyone when the directory is public, else only471+ // to members, whatever the read rule says.472+ mayList(pubkeys: string[]): string {473+ if (this.policy.directoryPublic) return "";474+ if (pubkeys.some((pk) => this.isAllowed(pk))) return "";475+ return pubkeys.length ? "restricted: the directory is for members" : "auth-required: the directory is for members; sign the request";476+ }450477 // roleOf is the pubkey's role, or null for a stranger.451478 roleOf(pubkey: string): Role | null {452479 if (this.isOwner(pubkey)) return "owner";