dendrite/clientapi/routing/multiroom.go
PiotrKozimor 369890c5d1
Multiroom feature (#45)
* Multiroom feature

* Run multiroom visibility expiration conditionally

Remove SQLite and go 1.18 for tests matrixes

* Remove sqlite from unit tests

* Fix linter errors

* Do not build with go1.18

* Do not run upgrade tests

* Fix dendrite workflow

* Add forgotten content and timestamp fields to multiroom in sync response

* Fix syncapi multiroom unit tests

* Review adjustments in queries and naming

* Remove no longer maintained linters from golangci-lint configuration

* Document sqlc code generation
2022-10-31 12:52:27 +01:00

49 lines
1.2 KiB
Go

package routing
import (
"io"
"net/http"
"github.com/matrix-org/dendrite/clientapi/jsonerror"
"github.com/matrix-org/dendrite/clientapi/producers"
"github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
log "github.com/sirupsen/logrus"
)
func PostMultiroom(
req *http.Request,
device *api.Device,
producer *producers.SyncAPIProducer,
dataType string,
) util.JSONResponse {
b, err := io.ReadAll(req.Body)
if err != nil {
log.WithError(err).Errorf("failed to read request body")
return util.JSONResponse{
Code: http.StatusInternalServerError,
JSON: jsonerror.InternalServerError(),
}
}
canonicalB, err := gomatrixserverlib.CanonicalJSON(b)
if err != nil {
return util.JSONResponse{
Code: http.StatusBadRequest,
JSON: jsonerror.BadJSON("The request body is not valid canonical JSON." + err.Error()),
}
}
err = producer.SendMultiroom(req.Context(), device.UserID, dataType, canonicalB)
if err != nil {
log.WithError(err).Errorf("failed to send multiroomcast")
return util.JSONResponse{
Code: http.StatusInternalServerError,
JSON: jsonerror.InternalServerError(),
}
}
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct{}{},
}
}