Live video on the AT Protocol
79
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v0.7.32 57 lines 1.4 kB view raw
1package model 2 3import ( 4 "context" 5 "errors" 6 "fmt" 7 8 lexutil "github.com/bluesky-social/indigo/lex/util" 9 "gorm.io/gorm" 10 "stream.place/streamplace/pkg/streamplace" 11) 12 13type ChatProfile struct { 14 RepoDID string `json:"repoDID" gorm:"primarykey;column:repo_did"` 15 Repo *Repo `json:"repo,omitempty" gorm:"foreignKey:DID;references:RepoDID"` 16 Record *[]byte 17} 18 19func (m *ChatProfile) ToStreamplaceChatProfile() (*streamplace.ChatProfile, error) { 20 rec, err := lexutil.CborDecodeValue(*m.Record) 21 if err != nil { 22 return nil, fmt.Errorf("error decoding feed post: %w", err) 23 } 24 scp, ok := rec.(*streamplace.ChatProfile) 25 if !ok { 26 return nil, fmt.Errorf("invalid chat profile") 27 } 28 return scp, nil 29} 30 31func (m *DBModel) CreateChatProfile(ctx context.Context, profile *ChatProfile) error { 32 err := m.DB.Save(profile).Error 33 if err != nil { 34 return err 35 } 36 return nil 37} 38 39func (m *DBModel) GetChatProfile(ctx context.Context, repoDID string) (*ChatProfile, error) { 40 var profile ChatProfile 41 err := m.DB.Where("repo_did = ?", repoDID).First(&profile).Error 42 if errors.Is(err, gorm.ErrRecordNotFound) { 43 return nil, nil 44 } 45 if err != nil { 46 return nil, err 47 } 48 return &profile, nil 49} 50 51func ColorToHex(color *streamplace.ChatProfile_Color) string { 52 if color == nil { 53 return "#f8baca" 54 } 55 hex := fmt.Sprintf("#%02x%02x%02x", color.Red, color.Green, color.Blue) 56 return hex 57}