forked from tangled.org/core
Monorepo for Tangled

appview: add internal notification system

Signed-off-by: Seongmin Lee <boltlessengineer@proton.me>

authored by boltless.me and committed by Tangled 8ac30f1a ec00705f

Changed files
+57
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 + }
+6
appview/state/state.go
··· 22 22 "tangled.sh/tangled.sh/core/appview/config" 23 23 "tangled.sh/tangled.sh/core/appview/db" 24 24 "tangled.sh/tangled.sh/core/appview/idresolver" 25 + "tangled.sh/tangled.sh/core/appview/notify" 25 26 "tangled.sh/tangled.sh/core/appview/oauth" 26 27 "tangled.sh/tangled.sh/core/appview/pages" 27 28 "tangled.sh/tangled.sh/core/appview/reporesolver" ··· 34 35 35 36 type State struct { 36 37 db *db.DB 38 + notifier notify.Notifier 37 39 oauth *oauth.OAuth 38 40 enforcer *rbac.Enforcer 39 41 tidClock syntax.TIDClock ··· 131 133 } 132 134 spindlestream.Start(ctx) 133 135 136 + notifier := notify.NewMergedNotifier( 137 + ) 138 + 134 139 state := &State{ 135 140 d, 141 + notifier, 136 142 oauth, 137 143 enforcer, 138 144 clock,