appview: add internal notification system #8

open
opened by boltless.me targeting master from feat/search
Changed files
+58 -1
appview
+37
appview/notify/merged_notifier.go
··· 1 + package notify 2 + 3 + import ( 4 + "context" 5 + 6 + "tangled.sh/tangled.sh/core/appview/db" 7 + ) 8 + 9 + type mergedNotifier struct { 10 + notifiers []Notifier 11 + } 12 + 13 + func NewMergedNotifier(notifiers ...Notifier) Notifier { 14 + return &mergedNotifier{ 15 + notifiers, 16 + } 17 + } 18 + 19 + var _ Notifier = &mergedNotifier{} 20 + 21 + func (m *mergedNotifier) NewIssue(ctx context.Context, issue db.Issue) { 22 + for _, notifier := range m.notifiers { 23 + notifier.NewIssue(ctx, issue) 24 + } 25 + } 26 + 27 + func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment db.Comment) { 28 + for _, notifier := range m.notifiers { 29 + notifier.NewIssueComment(ctx, comment) 30 + } 31 + } 32 + 33 + func (m *mergedNotifier) NewPullComment(ctx context.Context, comment db.PullComment) { 34 + for _, notifier := range m.notifiers { 35 + notifier.NewPullComment(ctx, comment) 36 + } 37 + }
+14
appview/notify/notifier.go
··· 1 + package notify 2 + 3 + import ( 4 + "context" 5 + 6 + "tangled.sh/tangled.sh/core/appview/db" 7 + ) 8 + 9 + type Notifier interface { 10 + NewIssue(ctx context.Context, issue db.Issue) 11 + NewIssueComment(ctx context.Context, comment db.Comment) 12 + 13 + NewPullComment(ctx context.Context, comment db.PullComment) 14 + }
+1 -1
appview/state/router.go
··· 191 191 } 192 192 193 193 func (s *State) IssuesRouter(mw *middleware.Middleware) http.Handler { 194 - issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog) 194 + issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog, s.notifier) 195 195 return issues.Router(mw) 196 196 197 197 }
+6
appview/state/state.go
··· 25 25 "tangled.sh/tangled.sh/core/appview/config" 26 26 "tangled.sh/tangled.sh/core/appview/db" 27 27 "tangled.sh/tangled.sh/core/appview/idresolver" 28 + "tangled.sh/tangled.sh/core/appview/notify" 28 29 "tangled.sh/tangled.sh/core/appview/oauth" 29 30 "tangled.sh/tangled.sh/core/appview/pages" 30 31 "tangled.sh/tangled.sh/core/appview/reporesolver" ··· 37 38 38 39 type State struct { 39 40 db *db.DB 41 + notifier notify.Notifier 40 42 oauth *oauth.OAuth 41 43 enforcer *rbac.Enforcer 42 44 tidClock syntax.TIDClock ··· 134 136 } 135 137 spindlestream.Start(ctx) 136 138 139 + notifier := notify.NewMergedNotifier( 140 + ) 141 + 137 142 state := &State{ 138 143 d, 144 + notifier, 139 145 oauth, 140 146 enforcer, 141 147 clock,