mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Generate random message ID
This commit is contained in:
parent
fef9ed2a17
commit
01f2f80154
|
|
@ -16,6 +16,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/Shopify/sarama"
|
"github.com/Shopify/sarama"
|
||||||
"github.com/matrix-org/dendrite/eduserver/api"
|
"github.com/matrix-org/dendrite/eduserver/api"
|
||||||
|
|
@ -106,13 +108,23 @@ func (t *OutputEDUConsumer) onSendToDeviceEvent(msg *sarama.ConsumerMessage) err
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate a random message ID for idempotency
|
||||||
|
chars := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
random := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
|
messageID := make([]byte, 32)
|
||||||
|
for i := range messageID {
|
||||||
|
messageID[i] = chars[random.Intn(len(chars))]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pack the EDU and marshal it
|
||||||
edu := &gomatrixserverlib.EDU{
|
edu := &gomatrixserverlib.EDU{
|
||||||
Type: gomatrixserverlib.MDirectToDevice,
|
Type: gomatrixserverlib.MDirectToDevice,
|
||||||
Origin: string(t.ServerName),
|
Origin: string(t.ServerName),
|
||||||
}
|
}
|
||||||
tdm := gomatrixserverlib.ToDeviceMessage{
|
tdm := gomatrixserverlib.ToDeviceMessage{
|
||||||
Sender: ote.Sender,
|
Sender: ote.Sender,
|
||||||
Type: ote.Type,
|
Type: ote.Type,
|
||||||
|
MessageID: string(messageID),
|
||||||
Messages: map[string]map[string]json.RawMessage{
|
Messages: map[string]map[string]json.RawMessage{
|
||||||
ote.UserID: {
|
ote.UserID: {
|
||||||
ote.DeviceID: ote.Content,
|
ote.DeviceID: ote.Content,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue