Add QueryRoomReceipts to roomserver

This commit is contained in:
Till Faelligen 2020-10-13 17:34:11 +02:00
parent 38de251d9f
commit 0815809634
4 changed files with 47 additions and 0 deletions

View file

@ -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)
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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)
}