tinyrelayfile
tinyrelay/internal/daemon/join_requests.go/

internal/daemon/join_requests.go raw
1package daemon
2
3import (
4 "context"
5 "strings"
6
7 "github.com/FelineStateMachine/tinyrelay/internal/community"
8 "github.com/FelineStateMachine/tinyrelay/internal/event"
9)
10
11// An access request is a NIP-43 join without a claim. The community service
12// holds it for review; this file wakes the reviewers once per new request.
13
14// 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: " + reason
22 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 continue
31 }
32 notices = append(notices, pushNotice{recipient: recipient, category: pushApprovals, body: body, url: url})
33 }
34 return notices
35}
36
37// 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 return
45 }
46 queued := 0
47 for _, notice := range notices {
48 if !t.pushCoalesced(notice.recipient, notice.category) {
49 continue
50 }
51 if err := t.enqueuePushNotice(ctx, notice); err != nil {
52 t.app.telemetry.Logger().Debug("access request notification not queued", "error", err)
53 continue
54 }
55 queued++
56 }
57 t.app.telemetry.Logger().Debug("access request notifications queued", "count", queued)
58}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs