1package models
2
3import (
4 "database/sql"
5 "time"
6
7 "gorm.io/gorm"
8
9 bsky "github.com/bluesky-social/indigo/api/bsky"
10 "github.com/bluesky-social/indigo/xrpc"
11)
12
13type FeedPost struct {
14 gorm.Model
15 Author Uid `gorm:"index:idx_feedpost_rkey,unique"`
16 Rkey string `gorm:"index:idx_feedpost_rkey,unique"`
17 Cid string
18 UpCount int64
19 ReplyCount int64
20 RepostCount int64
21 ReplyTo uint
22 Missing bool
23 Deleted bool
24}
25
26type RepostRecord struct {
27 ID uint `gorm:"primarykey"`
28 CreatedAt time.Time
29 RecCreated string
30 Post uint
31 Reposter Uid
32 Author Uid
33 RecCid string
34 Rkey string
35}
36
37type ActorInfo struct {
38 gorm.Model
39 Uid Uid `gorm:"uniqueindex"`
40 Handle sql.NullString `gorm:"index"`
41 DisplayName string
42 Did string `gorm:"uniqueindex"`
43 Following int64
44 Followers int64
45 Posts int64
46 Type string
47 PDS uint
48 ValidHandle bool `gorm:"default:true"`
49}
50
51func (ai *ActorInfo) ActorRef() *bsky.ActorDefs_ProfileViewBasic {
52 return &bsky.ActorDefs_ProfileViewBasic{
53 Did: ai.Did,
54 Handle: ai.Handle.String,
55 DisplayName: &ai.DisplayName,
56 }
57}
58
59// TODO: this is just s stub; needs to populate more info
60func (ai *ActorInfo) ActorView() *bsky.ActorDefs_ProfileView {
61 return &bsky.ActorDefs_ProfileView{
62 Did: ai.Did,
63 Handle: ai.Handle.String,
64 DisplayName: &ai.DisplayName,
65 }
66}
67
68type VoteDir int
69
70func (vd VoteDir) String() string {
71 switch vd {
72 case VoteDirUp:
73 return "up"
74 case VoteDirDown:
75 return "down"
76 default:
77 return "<unknown>"
78 }
79}
80
81const (
82 VoteDirUp = VoteDir(1)
83 VoteDirDown = VoteDir(2)
84)
85
86type VoteRecord struct {
87 gorm.Model
88 Dir VoteDir
89 Voter Uid
90 Post uint
91 Created string
92 Rkey string
93 Cid string
94}
95
96type FollowRecord struct {
97 gorm.Model
98 Follower Uid
99 Target Uid
100 Rkey string
101 Cid string
102}
103
104type PDS struct {
105 gorm.Model
106
107 Host string
108 Did string
109 SSL bool
110 Cursor int64
111 Registered bool
112 Blocked bool
113
114 RateLimit float64
115 CrawlRateLimit float64
116
117 RepoCount int64
118 RepoLimit int64
119
120 HourlyEventLimit int64
121 DailyEventLimit int64
122}
123
124func ClientForPds(pds *PDS) *xrpc.Client {
125 if pds.SSL {
126 return &xrpc.Client{
127 Host: "https://" + pds.Host,
128 }
129 }
130
131 return &xrpc.Client{
132 Host: "http://" + pds.Host,
133 }
134}
135
136// The CreatedAt column corresponds to the 'cat' timestamp on label records. The UpdatedAt column is database-specific.
137//
138// NOTE: to get fast string-prefix queries on Uri via the idx_uri_src_val_cid index, it is important that the PostgreSQL LC_COLLATE="C"
139type Label struct {
140 ID uint64 `gorm:"primaryKey"`
141 Uri string `gorm:"uniqueIndex:idx_uri_src_val_cid;not null"`
142 SourceDid string `gorm:"uniqueIndex:idx_uri_src_val_cid;uniqueIndex:idx_src_rkey;not null"`
143 Val string `gorm:"uniqueIndex:idx_uri_src_val_cid;not null"`
144 Cid *string `gorm:"uniqueIndex:idx_uri_src_val_cid"`
145 Neg *bool
146 RepoRKey *string `gorm:"uniqueIndex:idx_src_rkey"`
147 CreatedAt time.Time
148 UpdatedAt time.Time
149}
150
151type DomainBan struct {
152 gorm.Model
153 Domain string
154}