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 == "" {
|
||||
respMakeJoin.RoomVersion = gomatrixserverlib.RoomVersionV1
|
||||
}
|
||||
if _, err := respMakeJoin.RoomVersion.EventFormat(); err != nil {
|
||||
if _, err = respMakeJoin.RoomVersion.EventFormat(); err != nil {
|
||||
return &util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnsupportedRoomVersion(
|
||||
|
|
|
|||
|
|
@ -102,17 +102,6 @@ func AddPrevEventsToEvent(
|
|||
|
||||
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)
|
||||
|
||||
for i := range queryRes.StateEvents {
|
||||
|
|
@ -126,15 +115,22 @@ func AddPrevEventsToEvent(
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch eventFormat {
|
||||
case gomatrixserverlib.EventFormatV1:
|
||||
builder.AuthEvents = refs
|
||||
builder.PrevEvents = queryRes.LatestEvents
|
||||
case gomatrixserverlib.EventFormatV2:
|
||||
v2Refs := []string{}
|
||||
v2AuthRefs := []string{}
|
||||
v2PrevRefs := []string{}
|
||||
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
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
"github.com/matrix-org/dendrite/clientapi/producers"
|
||||
"github.com/matrix-org/dendrite/common/config"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
|
@ -35,10 +36,19 @@ func Invite(
|
|||
producer *producers.RoomserverProducer,
|
||||
keys gomatrixserverlib.KeyRing,
|
||||
) 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.
|
||||
var event gomatrixserverlib.Event
|
||||
if err := json.Unmarshal(request.Content(), &event); err != nil {
|
||||
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
|
@ -110,8 +109,9 @@ func SendLeave(
|
|||
}
|
||||
}
|
||||
|
||||
var event gomatrixserverlib.Event
|
||||
if err := json.Unmarshal(request.Content(), &event); err != nil {
|
||||
// Decode the event JSON from the request.
|
||||
event, err := gomatrixserverlib.NewEventFromUntrustedJSON(request.Content(), verRes.RoomVersion)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()),
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func Send(
|
|||
}
|
||||
|
||||
var txnEvents struct {
|
||||
events []json.RawMessage `json:"events"`
|
||||
Events []json.RawMessage `json:"events"`
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(request.Content(), &txnEvents); err != nil {
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ func ExchangeThirdPartyInvite(
|
|||
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
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{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||
|
|
|
|||
Loading…
Reference in a new issue