Monorepo for Tangled
Something went wrong. Try again.
Go
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168package models
import ( "fmt" "time"
"github.com/bluesky-social/indigo/atproto/syntax" "github.com/ipfs/go-cid")
type VouchSuggestion struct { Did syntax.DID Reason string VouchRelationship *VouchRelationship}
type VouchKind string
const ( VouchKindVouch VouchKind = "vouch" VouchKindDenounce VouchKind = "denounce")
func ParseVouchKind(v string) (VouchKind, error) { switch v { case "vouch": return VouchKindVouch, nil case "denounce": return VouchKindDenounce, nil default: return VouchKindVouch, fmt.Errorf("invalid vouch kind: %s", v) }}
type Vouch struct { Did syntax.DID SubjectDid syntax.DID Cid cid.Cid Kind VouchKind Reason *string Evidences []syntax.ATURI CreatedAt time.Time}
func (v Vouch) IsVouch() bool { return v.Kind == VouchKindVouch}
func (v Vouch) IsDenounce() bool { return v.Kind == VouchKindDenounce}
type VouchStats struct { Vouches int64 Denounces int64}
type VouchRelationship struct { ViewerDid syntax.DID SubjectDid syntax.DID
NetworkVouches []Vouch}
func (vr *VouchRelationship) IsDirectVouch() bool { for _, v := range vr.NetworkVouches { if v.Did == vr.ViewerDid && v.SubjectDid == vr.SubjectDid && v.Kind == VouchKindVouch { return true } } return false}
func (vr *VouchRelationship) IsDirectDenounce() bool { for _, v := range vr.NetworkVouches { if v.Did == vr.ViewerDid && v.SubjectDid == vr.SubjectDid && v.Kind == VouchKindDenounce { return true } } return false}
func (vr *VouchRelationship) IndirectVouches() []Vouch { var indirectVouches []Vouch for _, v := range vr.NetworkVouches { if v.Did != vr.ViewerDid { indirectVouches = append(indirectVouches, v) } } return indirectVouches}
func (vr *VouchRelationship) IsEmpty() bool { return len(vr.NetworkVouches) == 0}
func (vr *VouchRelationship) GetDirectVouch() *Vouch { for _, v := range vr.NetworkVouches { if v.Did == vr.ViewerDid && v.SubjectDid == vr.SubjectDid { return &v } } return nil}
func (vr *VouchRelationship) IsIndirectVouch() bool { if vr.IsDirectVouch() || vr.IsDirectDenounce() { return false } for _, v := range vr.NetworkVouches { if v.Did != vr.ViewerDid && v.Kind == VouchKindVouch { return true } } return false}
func (vr *VouchRelationship) IsIndirectDenounce() bool { if vr.IsDirectVouch() || vr.IsDirectDenounce() { return false } for _, v := range vr.NetworkVouches { if v.Did != vr.ViewerDid && v.Kind == VouchKindDenounce { return true } } return false}
func (vr *VouchRelationship) IsMixed() bool { if vr.IsDirectVouch() || vr.IsDirectDenounce() { return false } hasVouch := false hasDenounce := false for _, v := range vr.NetworkVouches { if v.Did != vr.ViewerDid { switch v.Kind { case VouchKindVouch: hasVouch = true case VouchKindDenounce: hasDenounce = true } } } return hasVouch && hasDenounce}
func (vr *VouchRelationship) VouchStrength() int { count := 0 for _, v := range vr.NetworkVouches { if v.Did != vr.ViewerDid && v.Kind == VouchKindVouch { count++ } } return count}
func (vr *VouchRelationship) DenounceStrength() int { count := 0 for _, v := range vr.NetworkVouches { if v.Did != vr.ViewerDid && v.Kind == VouchKindDenounce { count++ } } return count}