From 820b6e50950454c8092870fd6f036c35f0cd3fc4 Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:41:36 +0100 Subject: [PATCH] Fixes for 0.6 (#880) * Fix SVG image loading * Fix notification copy * Fix edit comment notifications --- .../src/pages/notifications/Notification.tsx | 2 +- pkg/api/routes_image.go | 6 ++- pkg/sqlx/querybuilder_notifications.go | 39 +++++++++++-------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/frontend/src/pages/notifications/Notification.tsx b/frontend/src/pages/notifications/Notification.tsx index 2cd92faea..70cf71bad 100644 --- a/frontend/src/pages/notifications/Notification.tsx +++ b/frontend/src/pages/notifications/Notification.tsx @@ -50,7 +50,7 @@ const NotificationHeader = ({ {notification.data.comment.user?.name} commented on an{" "} {editLink} - {"you've commented on."} + {" you've commented on."} ); if (notification.data.__typename === "CommentOwnEdit") diff --git a/pkg/api/routes_image.go b/pkg/api/routes_image.go index 8feb74249..34230364c 100644 --- a/pkg/api/routes_image.go +++ b/pkg/api/routes_image.go @@ -33,7 +33,7 @@ func (rs imageRoutes) image(w http.ResponseWriter, r *http.Request) { imageRepo := getRepo(r.Context()).Image() databaseImage, err := imageRepo.Find(uuid) - if err != nil { + if err != nil || databaseImage == nil { http.Error(w, err.Error(), http.StatusNotFound) return } @@ -45,6 +45,10 @@ func (rs imageRoutes) image(w http.ResponseWriter, r *http.Request) { return } + if databaseImage.Width == -1 { + w.Header().Add("Content-Type", "image/svg+xml") + } + w.Header().Add("Cache-Control", "max-age=604800000") maxSize := 0 diff --git a/pkg/sqlx/querybuilder_notifications.go b/pkg/sqlx/querybuilder_notifications.go index bbff2a295..10b7ca426 100644 --- a/pkg/sqlx/querybuilder_notifications.go +++ b/pkg/sqlx/querybuilder_notifications.go @@ -99,23 +99,28 @@ func (qb *notificationsQueryBuilder) TriggerEditCommentNotifications(commentID u args = append(args, commentID) query := ` INSERT INTO notifications - SELECT N.user_id, N.type, $1 - FROM edit_comments EC - JOIN edits E ON EC.edit_id = E.id - JOIN user_notifications N ON E.user_id = N.user_id AND N.type = 'COMMENT_OWN_EDIT' - WHERE EC.id = $1 - UNION - SELECT N.user_id, N.type, $1 - FROM edit_comments EC - JOIN edits E ON EC.edit_id = E.id JOIN edit_comments EO ON EO.edit_id = E.id - JOIN user_notifications N ON EO.user_id = N.user_id AND N.type = 'COMMENT_COMMENTED_EDIT' - WHERE EO.user_id != E.user_id AND EO.user_id != EC.user_id AND EC.id = $1 - UNION - SELECT N.user_id, N.type, $1 - FROM edit_comments EC - JOIN edits E ON EC.edit_id = E.id JOIN edit_votes EV ON EV.edit_id = E.id - JOIN user_notifications N ON EV.user_id = N.user_id AND N.type = 'COMMENT_VOTED_EDIT' - WHERE EV.vote != 'ABSTAIN' AND EV.user_id != E.user_id AND EV.user_id != EC.user_id AND EC.id = $1 + SELECT DISTINCT ON (user_id) user_id, type, $1 FROM ( + SELECT N.user_id, N.type, 1 as ordering + FROM edit_comments EC + JOIN edits E ON EC.edit_id = E.id + JOIN user_notifications N ON E.user_id = N.user_id AND N.type = 'COMMENT_OWN_EDIT' + WHERE EC.id = $1 + UNION + SELECT N.user_id, N.type, 2 as ordering + FROM edit_comments EC + JOIN edits E ON EC.edit_id = E.id + JOIN edit_comments EO ON EO.edit_id = E.id + JOIN user_notifications N ON EO.user_id = N.user_id AND N.type = 'COMMENT_COMMENTED_EDIT' + WHERE EO.user_id != E.user_id AND EO.user_id != EC.user_id AND EC.id = $1 + UNION + SELECT N.user_id, N.type, 3 as ordering + FROM edit_comments EC + JOIN edits E ON EC.edit_id = E.id + JOIN edit_votes EV ON EV.edit_id = E.id + JOIN user_notifications N ON EV.user_id = N.user_id AND N.type = 'COMMENT_VOTED_EDIT' + WHERE EV.vote != 'ABSTAIN' AND EV.user_id != E.user_id AND EV.user_id != EC.user_id AND EC.id = $1 + ) notifications + ORDER BY user_id, ordering ASC ` err := qb.dbi.RawExec(query, args) return err