mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Lint tweaks
This commit is contained in:
parent
b5a53546c7
commit
c12b493b7a
|
|
@ -331,7 +331,7 @@ func (r joinRoomReq) joinRoomUsingServer(roomID string, server gomatrixserverlib
|
||||||
if respMakeJoin.RoomVersion == "" {
|
if respMakeJoin.RoomVersion == "" {
|
||||||
respMakeJoin.RoomVersion = gomatrixserverlib.RoomVersionV1
|
respMakeJoin.RoomVersion = gomatrixserverlib.RoomVersionV1
|
||||||
}
|
}
|
||||||
if _, err := respMakeJoin.RoomVersion.EventFormat(); err != nil {
|
if _, err = respMakeJoin.RoomVersion.EventFormat(); err != nil {
|
||||||
return &util.JSONResponse{
|
return &util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnsupportedRoomVersion(
|
JSON: jsonerror.UnsupportedRoomVersion(
|
||||||
|
|
|
||||||
|
|
@ -102,17 +102,6 @@ func AddPrevEventsToEvent(
|
||||||
|
|
||||||
builder.Depth = queryRes.Depth
|
builder.Depth = queryRes.Depth
|
||||||
|
|
||||||
switch eventFormat {
|
|
||||||
case gomatrixserverlib.EventFormatV1:
|
|
||||||
builder.PrevEvents = queryRes.LatestEvents
|
|
||||||
case gomatrixserverlib.EventFormatV2:
|
|
||||||
v2Refs := []string{}
|
|
||||||
for _, ref := range queryRes.LatestEvents {
|
|
||||||
v2Refs = append(v2Refs, ref.EventID)
|
|
||||||
}
|
|
||||||
builder.PrevEvents = v2Refs
|
|
||||||
}
|
|
||||||
|
|
||||||
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
authEvents := gomatrixserverlib.NewAuthEvents(nil)
|
||||||
|
|
||||||
for i := range queryRes.StateEvents {
|
for i := range queryRes.StateEvents {
|
||||||
|
|
@ -126,15 +115,22 @@ func AddPrevEventsToEvent(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch eventFormat {
|
switch eventFormat {
|
||||||
case gomatrixserverlib.EventFormatV1:
|
case gomatrixserverlib.EventFormatV1:
|
||||||
builder.AuthEvents = refs
|
builder.AuthEvents = refs
|
||||||
|
builder.PrevEvents = queryRes.LatestEvents
|
||||||
case gomatrixserverlib.EventFormatV2:
|
case gomatrixserverlib.EventFormatV2:
|
||||||
v2Refs := []string{}
|
v2AuthRefs := []string{}
|
||||||
|
v2PrevRefs := []string{}
|
||||||
for _, ref := range refs {
|
for _, ref := range refs {
|
||||||
v2Refs = append(v2Refs, ref.EventID)
|
v2AuthRefs = append(v2AuthRefs, ref.EventID)
|
||||||
}
|
}
|
||||||
builder.AuthEvents = v2Refs
|
for _, ref := range queryRes.LatestEvents {
|
||||||
|
v2PrevRefs = append(v2PrevRefs, ref.EventID)
|
||||||
|
}
|
||||||
|
builder.AuthEvents = v2AuthRefs
|
||||||
|
builder.PrevEvents = v2PrevRefs
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||||
"github.com/matrix-org/dendrite/common/config"
|
"github.com/matrix-org/dendrite/common/config"
|
||||||
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
@ -35,10 +36,19 @@ func Invite(
|
||||||
producer *producers.RoomserverProducer,
|
producer *producers.RoomserverProducer,
|
||||||
keys gomatrixserverlib.KeyRing,
|
keys gomatrixserverlib.KeyRing,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
|
// Look up the room version for the room.
|
||||||
|
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||||
|
verRes := api.QueryRoomVersionForRoomResponse{}
|
||||||
|
if err := producer.QueryAPI.QueryRoomVersionForRoom(context.Background(), &verReq, &verRes); err != nil {
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusBadRequest,
|
||||||
|
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Decode the event JSON from the request.
|
// Decode the event JSON from the request.
|
||||||
var event gomatrixserverlib.Event
|
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
|
||||||
if err := json.Unmarshal(request.Content(), &event); err != nil {
|
if err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@
|
||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -110,8 +109,9 @@ func SendLeave(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var event gomatrixserverlib.Event
|
// Decode the event JSON from the request.
|
||||||
if err := json.Unmarshal(request.Content(), &event); err != nil {
|
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
|
||||||
|
if err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ func Send(
|
||||||
}
|
}
|
||||||
|
|
||||||
var txnEvents struct {
|
var txnEvents struct {
|
||||||
events []json.RawMessage `json:"events"`
|
Events []json.RawMessage `json:"events"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal(request.Content(), &txnEvents); err != nil {
|
if err := json.Unmarshal(request.Content(), &txnEvents); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ func ExchangeThirdPartyInvite(
|
||||||
|
|
||||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||||
verRes := api.QueryRoomVersionForRoomResponse{}
|
verRes := api.QueryRoomVersionForRoomResponse{}
|
||||||
if err := queryAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
|
if err = queryAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusBadRequest,
|
Code: http.StatusBadRequest,
|
||||||
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue