- 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"`
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
}
// TODO: easier/nicer creation of receipt EDUs
content := map[string]interface{}{}
content[receipt.RoomID] = map[string]interface{}{
"m.read": map[string]interface{}{
receipt.UserID: userData{
Data: struct {
Ts gomatrixserverlib.Timestamp `json:"ts"`
}{receipt.Timestamp},
EventIds: []string{receipt.EventID},
content := map[string]api.FederationReceiptMRead{}
content[receipt.RoomID] = api.FederationReceiptMRead{
User: map[string]api.FederationReceiptData{
receipt.UserID: {
Data: api.ReceiptTS{
TS: receipt.Timestamp,
},
EventIDs: []string{receipt.EventID},
},
},
}

View file

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