From eab8cba4bb37491d5c3b497b98faa7029e7b7300 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Tue, 4 Feb 2025 18:52:57 +0200 Subject: Refactored the way notifications work on the server-side, next commit fixes the client to use this new system --- query/notifications.sql | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'query') diff --git a/query/notifications.sql b/query/notifications.sql index 5522fe8..5dd4d5a 100644 --- a/query/notifications.sql +++ b/query/notifications.sql @@ -1,14 +1,7 @@ --- name: GetNotifications :many -WITH entries(source, lastId) AS ( - VALUES - ('source1', 12345), - ('source2', 54321) -) -SELECT - e.source, - CASE WHEN COUNT(m.id) > 0 THEN 1 ELSE 0 END AS hasNotif, - COALESCE(SUM(CASE WHEN m.ping = ? THEN 1 ELSE 0 END), 0) AS pings -FROM entries e -LEFT JOIN messages m ON m.id > e.lastId - AND (m.s1 = e.source OR m.s2 = e.source OR m.s3 = e.source) -GROUP BY e.source, e.lastId; +-- name: SetLastReadMessage :exec +INSERT INTO last_read_messages ( + user_id, source_id, last_read +) VALUES (?, ?, ?) +ON CONFLICT DO +UPDATE SET last_read = EXCLUDED.last_read +WHERE user_id = EXCLUDED.user_id AND source_id = EXCLUDED.source_id; -- cgit v1.3.1