From 4907cf76402996ab9c1606999eec9e70c256c505 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Wed, 10 Sep 2025 18:16:19 +0300 Subject: [PATCH] appview/{notify,strings}: notify on string create/edit/delete ops Change-Id: zwoymssunvspuzqvtvxzlxqsyzznsmkn Signed-off-by: Anirudh Oppiliappan --- appview/notify/merged_notifier.go | 18 ++++++++++++++++++ appview/notify/notifier.go | 8 ++++++++ appview/strings/strings.go | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/appview/notify/merged_notifier.go b/appview/notify/merged_notifier.go index faf0a11e..8eb72dd4 100644 --- a/appview/notify/merged_notifier.go +++ b/appview/notify/merged_notifier.go @@ -66,3 +66,21 @@ func (m *mergedNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) notifier.UpdateProfile(ctx, profile) } } + +func (m *mergedNotifier) NewString(ctx context.Context, string *db.String) { + for _, notifier := range m.notifiers { + notifier.NewString(ctx, string) + } +} + +func (m *mergedNotifier) EditString(ctx context.Context, string *db.String) { + for _, notifier := range m.notifiers { + notifier.EditString(ctx, string) + } +} + +func (m *mergedNotifier) DeleteString(ctx context.Context, did, rkey string) { + for _, notifier := range m.notifiers { + notifier.DeleteString(ctx, did, rkey) + } +} diff --git a/appview/notify/notifier.go b/appview/notify/notifier.go index 89f81215..eb24f157 100644 --- a/appview/notify/notifier.go +++ b/appview/notify/notifier.go @@ -21,6 +21,10 @@ type Notifier interface { NewPullComment(ctx context.Context, comment *db.PullComment) UpdateProfile(ctx context.Context, profile *db.Profile) + + NewString(ctx context.Context, s *db.String) + EditString(ctx context.Context, s *db.String) + DeleteString(ctx context.Context, did, rkey string) } // BaseNotifier is a listener that does nothing @@ -42,3 +46,7 @@ func (m *BaseNotifier) NewPull(ctx context.Context, pull *db.Pull) func (m *BaseNotifier) NewPullComment(ctx context.Context, comment *db.PullComment) {} func (m *BaseNotifier) UpdateProfile(ctx context.Context, profile *db.Profile) {} + +func (m *BaseNotifier) NewString(ctx context.Context, s *db.String) {} +func (m *BaseNotifier) EditString(ctx context.Context, s *db.String) {} +func (m *BaseNotifier) DeleteString(ctx context.Context, did, rkey string) {} diff --git a/appview/strings/strings.go b/appview/strings/strings.go index cb9328ab..f1e4267c 100644 --- a/appview/strings/strings.go +++ b/appview/strings/strings.go @@ -12,6 +12,7 @@ import ( "tangled.sh/tangled.sh/core/appview/config" "tangled.sh/tangled.sh/core/appview/db" "tangled.sh/tangled.sh/core/appview/middleware" + "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/pages/markup" @@ -36,6 +37,7 @@ type Strings struct { IdResolver *idresolver.Resolver Logger *slog.Logger Knotstream *eventconsumer.Consumer + Notifier notify.Notifier } func (s *Strings) Router(mw *middleware.Middleware) http.Handler { @@ -284,6 +286,8 @@ func (s *Strings) edit(w http.ResponseWriter, r *http.Request) { return } + s.Notifier.EditString(r.Context(), &entry) + // if that went okay, redir to the string s.Pages.HxRedirect(w, "/strings/"+user.Handle+"/"+entry.Rkey) } @@ -358,6 +362,8 @@ func (s *Strings) create(w http.ResponseWriter, r *http.Request) { return } + s.Notifier.NewString(r.Context(), &string) + // successful s.Pages.HxRedirect(w, "/strings/"+user.Handle+"/"+string.Rkey) } @@ -400,6 +406,8 @@ func (s *Strings) delete(w http.ResponseWriter, r *http.Request) { return } + s.Notifier.DeleteString(r.Context(), user.Did, rkey) + s.Pages.HxRedirect(w, "/strings/"+user.Handle) } -- 2.43.0