fork
Configure Feed
Select the types of activity you want to include in your feed.
Live video on the AT Protocol
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package statedb
2
3import (
4 "fmt"
5 "time"
6)
7
8type Notification struct {
9 Token string `gorm:"column:token;primarykey"`
10 RepoDID string `json:"repoDID,omitempty" gorm:"column:repo_did;index"`
11 CreatedAt time.Time `gorm:"column:created_at"`
12 UpdatedAt time.Time `gorm:"column:updated_at"`
13}
14
15func (state *StatefulDB) CreateNotification(token string, repoDID string) error {
16 not := Notification{
17 Token: token,
18 }
19 if repoDID != "" {
20 not.RepoDID = repoDID
21 }
22 err := state.DB.Save(¬).Error
23 if err != nil {
24 return err
25 }
26 return nil
27}
28
29func (state *StatefulDB) ListNotifications() ([]Notification, error) {
30 nots := []Notification{}
31 err := state.DB.Find(¬s).Error
32 if err != nil {
33 return nil, fmt.Errorf("error retrieving notifications: %w", err)
34 }
35 return nots, nil
36}
37
38func (state *StatefulDB) ListUserNotifications(userDID string) ([]Notification, error) {
39 nots := []Notification{}
40 err := state.DB.Where("repo_did = ?", userDID).Find(¬s).Error
41 if err != nil {
42 return nil, fmt.Errorf("error retrieving notifications: %w", err)
43 }
44 return nots, nil
45}
46
47func (state *StatefulDB) GetManyNotificationTokens(userDIDs []string) ([]string, error) {
48 tokens := []string{}
49 err := state.DB.Model(&Notification{}).
50 Where("repo_did IN (?)", userDIDs).
51 Pluck("token", &tokens).
52 Error
53 if err != nil {
54 return nil, fmt.Errorf("error retrieving notification tokens: %w", err)
55 }
56 return tokens, nil
57}