Monorepo for Tangled tangled.org
6

Configure Feed

Select the types of activity you want to include in your feed.

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 NotificationTypeIssueAssigned NotificationType = "issue_assigned" 25 NotificationTypeIssueUnassigned NotificationType = "issue_unassigned" 26 NotificationTypePullAssigned NotificationType = "pull_assigned" 27 NotificationTypePullUnassigned NotificationType = "pull_unassigned" 28) 29 30var SocialNotificationTypes = []NotificationType{ 31 NotificationTypeRepoStarred, 32 NotificationTypeFollowed, 33} 34 35var WorkNotificationTypes = []NotificationType{ 36 NotificationTypeIssueCreated, 37 NotificationTypeIssueCommented, 38 NotificationTypeIssueClosed, 39 NotificationTypeIssueReopen, 40 NotificationTypePullCreated, 41 NotificationTypePullCommented, 42 NotificationTypePullMerged, 43 NotificationTypePullClosed, 44 NotificationTypePullReopen, 45 NotificationTypeUserMentioned, 46 NotificationTypeIssueAssigned, 47 NotificationTypeIssueUnassigned, 48 NotificationTypePullAssigned, 49 NotificationTypePullUnassigned, 50} 51 52type Notification struct { 53 ID int64 54 RecipientDid string 55 ActorDid string 56 Type NotificationType 57 EntityType string 58 EntityId string 59 Read bool 60 Created time.Time 61 62 // foreign key references 63 RepoId *int64 64 IssueId *int64 65 PullId *int64 66} 67 68// lucide icon that represents this notification 69func (n *Notification) Icon() string { 70 switch n.Type { 71 case NotificationTypeRepoStarred: 72 return "star" 73 case NotificationTypeIssueCreated: 74 return "circle-dot" 75 case NotificationTypeIssueCommented: 76 return "message-square" 77 case NotificationTypeIssueClosed: 78 return "ban" 79 case NotificationTypeIssueReopen: 80 return "circle-dot" 81 case NotificationTypePullCreated: 82 return "git-pull-request-create" 83 case NotificationTypePullCommented: 84 return "message-square" 85 case NotificationTypePullMerged: 86 return "git-merge" 87 case NotificationTypePullClosed: 88 return "git-pull-request-closed" 89 case NotificationTypePullReopen: 90 return "git-pull-request-create" 91 case NotificationTypeFollowed: 92 return "user-plus" 93 case NotificationTypeUserMentioned: 94 return "at-sign" 95 case NotificationTypeIssueAssigned, NotificationTypePullAssigned: 96 return "user-round-arrow-forward" 97 case NotificationTypeIssueUnassigned, NotificationTypePullUnassigned: 98 return "user-round-minus" 99 default: 100 return "" 101 } 102} 103 104type NotificationWithEntity struct { 105 *Notification 106 Repo *Repo 107 Issue *Issue 108 Pull *Pull 109} 110 111type NotificationPreferences struct { 112 ID int64 113 UserDid syntax.DID 114 RepoStarred bool 115 IssueCreated bool 116 IssueCommented bool 117 PullCreated bool 118 PullCommented bool 119 Followed bool 120 UserMentioned bool 121 PullMerged bool 122 IssueClosed bool 123 EmailNotifications bool 124} 125 126func (prefs *NotificationPreferences) ShouldNotify(t NotificationType) bool { 127 switch t { 128 case NotificationTypeRepoStarred: 129 return prefs.RepoStarred 130 case NotificationTypeIssueCreated: 131 return prefs.IssueCreated 132 case NotificationTypeIssueCommented: 133 return prefs.IssueCommented 134 case NotificationTypeIssueClosed: 135 return prefs.IssueClosed 136 case NotificationTypeIssueReopen: 137 return prefs.IssueCreated // same pref for now 138 case NotificationTypePullCreated: 139 return prefs.PullCreated 140 case NotificationTypePullCommented: 141 return prefs.PullCommented 142 case NotificationTypePullMerged: 143 return prefs.PullMerged 144 case NotificationTypePullClosed: 145 return prefs.PullMerged // same pref for now 146 case NotificationTypePullReopen: 147 return prefs.PullCreated // same pref for now 148 case NotificationTypeFollowed: 149 return prefs.Followed 150 case NotificationTypeUserMentioned, 151 NotificationTypeIssueAssigned, 152 NotificationTypeIssueUnassigned, 153 NotificationTypePullAssigned, 154 NotificationTypePullUnassigned: 155 return prefs.UserMentioned 156 default: 157 return false 158 } 159} 160 161func DefaultNotificationPreferences(user syntax.DID) *NotificationPreferences { 162 return &NotificationPreferences{ 163 UserDid: user, 164 RepoStarred: true, 165 IssueCreated: true, 166 IssueCommented: true, 167 PullCreated: true, 168 PullCommented: true, 169 Followed: true, 170 UserMentioned: true, 171 PullMerged: true, 172 IssueClosed: true, 173 EmailNotifications: false, 174 } 175}