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.27 55 lines 1.5 kB view raw
1package model 2 3import ( 4 "context" 5 "errors" 6 "time" 7 8 "gorm.io/gorm" 9 "stream.place/streamplace/pkg/streamplace" 10) 11 12type Gate struct { 13 RKey string `gorm:"primaryKey;column:rkey"` 14 CID string `gorm:"column:cid"` 15 RepoDID string `json:"repoDID" gorm:"column:repo_did"` 16 Repo *Repo `json:"repo,omitempty" gorm:"foreignKey:DID;references:RepoDID"` 17 HiddenMessage string `gorm:"column:hidden_message" json:"hiddenMessage"` 18 CreatedAt time.Time `gorm:"column:created_at"` 19} 20 21func (g *Gate) ToStreamplaceGate() (*streamplace.ChatGate, error) { 22 return &streamplace.ChatGate{ 23 LexiconTypeID: "place.stream.chat.gate", 24 HiddenMessage: g.HiddenMessage, 25 }, nil 26} 27 28func (m *DBModel) CreateGate(ctx context.Context, gate *Gate) error { 29 return m.DB.Create(gate).Error 30} 31 32func (m *DBModel) GetGate(ctx context.Context, rkey string) (*Gate, error) { 33 var gate Gate 34 err := m.DB.Preload("Repo").Where("rkey = ?", rkey).First(&gate).Error 35 if errors.Is(err, gorm.ErrRecordNotFound) { 36 return nil, nil 37 } 38 if err != nil { 39 return nil, err 40 } 41 return &gate, nil 42} 43 44func (m *DBModel) DeleteGate(ctx context.Context, rkey string) error { 45 return m.DB.Where("rkey = ?", rkey).Delete(&Gate{}).Error 46} 47 48func (m *DBModel) GetUserGates(ctx context.Context, userDID string) ([]*Gate, error) { 49 var gates []*Gate 50 err := m.DB.Where("repo_did = ?", userDID).Find(&gates).Error 51 if err != nil { 52 return nil, err 53 } 54 return gates, nil 55}