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
···
+
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)
+
}
+
}
+14
appview/notify/notifier.go
···
+
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)
+
}
+1 -1
appview/state/router.go
···
}
func (s *State) IssuesRouter(mw *middleware.Middleware) http.Handler {
-
issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog)
+
issues := issues.New(s.oauth, s.repoResolver, s.pages, s.idResolver, s.db, s.config, s.posthog, s.notifier)
return issues.Router(mw)
}
+6
appview/state/state.go
···
"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"
···
type State struct {
db *db.DB
+
notifier notify.Notifier
oauth *oauth.OAuth
enforcer *rbac.Enforcer
tidClock syntax.TIDClock
···
}
spindlestream.Start(ctx)
+
notifier := notify.NewMergedNotifier(
+
)
+
state := &State{
d,
+
notifier,
oauth,
enforcer,
clock,