mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Fix ordering of ToDevice messages
This commit is contained in:
parent
a01cbb8600
commit
ef25572d2f
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
"github.com/matrix-org/dendrite/syncapi/storage/tables"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const sendToDeviceSchema = `
|
const sendToDeviceSchema = `
|
||||||
|
|
@ -51,7 +52,7 @@ const selectSendToDeviceMessagesSQL = `
|
||||||
SELECT id, user_id, device_id, content
|
SELECT id, user_id, device_id, content
|
||||||
FROM syncapi_send_to_device
|
FROM syncapi_send_to_device
|
||||||
WHERE user_id = $1 AND device_id = $2 AND id > $3 AND id <= $4
|
WHERE user_id = $1 AND device_id = $2 AND id > $3 AND id <= $4
|
||||||
ORDER BY id DESC
|
ORDER BY id ASC
|
||||||
`
|
`
|
||||||
|
|
||||||
const deleteSendToDeviceMessagesSQL = `
|
const deleteSendToDeviceMessagesSQL = `
|
||||||
|
|
@ -112,17 +113,18 @@ func (s *sendToDeviceStatements) SelectSendToDeviceMessages(
|
||||||
if err = rows.Scan(&id, &userID, &deviceID, &content); err != nil {
|
if err = rows.Scan(&id, &userID, &deviceID, &content); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if id > lastPos {
|
|
||||||
lastPos = id
|
|
||||||
}
|
|
||||||
event := types.SendToDeviceEvent{
|
event := types.SendToDeviceEvent{
|
||||||
ID: id,
|
ID: id,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
DeviceID: deviceID,
|
DeviceID: deviceID,
|
||||||
}
|
}
|
||||||
if err = json.Unmarshal([]byte(content), &event.SendToDeviceEvent); err != nil {
|
if err = json.Unmarshal([]byte(content), &event.SendToDeviceEvent); err != nil {
|
||||||
|
logrus.WithError(err).Errorf("Failed to unmarshal send-to-device message")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if id > lastPos {
|
||||||
|
lastPos = id
|
||||||
|
}
|
||||||
events = append(events, event)
|
events = append(events, event)
|
||||||
}
|
}
|
||||||
if lastPos == 0 {
|
if lastPos == 0 {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ const selectSendToDeviceMessagesSQL = `
|
||||||
SELECT id, user_id, device_id, content
|
SELECT id, user_id, device_id, content
|
||||||
FROM syncapi_send_to_device
|
FROM syncapi_send_to_device
|
||||||
WHERE user_id = $1 AND device_id = $2 AND id > $3 AND id <= $4
|
WHERE user_id = $1 AND device_id = $2 AND id > $3 AND id <= $4
|
||||||
ORDER BY id DESC
|
ORDER BY id ASC
|
||||||
`
|
`
|
||||||
|
|
||||||
const deleteSendToDeviceMessagesSQL = `
|
const deleteSendToDeviceMessagesSQL = `
|
||||||
|
|
@ -120,9 +120,6 @@ func (s *sendToDeviceStatements) SelectSendToDeviceMessages(
|
||||||
logrus.WithError(err).Errorf("Failed to retrieve send-to-device message")
|
logrus.WithError(err).Errorf("Failed to retrieve send-to-device message")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if id > lastPos {
|
|
||||||
lastPos = id
|
|
||||||
}
|
|
||||||
event := types.SendToDeviceEvent{
|
event := types.SendToDeviceEvent{
|
||||||
ID: id,
|
ID: id,
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
|
|
@ -132,6 +129,9 @@ func (s *sendToDeviceStatements) SelectSendToDeviceMessages(
|
||||||
logrus.WithError(err).Errorf("Failed to unmarshal send-to-device message")
|
logrus.WithError(err).Errorf("Failed to unmarshal send-to-device message")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if id > lastPos {
|
||||||
|
lastPos = id
|
||||||
|
}
|
||||||
events = append(events, event)
|
events = append(events, event)
|
||||||
}
|
}
|
||||||
if lastPos == 0 {
|
if lastPos == 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue