From 9e057f174fa05a82776045795ad54a2e6a2ccbb6 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sat, 12 Jul 2025 20:28:10 +0900 Subject: [PATCH] appview: add internal notification system Change-Id: quxnxquxmqrzpwkqzryqlxvwsptomlzs Signed-off-by: Seongmin Lee --- appview/notify/merged_notifier.go | 37 +++++++++++++++++++++++++++++++ appview/notify/notifier.go | 14 ++++++++++++ appview/state/state.go | 6 +++++ 3 files changed, 57 insertions(+) create mode 100644 appview/notify/merged_notifier.go create mode 100644 appview/notify/notifier.go diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go new file mode 100644 index 0000000..901cda8 --- /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 index 0000000..5eff4d3 --- /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 index a5b30a6..da4f7e8 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -22,6 +22,7 @@ import ( "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 @@ import ( type State struct { db *db.DB + notifier notify.Notifier oauth *oauth.OAuth enforcer *rbac.Enforcer tidClock syntax.TIDClock @@ -131,8 +133,12 @@ func Make(ctx context.Context, config *config.Config) (*State, error) { } spindlestream.Start(ctx) + notifier := notify.NewMergedNotifier( + ) + state := &State{ d, + notifier, oauth, enforcer, clock, -- 2.43.0