From 8ac30f1ac69783c36aacc9a8d6152f0979247899 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sat, 12 Jul 2025 11:28:10 +0000 Subject: [PATCH] appview: add internal notification system Signed-off-by: Seongmin Lee --- appview/notify/merged_notifier.go | 37 +++++++++++++++++++++++++++++++++++++ appview/notify/notifier.go | 14 ++++++++++++++ appview/state/state.go | 6 ++++++ 3 file(s) changed, 57 insertion(s)(+), 0 deletion(s)(-) diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go new file mode 100644 --- /dev/null +++ b/appview/notify/merged_notifier.go @@ -0,0 +1,37 @@ +package notify + +import ( + "context" + + "tangled.sh/tangled.sh/core/appview/db" +) + +type mergedNotifier struct { + notifiers []Notifier +} + +func NewMergedNotifier(notifiers ...Notifier) Notifier { + return &mergedNotifier{ + notifiers, + } +} + +var _ Notifier = &mergedNotifier{} + +func (m *mergedNotifier) NewIssue(ctx context.Context, issue *db.Issue) { + for _, notifier := range m.notifiers { + notifier.NewIssue(ctx, issue) + } +} + +func (m *mergedNotifier) NewIssueComment(ctx context.Context, comment db.Comment) { + for _, notifier := range m.notifiers { + notifier.NewIssueComment(ctx, comment) + } +} + +func (m *mergedNotifier) NewPullComment(ctx context.Context, comment db.PullComment) { + for _, notifier := range m.notifiers { + notifier.NewPullComment(ctx, comment) + } +} diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go new file mode 100644 --- /dev/null +++ b/appview/notify/notifier.go @@ -0,0 +1,14 @@ +package notify + +import ( + "context" + + "tangled.sh/tangled.sh/core/appview/db" +) + +type Notifier interface { + NewIssue(ctx context.Context, issue *db.Issue) + NewIssueComment(ctx context.Context, comment db.Comment) + + NewPullComment(ctx context.Context, comment db.PullComment) +} diff --git a/appview/state/state.go b/appview/state/state.go --- a/appview/state/state.go +++ b/appview/state/state.go @@ -22,6 +22,7 @@ "tangled.sh/tangled.sh/core/appview/config" "tangled.sh/tangled.sh/core/appview/db" "tangled.sh/tangled.sh/core/appview/idresolver" + "tangled.sh/tangled.sh/core/appview/notify" "tangled.sh/tangled.sh/core/appview/oauth" "tangled.sh/tangled.sh/core/appview/pages" "tangled.sh/tangled.sh/core/appview/reporesolver" @@ -34,6 +35,7 @@ type State struct { db *db.DB + notifier notify.Notifier oauth *oauth.OAuth enforcer *rbac.Enforcer tidClock syntax.TIDClock @@ -131,8 +133,12 @@ } spindlestream.Start(ctx) + notifier := notify.NewMergedNotifier( + ) + state := &State{ d, + notifier, oauth, enforcer, clock, -- tangled.sh