// Code generated by glex; DO NOT EDIT. // Lexicon schema: place.stream.chat.access package placestream import ( "encoding/json" "fmt" "io" glex "github.com/streamplace/glex/runtime" cbg "github.com/whyrusleeping/cbor-gen" ) func init() { glex.RegisterType("place.stream.chat.access", &ChatAccess{}) } // A rule about who may chat on this streamer's streams. Rules are evaluated per streamer: when any allow rule exists, only accounts matching an allow rule may chat; accounts matching a deny rule never may. A streamer with no rules has open chat. type ChatAccess struct { LexiconTypeID string `json:"$type,omitempty"` // action: Whether accounts matching the subject may chat (allow) or may not (deny). Deny wins over allow. Action string `json:"action"` // createdAt: Client-declared timestamp when this rule was created. CreatedAt string `json:"createdAt"` // subject: Who the rule matches. Open: a node ignores subject types it does not understand. Subject ChatAccess_Subject `json:"subject"` } // RecordTypeID implements glex.Record. func (t *ChatAccess) RecordTypeID() string { return "place.stream.chat.access" } // MarshalJSON stamps the $type field, like MarshalCBOR does. The value // receiver operates on a copy, so the record is never mutated and both // ChatAccess and *ChatAccess marshal with $type. func (t ChatAccess) MarshalJSON() ([]byte, error) { t.LexiconTypeID = "place.stream.chat.access" type alias ChatAccess return json.Marshal((alias)(t)) } func (t *ChatAccess) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "place.stream.chat.access" return glex.MarshalCBOR(w, &cp) } func (t *ChatAccess) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // Who the rule matches. Open: a node ignores subject types it does not understand. type ChatAccess_Subject struct { ChatAccess_Label *ChatAccess_Label ChatAccess_Verifier *ChatAccess_Verifier // Raw preserves a variant whose $type is not in this union's generated // set, so unrecognized variants still round-trip losslessly through // decode/re-encode. Nil when a known variant is set. Raw *glex.RawRecord } // MarshalJSON emits the set variant, stamped with its $type, per the atproto // union wire format. The value receiver stamps a copy, so the variant is // never mutated and both ChatAccess_Subject and *ChatAccess_Subject marshal correctly. func (t ChatAccess_Subject) MarshalJSON() ([]byte, error) { if t.ChatAccess_Label != nil { cp := *t.ChatAccess_Label cp.LexiconTypeID = "place.stream.chat.access#label" return json.Marshal(&cp) } if t.ChatAccess_Verifier != nil { cp := *t.ChatAccess_Verifier cp.LexiconTypeID = "place.stream.chat.access#verifier" return json.Marshal(&cp) } if t.Raw != nil { if t.Raw.Encoding != "json" { return nil, fmt.Errorf("cannot marshal raw %s record as JSON in union ChatAccess_Subject", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union ChatAccess_Subject as JSON") } func (t *ChatAccess_Subject) UnmarshalJSON(b []byte) error { typ, err := glex.TypeExtract(b) if err != nil { return err } switch typ { case "place.stream.chat.access#label": t.ChatAccess_Label = new(ChatAccess_Label) return json.Unmarshal(b, t.ChatAccess_Label) case "place.stream.chat.access#verifier": t.ChatAccess_Verifier = new(ChatAccess_Verifier) return json.Unmarshal(b, t.ChatAccess_Verifier) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "json", Bytes: append([]byte(nil), b...)} return nil } } // MarshalCBOR implements drisl.Marshaler, emitting the set variant (stamped // with its $type) per the atproto union wire format. go-dasl invokes this // when the union appears inside another record, so nested unions serialize // correctly. func (t ChatAccess_Subject) MarshalCBOR() ([]byte, error) { if t.ChatAccess_Label != nil { cp := *t.ChatAccess_Label cp.LexiconTypeID = "place.stream.chat.access#label" return glex.MarshalCBORBytes(&cp) } if t.ChatAccess_Verifier != nil { cp := *t.ChatAccess_Verifier cp.LexiconTypeID = "place.stream.chat.access#verifier" return glex.MarshalCBORBytes(&cp) } if t.Raw != nil { if t.Raw.Encoding != "cbor" { return nil, fmt.Errorf("cannot marshal raw %s record as CBOR in union ChatAccess_Subject", t.Raw.Encoding) } return t.Raw.Bytes, nil } return nil, fmt.Errorf("cannot marshal empty union ChatAccess_Subject as CBOR") } func (t *ChatAccess_Subject) UnmarshalCBOR(b []byte) error { typ, err := glex.CborTypeExtract(b) if err != nil { return err } switch typ { case "place.stream.chat.access#label": t.ChatAccess_Label = new(ChatAccess_Label) return glex.UnmarshalCBORBytes(b, t.ChatAccess_Label) case "place.stream.chat.access#verifier": t.ChatAccess_Verifier = new(ChatAccess_Verifier) return glex.UnmarshalCBORBytes(b, t.ChatAccess_Verifier) default: t.Raw = &glex.RawRecord{Type: typ, Encoding: "cbor", Bytes: append([]byte(nil), b...)} return nil } } // ChatAccess_Label is a "label" in the place.stream.chat.access schema. // // Accounts carrying this label from this labeler. A node that sees a rule naming a labeler starts mirroring its matching labels. type ChatAccess_Label struct { LexiconTypeID string `json:"$type,omitempty"` // labeler: The labeler's DID. Labeler string `json:"labeler"` // value: The label value that matches; a trailing * matches any label with that prefix. Value string `json:"value"` } // RecordTypeID implements glex.Record. func (t *ChatAccess_Label) RecordTypeID() string { return "place.stream.chat.access#label" } func (t *ChatAccess_Label) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "place.stream.chat.access#label" return glex.MarshalCBOR(w, &cp) } func (t *ChatAccess_Label) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) } // ChatAccess_Verifier is a "verifier" in the place.stream.chat.access schema. // // Accounts that hold an app.bsky.graph.verification record issued by this DID. A node that sees a rule naming a verifier starts indexing that verifier's records. type ChatAccess_Verifier struct { LexiconTypeID string `json:"$type,omitempty"` // did: The verifier's DID. Did string `json:"did"` } // RecordTypeID implements glex.Record. func (t *ChatAccess_Verifier) RecordTypeID() string { return "place.stream.chat.access#verifier" } func (t *ChatAccess_Verifier) MarshalCBOR(w io.Writer) error { if t == nil { _, err := w.Write(cbg.CborNull) return err } // stamp $type on a copy so marshal never mutates the record cp := *t cp.LexiconTypeID = "place.stream.chat.access#verifier" return glex.MarshalCBOR(w, &cp) } func (t *ChatAccess_Verifier) UnmarshalCBOR(r io.Reader) error { return glex.UnmarshalCBOR(r, t) }