Skip to content

Commit

Permalink
Fix edit comment notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
InfiniteStash committed Jan 3, 2025
1 parent fe54e8b commit cc6fbc1
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions pkg/sqlx/querybuilder_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cc6fbc1

Please sign in to comment.