[PD1] Logic all done?

This commit is contained in:
Afonso Franco 2024-04-20 00:55:16 +01:00
parent cfe9f3c7b3
commit 4c141bbc6e
Signed by: afonso
SSH key fingerprint: SHA256:aiLbdlPwXKJS5wMnghdtod0SPy8imZjlVvCyUX9DJNk
4 changed files with 31 additions and 34 deletions

View file

@ -63,7 +63,6 @@ func (ds DataStore) GetMessage(toUID string, position int) protocol.Packet {
SELECT fromUID, toUID, subject, body, timestamp
FROM messages
WHERE toUID = ?
AND status = 0
ORDER BY timestamp
LIMIT 1 OFFSET ?
`
@ -81,10 +80,14 @@ func (ds DataStore) GetMessage(toUID string, position int) protocol.Packet {
func (ds DataStore) MarkMessageInQueueAsRead(toUID string, position int) {
query := `
UPDATE messages
SET status = 1
WHERE toUID = ? AND status = 0
ORDER BY timestamp
LIMIT 1 OFFSET ?
SET status = 1
WHERE (fromUID,toUID,timestamp) = (
SELECT fromUID,toUID,timestamp
FROM messages
WHERE toUID = ?
ORDER BY timestamp
LIMIT 1 OFFSET ?
)
`
// Execute the SQL statement