From 1a10566f289a3a466928a644df080a5881983617 Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Sun, 18 Oct 2020 11:19:47 +0200 Subject: [PATCH] - Fix a bug when creating client receipts - Use concrete types instead of interface{} --- eduserver/api/output.go | 19 +++++++++++++++++++ federationsender/consumers/eduserver.go | 17 ++++++++--------- syncapi/storage/shared/syncserver.go | 16 ++++++---------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/eduserver/api/output.go b/eduserver/api/output.go index b97126582..650458a29 100644 --- a/eduserver/api/output.go +++ b/eduserver/api/output.go @@ -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"` +} diff --git a/federationsender/consumers/eduserver.go b/federationsender/consumers/eduserver.go index 65500f808..3956abde5 100644 --- a/federationsender/consumers/eduserver.go +++ b/federationsender/consumers/eduserver.go @@ -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}, }, }, } diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index 9c18258ad..c93ff3306 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -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 {