mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Transpose invite_room_state into invite_state.events for sync API
This commit is contained in:
parent
15a1db7062
commit
e385a5540e
1
go.mod
1
go.mod
|
|
@ -27,6 +27,7 @@ require (
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/prometheus/client_golang v1.4.1
|
github.com/prometheus/client_golang v1.4.1
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.4.2
|
||||||
|
github.com/tidwall/gjson v1.6.0
|
||||||
github.com/uber/jaeger-client-go v2.15.0+incompatible
|
github.com/uber/jaeger-client-go v2.15.0+incompatible
|
||||||
github.com/uber/jaeger-lib v1.5.0
|
github.com/uber/jaeger-lib v1.5.0
|
||||||
go.uber.org/atomic v1.4.0
|
go.uber.org/atomic v1.4.0
|
||||||
|
|
|
||||||
|
|
@ -752,11 +752,7 @@ func (d *SyncServerDatasource) addInvitesToResponse(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for roomID, inviteEvent := range invites {
|
for roomID, inviteEvent := range invites {
|
||||||
ir := types.NewInviteResponse()
|
ir := types.NewInviteResponse(inviteEvent)
|
||||||
ir.InviteState.Events = gomatrixserverlib.ToClientEvents(
|
|
||||||
[]gomatrixserverlib.Event{inviteEvent.Event}, gomatrixserverlib.FormatSync,
|
|
||||||
)
|
|
||||||
// TODO: add the invite state from the invite event.
|
|
||||||
res.Rooms.Invite[roomID] = *ir
|
res.Rooms.Invite[roomID] = *ir
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -799,11 +799,7 @@ func (d *SyncServerDatasource) addInvitesToResponse(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for roomID, inviteEvent := range invites {
|
for roomID, inviteEvent := range invites {
|
||||||
ir := types.NewInviteResponse()
|
ir := types.NewInviteResponse(inviteEvent)
|
||||||
ir.InviteState.Events = gomatrixserverlib.HeaderedToClientEvents(
|
|
||||||
[]gomatrixserverlib.HeaderedEvent{inviteEvent}, gomatrixserverlib.FormatSync,
|
|
||||||
)
|
|
||||||
// TODO: add the invite state from the invite event.
|
|
||||||
res.Rooms.Invite[roomID] = *ir
|
res.Rooms.Invite[roomID] = *ir
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@
|
||||||
package sync
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -69,6 +71,10 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
|
||||||
logger.WithError(err).Error("rp.currentSyncForUser failed")
|
logger.WithError(err).Error("rp.currentSyncForUser failed")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
j, _ := json.MarshalIndent(syncData, "", " ")
|
||||||
|
fmt.Println("Sync response:", string(j))
|
||||||
|
|
||||||
logger.WithField("next", syncData.NextBatch).Info("Responding immediately")
|
logger.WithField("next", syncData.NextBatch).Info("Responding immediately")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
|
|
@ -123,6 +129,9 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
|
||||||
}
|
}
|
||||||
|
|
||||||
if !syncData.IsEmpty() || hasTimedOut {
|
if !syncData.IsEmpty() || hasTimedOut {
|
||||||
|
j, _ := json.MarshalIndent(syncData, "", " ")
|
||||||
|
fmt.Println("Sync response:", string(j))
|
||||||
|
|
||||||
logger.WithField("next", syncData.NextBatch).WithField("timed_out", hasTimedOut).Info("Responding")
|
logger.WithField("next", syncData.NextBatch).WithField("timed_out", hasTimedOut).Info("Responding")
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -247,14 +248,17 @@ func NewJoinResponse() *JoinResponse {
|
||||||
// InviteResponse represents a /sync response for a room which is under the 'invite' key.
|
// InviteResponse represents a /sync response for a room which is under the 'invite' key.
|
||||||
type InviteResponse struct {
|
type InviteResponse struct {
|
||||||
InviteState struct {
|
InviteState struct {
|
||||||
Events []gomatrixserverlib.ClientEvent `json:"events"`
|
Events json.RawMessage `json:"events"`
|
||||||
} `json:"invite_state"`
|
} `json:"invite_state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInviteResponse creates an empty response with initialised arrays.
|
// NewInviteResponse creates an empty response with initialised arrays.
|
||||||
func NewInviteResponse() *InviteResponse {
|
func NewInviteResponse(event gomatrixserverlib.HeaderedEvent) *InviteResponse {
|
||||||
res := InviteResponse{}
|
res := InviteResponse{}
|
||||||
res.InviteState.Events = make([]gomatrixserverlib.ClientEvent, 0)
|
res.InviteState.Events = json.RawMessage{'[', ']'}
|
||||||
|
if inviteRoomState := gjson.GetBytes(event.Unsigned(), "invite_room_state"); inviteRoomState.Exists() {
|
||||||
|
res.InviteState.Events = json.RawMessage(inviteRoomState.Raw)
|
||||||
|
}
|
||||||
return &res
|
return &res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue