clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

feat/standalone-relay
tinyrelay / internal / daemon / join_requests.go
join_requests.go 2.0K
1package daemon23import (4 "context"5 "strings"67 "github.com/FelineStateMachine/tinyrelay/internal/community"8 "github.com/FelineStateMachine/tinyrelay/internal/event"9)1011// An access request is a NIP-43 join without a claim. The community service12// holds it for review; this file wakes the reviewers once per new request.1314// joinRequestNotices names the owner and moderators as the people asked,15// with the asker's short key and reason in the approvals category.16func (t *Tenant) joinRequestNotices(ctx context.Context, e event.Event) []pushNotice {17 reason := excerpt(community.JoinReason(e.Content))18 if reason == "" {19 reason = "no reason given"20 }21 body := shortKey(e.PubKey) + " asks to join: " + reason22 url := strings.TrimRight(t.publicURL, "/") + "/manage/people"23 recipients := []string{t.Policy().Owner}24 if moderators, err := t.community.Moderators(ctx); err == nil {25 recipients = append(recipients, moderators...)26 }27 notices := make([]pushNotice, 0, len(recipients))28 for _, recipient := range recipients {29 if recipient == e.PubKey {30 continue31 }32 notices = append(notices, pushNotice{recipient: recipient, category: pushApprovals, body: body, url: url})33 }34 return notices35}3637// notifyJoinRequest wakes the reviewers' devices for a new pending request.38// A refreshed request never reaches here, so each request wakes them once.39// The log carries counts only.40func (t *Tenant) notifyJoinRequest(ctx context.Context, e event.Event) {41 notices := t.joinRequestNotices(ctx, e)42 t.app.telemetry.Logger().Info("access request", "tenant", t.meta.Name, "reviewers", len(notices))43 if !t.pushDevicesExist(ctx) {44 return45 }46 queued := 047 for _, notice := range notices {48 if !t.pushCoalesced(notice.recipient, notice.category) {49 continue50 }51 if err := t.enqueuePushNotice(ctx, notice); err != nil {52 t.app.telemetry.Logger().Debug("access request notification not queued", "error", err)53 continue54 }55 queued++56 }57 t.app.telemetry.Logger().Debug("access request notifications queued", "count", queued)58}