summaryrefslogtreecommitdiff
path: root/query
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2025-02-04 18:52:57 +0200
committerKyren223 <Kyren223@proton.me>2025-02-04 18:52:57 +0200
commiteab8cba4bb37491d5c3b497b98faa7029e7b7300 (patch)
tree15f9994c423d18f0492f97c43bf71a0793e1e6a4 /query
parent42a1ee12c1e64955e6ddd38c34b122c7c10a93f2 (diff)
Refactored the way notifications work on the server-side, next commit
fixes the client to use this new system
Diffstat (limited to 'query')
-rw-r--r--query/notifications.sql21
1 files changed, 7 insertions, 14 deletions
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;