Skip to content

Commit 2f0cdc4

Browse files
authored
ntf server: fix returned last notifications (#1530)
1 parent 0a3d014 commit 2f0cdc4

File tree

1 file changed

+7
-3
lines changed
  • src/Simplex/Messaging/Notifications/Server/Store

1 file changed

+7
-3
lines changed

src/Simplex/Messaging/Notifications/Server/Store/Postgres.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,15 @@ addTokenLastNtf st newNtf =
579579
sent_at = EXCLUDED.sent_at,
580580
nmsg_nonce = EXCLUDED.nmsg_nonce,
581581
nmsg_data = EXCLUDED.nmsg_data
582+
RETURNING subscription_id, sent_at, nmsg_nonce, nmsg_data
582583
),
583584
last AS (
584-
SELECT token_ntf_id, subscription_id, sent_at, nmsg_nonce, nmsg_data
585+
SELECT subscription_id, sent_at, nmsg_nonce, nmsg_data
585586
FROM last_notifications
586-
WHERE token_id = ?
587+
WHERE token_id = ? AND subscription_id != (SELECT subscription_id FROM new)
588+
UNION
589+
SELECT subscription_id, sent_at, nmsg_nonce, nmsg_data
590+
FROM new
587591
ORDER BY sent_at DESC
588592
LIMIT ?
589593
),
@@ -597,7 +601,7 @@ addTokenLastNtf st newNtf =
597601
FROM last l
598602
JOIN subscriptions s ON s.subscription_id = l.subscription_id
599603
JOIN smp_servers p ON p.smp_server_id = s.smp_server_id
600-
ORDER BY token_ntf_id DESC
604+
ORDER BY sent_at ASC
601605
|]
602606
(tId, sId, systemToUTCTime ntfTs, nmsgNonce, Binary encNMsgMeta, tId, maxNtfs, tId)
603607
let lastNtfs = fromMaybe (newNtf :| []) (L.nonEmpty lastNtfs_)

0 commit comments

Comments
 (0)