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) 23 24type Notification struct { 25 ID int64 26 RecipientDid string 27 ActorDid string 28 Type NotificationType 29 EntityType string 30 EntityId string 31 Read bool 32 Created time.Time 33 34 // foreign key references 35 RepoId *int64 36 IssueId *int64 37 PullId *int64 38} 39 40// lucide icon that represents this notification 41func (n *Notification) Icon() string { 42 switch n.Type { 43 case NotificationTypeRepoStarred: 44 return "star" 45 case NotificationTypeIssueCreated: 46 return "circle-dot" 47 case NotificationTypeIssueCommented: 48 return "message-square" 49 case NotificationTypeIssueClosed: 50 return "ban" 51 case NotificationTypeIssueReopen: 52 return "circle-dot" 53 case NotificationTypePullCreated: 54 return "git-pull-request-create" 55 case NotificationTypePullCommented: 56 return "message-square" 57 case NotificationTypePullMerged: 58 return "git-merge" 59 case NotificationTypePullClosed: 60 return "git-pull-request-closed" 61 case NotificationTypeFollowed: 62 return "user-plus" 63 default: 64 return "" 65 } 66} 67 68type NotificationWithEntity struct { 69 *Notification 70 Repo *Repo 71 Issue *Issue 72 Pull *Pull 73} 74 75type NotificationPreferences struct { 76 ID int64 77 UserDid syntax.DID 78 RepoStarred bool 79 IssueCreated bool 80 IssueCommented bool 81 PullCreated bool 82 PullCommented bool 83 Followed bool 84 PullMerged bool 85 IssueClosed bool 86 EmailNotifications bool 87} 88 89func (prefs *NotificationPreferences) ShouldNotify(t NotificationType) bool { 90 switch t { 91 case NotificationTypeRepoStarred: 92 return prefs.RepoStarred 93 case NotificationTypeIssueCreated: 94 return prefs.IssueCreated 95 case NotificationTypeIssueCommented: 96 return prefs.IssueCommented 97 case NotificationTypeIssueClosed: 98 return prefs.IssueClosed 99 case NotificationTypeIssueReopen: 100 return prefs.IssueCreated // smae pref for now 101 case NotificationTypePullCreated: 102 return prefs.PullCreated 103 case NotificationTypePullCommented: 104 return prefs.PullCommented 105 case NotificationTypePullMerged: 106 return prefs.PullMerged 107 case NotificationTypePullClosed: 108 return prefs.PullMerged // same pref for now 109 case NotificationTypeFollowed: 110 return prefs.Followed 111 default: 112 return false 113 } 114} 115 116func DefaultNotificationPreferences(user syntax.DID) *NotificationPreferences { 117 return &NotificationPreferences{ 118 UserDid: user, 119 RepoStarred: true, 120 IssueCreated: true, 121 IssueCommented: true, 122 PullCreated: true, 123 PullCommented: true, 124 Followed: true, 125 PullMerged: true, 126 IssueClosed: true, 127 EmailNotifications: false, 128 } 129}