diff --git a/http.go b/http.go
index 9677792..f42c1ab 100644
--- a/http.go
+++ b/http.go
@@ -212,6 +212,7 @@ func buildStaticHandlersRouters() error {
notificationsRouter.Use(authMiddleware)
notificationsRouter.Get("/", notificationsAdmin)
notificationsRouter.Get(paginationPath, notificationsAdmin)
+ notificationsRouter.Post("/delete", notificationsAdminDelete)
if ap := appConfig.ActivityPub; ap != nil && ap.Enabled {
activitypubRouter = chi.NewRouter()
diff --git a/notifications.go b/notifications.go
index 9a1162f..c3c25e4 100644
--- a/notifications.go
+++ b/notifications.go
@@ -46,6 +46,11 @@ func saveNotification(n *notification) error {
return nil
}
+func deleteNotification(id int) error {
+ _, err := appDbExec("delete from notifications where id = @id", sql.Named("id", id))
+ return err
+}
+
type notificationsRequestConfig struct {
offset, limit int
}
@@ -157,3 +162,17 @@ func notificationsAdmin(w http.ResponseWriter, r *http.Request) {
},
})
}
+
+func notificationsAdminDelete(w http.ResponseWriter, r *http.Request) {
+ id, err := strconv.Atoi(r.FormValue("notificationid"))
+ if err != nil {
+ serveError(w, r, err.Error(), http.StatusBadRequest)
+ return
+ }
+ err = deleteNotification(id)
+ if err != nil {
+ serveError(w, r, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ http.Redirect(w, r, ".", http.StatusFound)
+}
diff --git a/templateStrings.go b/templateStrings.go
index 3ed679a..d3e30ba 100644
--- a/templateStrings.go
+++ b/templateStrings.go
@@ -37,7 +37,18 @@ func initTemplateStrings() error {
return nil
}
-func getTemplateStringVariant(lang, name string) (result string) {
+func getTemplateStringVariant(input ...string) (result string) {
+ var lang, name string
+ if l := len(input); l == 1 {
+ lang = appConfig.Blogs[appConfig.DefaultBlog].Lang
+ name = input[0]
+ } else if l == 2 {
+ lang = input[0]
+ name = input[1]
+ } else {
+ // Wrong number of input strings
+ return ""
+ }
m, ok := templateStrings[lang]
if !ok {
m = templateStrings[defaultStrings]
diff --git a/templates/notificationsadmin.gohtml b/templates/notificationsadmin.gohtml
index 2edc669..9b2c972 100644
--- a/templates/notificationsadmin.gohtml
+++ b/templates/notificationsadmin.gohtml
@@ -1,22 +1,25 @@
{{ define "title" }}
-
{{ string .Blog.Lang "notifications" }} - {{ .Blog.Title }}
+ {{ string "notifications" }} - {{ .Blog.Title }}
{{ end }}
{{ define "main" }}
- {{ string .Blog.Lang "notifications" }}
+ {{ string "notifications" }}
{{ range $i, $notification := .Data.Notifications }}
-
- ID: {{ $notification.ID }}
- Time: {{ unixtodate $notification.Time }}
- Text: {{ $notification.Text }}
-
+
+
{{ unixtodate $notification.Time }}
+ {{ md $notification.Text }}
+
+
{{ end }}
{{ if .Data.HasPrev }}
- {{ string .Blog.Lang "prev" }}
+ {{ string "prev" }}
{{ end }}
{{ if .Data.HasNext }}
- {{ string .Blog.Lang "next" }}
+ {{ string "next" }}
{{ end }}
{{ end }}