From 08158096347c796b5f2558ee879dcc78f2311e8e Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Tue, 13 Oct 2020 17:34:11 +0200 Subject: [PATCH] Add QueryRoomReceipts to roomserver --- roomserver/internal/api.go | 8 ++++++++ roomserver/internal/perform/perform_receipt.go | 13 +++++++++++++ roomserver/internal/query/query.go | 13 +++++++++++++ roomserver/inthttp/client.go | 13 +++++++++++++ 4 files changed, 47 insertions(+) diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go index 0b5a863a2..895c53de4 100644 --- a/roomserver/internal/api.go +++ b/roomserver/internal/api.go @@ -155,3 +155,11 @@ func (r *RoomserverInternalAPI) PerformUserReceiptUpdate( ) error { return r.Receipter.PerformUserReceiptUpdate(ctx, req, res) } + +func (r *RoomserverInternalAPI) QueryRoomReceipts( + ctx context.Context, + req *api.QueryRoomReceiptRequest, + res *api.QueryRoomReceiptResponse, +) error { + return r.Receipter.QueryRoomReceipts(ctx, req, res) +} diff --git a/roomserver/internal/perform/perform_receipt.go b/roomserver/internal/perform/perform_receipt.go index 9f81c177f..afb70e5fa 100644 --- a/roomserver/internal/perform/perform_receipt.go +++ b/roomserver/internal/perform/perform_receipt.go @@ -14,3 +14,16 @@ type Receipter struct { func (r *Receipter) PerformUserReceiptUpdate(ctx context.Context, req *api.PerformUserReceiptUpdateRequest, res *api.PerformUserReceiptUpdateResponse) error { return r.DB.StoreReceipt(ctx, req.RoomID, req.ReceiptType, req.UserID, req.EventID) } + +func (r *Receipter) QueryRoomReceipts( + ctx context.Context, + req *api.QueryRoomReceiptRequest, + res *api.QueryRoomReceiptResponse, +) error { + receipts, err := r.DB.GetRoomReceipts(ctx, req.RoomID, req.TS) + if err != nil { + return err + } + res.Receipts = receipts + return nil +} diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index 810511505..60bee385d 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -685,3 +685,16 @@ func (r *Queryer) QueryServerBannedFromRoom(ctx context.Context, req *api.QueryS res.Banned = r.ServerACLs.IsServerBannedFromRoom(req.ServerName, req.RoomID) return nil } + +func (r *Queryer) QueryRoomReceipts( + ctx context.Context, + req *api.QueryRoomReceiptRequest, + res *api.QueryRoomReceiptResponse, +) error { + receipts, err := r.DB.GetRoomReceipts(ctx, req.RoomID, req.TS) + if err != nil { + return err + } + res.Receipts = receipts + return nil +} diff --git a/roomserver/inthttp/client.go b/roomserver/inthttp/client.go index 4dadb6c5c..00f7d83e2 100644 --- a/roomserver/inthttp/client.go +++ b/roomserver/inthttp/client.go @@ -53,6 +53,7 @@ const ( RoomserverQuerySharedUsersPath = "/roomserver/querySharedUsers" RoomserverQueryKnownUsersPath = "/roomserver/queryKnownUsers" RoomserverQueryServerBannedFromRoomPath = "/roomserver/queryServerBannedFromRoom" + RoomserverQueryRoomReceiptsPath = "/roomserver/queryRoomReceipts" ) type httpRoomserverInternalAPI struct { @@ -505,3 +506,15 @@ func (h *httpRoomserverInternalAPI) PerformUserReceiptUpdate( apiURL := h.roomserverURL + RoomserverPerformReceiptUpdatePath return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) } + +func (h *httpRoomserverInternalAPI) QueryRoomReceipts( + ctx context.Context, + req *api.QueryRoomReceiptRequest, + res *api.QueryRoomReceiptResponse, +) error { + span, ctx := opentracing.StartSpanFromContext(ctx, "RoomserverQueryRoomReceiptsPath") + defer span.Finish() + + apiURL := h.roomserverURL + RoomserverQueryRoomReceiptsPath + return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res) +}