forked from tangled.org/core
Monorepo for Tangled — https://tangled.org
at master 3.9 kB view raw
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 UserMentioned bool 91 PullMerged bool 92 IssueClosed bool 93 EmailNotifications bool 94} 95 96func (prefs *NotificationPreferences) ShouldNotify(t NotificationType) bool { 97 switch t { 98 case NotificationTypeRepoStarred: 99 return prefs.RepoStarred 100 case NotificationTypeIssueCreated: 101 return prefs.IssueCreated 102 case NotificationTypeIssueCommented: 103 return prefs.IssueCommented 104 case NotificationTypeIssueClosed: 105 return prefs.IssueClosed 106 case NotificationTypeIssueReopen: 107 return prefs.IssueCreated // smae pref for now 108 case NotificationTypePullCreated: 109 return prefs.PullCreated 110 case NotificationTypePullCommented: 111 return prefs.PullCommented 112 case NotificationTypePullMerged: 113 return prefs.PullMerged 114 case NotificationTypePullClosed: 115 return prefs.PullMerged // same pref for now 116 case NotificationTypePullReopen: 117 return prefs.PullCreated // same pref for now 118 case NotificationTypeFollowed: 119 return prefs.Followed 120 case NotificationTypeUserMentioned: 121 return prefs.UserMentioned 122 default: 123 return false 124 } 125} 126 127func DefaultNotificationPreferences(user syntax.DID) *NotificationPreferences { 128 return &NotificationPreferences{ 129 UserDid: user, 130 RepoStarred: true, 131 IssueCreated: true, 132 IssueCommented: true, 133 PullCreated: true, 134 PullCommented: true, 135 Followed: true, 136 UserMentioned: true, 137 PullMerged: true, 138 IssueClosed: true, 139 EmailNotifications: false, 140 } 141}