- Fix a bug when creating client receipts

- Use concrete types instead of interface{}
This commit is contained in:
Till Faelligen 2020-10-18 11:19:47 +02:00
parent 247da6d862
commit 1a10566f28
3 changed files with 33 additions and 19 deletions

View file

@ -66,3 +66,22 @@ type OutputReceiptEvent struct {
Type string `json:"type"` Type string `json:"type"`
Timestamp gomatrixserverlib.Timestamp `json:"timestamp"` Timestamp gomatrixserverlib.Timestamp `json:"timestamp"`
} }
// Helper structs for receipts json creation
type ReceiptMRead struct {
User map[string]ReceiptTS `json:"m.read"`
}
type ReceiptTS struct {
TS gomatrixserverlib.Timestamp `json:"ts"`
}
// FederationSender output
type FederationReceiptMRead struct {
User map[string]FederationReceiptData `json:"m.read"`
}
type FederationReceiptData struct {
Data ReceiptTS `json:"data"`
EventIDs []string `json:"event_ids"`
}

View file

@ -228,15 +228,14 @@ func (t *OutputEDUConsumer) onReceiptEvent(msg *sarama.ConsumerMessage) error {
names[i] = joined[i].ServerName names[i] = joined[i].ServerName
} }
// TODO: easier/nicer creation of receipt EDUs content := map[string]api.FederationReceiptMRead{}
content := map[string]interface{}{} content[receipt.RoomID] = api.FederationReceiptMRead{
content[receipt.RoomID] = map[string]interface{}{ User: map[string]api.FederationReceiptData{
"m.read": map[string]interface{}{ receipt.UserID: {
receipt.UserID: userData{ Data: api.ReceiptTS{
Data: struct { TS: receipt.Timestamp,
Ts gomatrixserverlib.Timestamp `json:"ts"` },
}{receipt.Timestamp}, EventIDs: []string{receipt.EventID},
EventIds: []string{receipt.EventID},
}, },
}, },
} }

View file

@ -599,17 +599,13 @@ func (d *Database) addReceiptDeltaToResponse(
Type: gomatrixserverlib.MReceipt, Type: gomatrixserverlib.MReceipt,
RoomID: roomID, RoomID: roomID,
} }
content := map[string]interface{}{} content := make(map[string]eduAPI.ReceiptMRead)
for _, receipt := range receipts { read := eduAPI.ReceiptMRead{
content[receipt.EventID] = map[string]interface{}{ User: make(map[string]eduAPI.ReceiptTS),
"m.read": map[string]interface{}{
receipt.UserID: struct {
gomatrixserverlib.Timestamp `json:"ts"`
}{
receipt.Timestamp,
},
},
} }
for _, receipt := range receipts {
read.User[receipt.UserID] = eduAPI.ReceiptTS{receipt.Timestamp}
content[receipt.EventID] = read
} }
ev.Content, err = json.Marshal(content) ev.Content, err = json.Marshal(content)
if err != nil { if err != nil {