Live video on the AT Protocol
at natb/block-javascript-protocol 61 lines 2.0 kB view raw
1package statedb 2 3import ( 4 "context" 5 "time" 6) 7 8type ModerationAuditLog struct { 9 ID uint `gorm:"primaryKey;autoIncrement"` 10 StreamerDID string `gorm:"column:streamer_did;index:idx_streamer_time,priority:1"` 11 ModeratorDID string `gorm:"column:moderator_did;index:idx_audit_moderator"` 12 Action string `gorm:"column:action"` // "createBlock", "deleteBlock", "createGate", "deleteGate", "updateLivestream" 13 TargetURI string `gorm:"column:target_uri"` // URI of affected resource 14 TargetDID string `gorm:"column:target_did"` // DID of affected user (for blocks) 15 ResultURI string `gorm:"column:result_uri"` // URI of created/deleted record 16 Success bool `gorm:"column:success"` 17 ErrorMsg string `gorm:"column:error_msg"` 18 CreatedAt time.Time `gorm:"column:created_at;index:idx_streamer_time,priority:2"` 19} 20 21func (ModerationAuditLog) TableName() string { 22 return "moderation_audit_logs" 23} 24 25func (state *StatefulDB) CreateAuditLog(ctx context.Context, log *ModerationAuditLog) error { 26 return state.DB.WithContext(ctx).Create(log).Error 27} 28 29func (state *StatefulDB) GetAuditLogs(ctx context.Context, streamerDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) { 30 var logs []*ModerationAuditLog 31 query := state.DB.WithContext(ctx).Where("streamer_did = ?", streamerDID). 32 Order("created_at DESC"). 33 Limit(limit) 34 35 if before != nil { 36 query = query.Where("created_at < ?", *before) 37 } 38 39 err := query.Find(&logs).Error 40 if err != nil { 41 return nil, err 42 } 43 return logs, nil 44} 45 46func (state *StatefulDB) GetModeratorAuditLogs(ctx context.Context, moderatorDID string, limit int, before *time.Time) ([]*ModerationAuditLog, error) { 47 var logs []*ModerationAuditLog 48 query := state.DB.WithContext(ctx).Where("moderator_did = ?", moderatorDID). 49 Order("created_at DESC"). 50 Limit(limit) 51 52 if before != nil { 53 query = query.Where("created_at < ?", *before) 54 } 55 56 err := query.Find(&logs).Error 57 if err != nil { 58 return nil, err 59 } 60 return logs, nil 61}