···2233import (
44 "context"
55- "encoding/json"
65 "fmt"
76 "time"
8798 "stream.place/streamplace/pkg/model"
99+ "stream.place/streamplace/pkg/streamplace"
1010)
11111212// Permission scope constants
···8181 }
82828383 // Check all delegation records and merge their permissions
8484- for _, delegation := range delegations {
8585- // Skip expired delegations
8686- if delegation.ExpirationTime != nil && time.Now().After(*delegation.ExpirationTime) {
8787- continue
8484+ for _, delegationView := range delegations {
8585+ // Extract the actual permission record from the view
8686+ permRecord, ok := delegationView.Record.Val.(*streamplace.ModerationPermission)
8787+ if !ok {
8888+ return false, fmt.Errorf("failed to cast record to ModerationPermission")
8889 }
89909090- // Parse permissions JSON array
9191- var permissions []string
9292- if err := json.Unmarshal(delegation.Permissions, &permissions); err != nil {
9393- return false, fmt.Errorf("failed to unmarshal permissions: %w", err)
9191+ // Skip expired delegations
9292+ if permRecord.ExpirationTime != nil {
9393+ expirationTime, err := time.Parse(time.RFC3339, *permRecord.ExpirationTime)
9494+ if err != nil {
9595+ return false, fmt.Errorf("failed to parse expiration time: %w", err)
9696+ }
9797+ if time.Now().After(expirationTime) {
9898+ continue
9999+ }
94100 }
9510196102 // Check if this delegation has the required permission
9797- for _, p := range permissions {
103103+ for _, p := range permRecord.Permissions {
98104 if p == permission {
99105 return true, nil
100106 }
+22
pkg/streamplace/moderationdefs.go
···11+// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.
22+33+// Lexicon schema: place.stream.moderation.defs
44+55+package streamplace
66+77+import (
88+ appbsky "github.com/bluesky-social/indigo/api/bsky"
99+ lexutil "github.com/bluesky-social/indigo/lex/util"
1010+)
1111+1212+// ModerationDefs_PermissionView is a "permissionView" in the place.stream.moderation.defs schema.
1313+type ModerationDefs_PermissionView struct {
1414+ // author: The streamer who granted these permissions
1515+ Author *appbsky.ActorDefs_ProfileViewBasic `json:"author" cborgen:"author"`
1616+ // cid: Content identifier of the permission record
1717+ Cid string `json:"cid" cborgen:"cid"`
1818+ // record: The permission record itself
1919+ Record *lexutil.LexiconTypeDecoder `json:"record" cborgen:"record"`
2020+ // uri: AT-URI of the permission record
2121+ Uri string `json:"uri" cborgen:"uri"`
2222+}