this repo has no description
1package models
2
3import (
4 "time"
5
6 "github.com/bluesky-social/indigo/atproto/syntax"
7)
8
9type NotificationType string
10
11const (
12 NotificationTypeRepoStarred NotificationType = "repo_starred"
13 NotificationTypeIssueCreated NotificationType = "issue_created"
14 NotificationTypeIssueCommented NotificationType = "issue_commented"
15 NotificationTypePullCreated NotificationType = "pull_created"
16 NotificationTypePullCommented NotificationType = "pull_commented"
17 NotificationTypeFollowed NotificationType = "followed"
18 NotificationTypePullMerged NotificationType = "pull_merged"
19 NotificationTypeIssueClosed NotificationType = "issue_closed"
20 NotificationTypeIssueReopen NotificationType = "issue_reopen"
21 NotificationTypePullClosed NotificationType = "pull_closed"
22 NotificationTypePullReopen NotificationType = "pull_reopen"
23 NotificationTypeUserMentioned NotificationType = "user_mentioned"
24)
25
26type Notification struct {
27 ID int64
28 RecipientDid string
29 ActorDid string
30 Type NotificationType
31 EntityType string
32 EntityId string
33 Read bool
34 Created time.Time
35
36 // foreign key references
37 RepoId *int64
38 IssueId *int64
39 PullId *int64
40}
41
42// lucide icon that represents this notification
43func (n *Notification) Icon() string {
44 switch n.Type {
45 case NotificationTypeRepoStarred:
46 return "star"
47 case NotificationTypeIssueCreated:
48 return "circle-dot"
49 case NotificationTypeIssueCommented:
50 return "message-square"
51 case NotificationTypeIssueClosed:
52 return "ban"
53 case NotificationTypeIssueReopen:
54 return "circle-dot"
55 case NotificationTypePullCreated:
56 return "git-pull-request-create"
57 case NotificationTypePullCommented:
58 return "message-square"
59 case NotificationTypePullMerged:
60 return "git-merge"
61 case NotificationTypePullClosed:
62 return "git-pull-request-closed"
63 case NotificationTypePullReopen:
64 return "git-pull-request-create"
65 case NotificationTypeFollowed:
66 return "user-plus"
67 case NotificationTypeUserMentioned:
68 return "at-sign"
69 default:
70 return ""
71 }
72}
73
74type NotificationWithEntity struct {
75 *Notification
76 Repo *Repo
77 Issue *Issue
78 Pull *Pull
79}
80
81type NotificationPreferences struct {
82 ID int64
83 UserDid syntax.DID
84 RepoStarred bool
85 IssueCreated bool
86 IssueCommented bool
87 PullCreated bool
88 PullCommented bool
89 Followed bool
90 PullMerged bool
91 IssueClosed bool
92 EmailNotifications bool
93}
94
95func (prefs *NotificationPreferences) ShouldNotify(t NotificationType) bool {
96 switch t {
97 case NotificationTypeRepoStarred:
98 return prefs.RepoStarred
99 case NotificationTypeIssueCreated:
100 return prefs.IssueCreated
101 case NotificationTypeIssueCommented:
102 return prefs.IssueCommented
103 case NotificationTypeIssueClosed:
104 return prefs.IssueClosed
105 case NotificationTypeIssueReopen:
106 return prefs.IssueCreated // smae pref for now
107 case NotificationTypePullCreated:
108 return prefs.PullCreated
109 case NotificationTypePullCommented:
110 return prefs.PullCommented
111 case NotificationTypePullMerged:
112 return prefs.PullMerged
113 case NotificationTypePullClosed:
114 return prefs.PullMerged // same pref for now
115 case NotificationTypePullReopen:
116 return prefs.PullCreated // same pref for now
117 case NotificationTypeFollowed:
118 return prefs.Followed
119 case NotificationTypeUserMentioned:
120 return true // always notify on mention
121 default:
122 return false
123 }
124}
125
126func DefaultNotificationPreferences(user syntax.DID) *NotificationPreferences {
127 return &NotificationPreferences{
128 UserDid: user,
129 RepoStarred: true,
130 IssueCreated: true,
131 IssueCommented: true,
132 PullCreated: true,
133 PullCommented: true,
134 Followed: true,
135 PullMerged: true,
136 IssueClosed: true,
137 EmailNotifications: false,
138 }
139}