Try this again

This commit is contained in:
Neil Alexander 2020-04-22 18:02:44 +01:00
parent 8123a76117
commit adc7f36d38
2 changed files with 5 additions and 12 deletions

View file

@ -15,8 +15,6 @@
package sync package sync
import ( import (
"encoding/json"
"fmt"
"net/http" "net/http"
"time" "time"
@ -126,10 +124,6 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
if !syncData.IsEmpty() || hasTimedOut { if !syncData.IsEmpty() || hasTimedOut {
logger.WithField("next", syncData.NextBatch).WithField("timed_out", hasTimedOut).Info("Responding") logger.WithField("next", syncData.NextBatch).WithField("timed_out", hasTimedOut).Info("Responding")
j, _ := json.MarshalIndent(syncData, "", " ")
fmt.Println(string(j))
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusOK, Code: http.StatusOK,
JSON: syncData, JSON: syncData,

View file

@ -247,20 +247,19 @@ 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 json.RawMessage `json:"events,omitempty"` Events []json.RawMessage `json:"events"`
} `json:"invite_state,omitempty"` } `json:"invite_state"`
} }
// NewInviteResponse creates an empty response with initialised arrays. // NewInviteResponse creates an empty response with initialised arrays.
func NewInviteResponse(ev gomatrixserverlib.HeaderedEvent) *InviteResponse { func NewInviteResponse(ev gomatrixserverlib.HeaderedEvent) *InviteResponse {
res := InviteResponse{} res := InviteResponse{}
res.InviteState.Events = []json.RawMessage{}
var unsigned struct { var unsigned struct {
InviteRoomState json.RawMessage `json:"invite_room_state"` InviteRoomState []json.RawMessage `json:"invite_room_state"`
} }
if err := json.Unmarshal(ev.Unsigned(), &unsigned); err == nil { if err := json.Unmarshal(ev.Unsigned(), &unsigned); err == nil {
if len(unsigned.InviteRoomState) > 0 { res.InviteState.Events = append(res.InviteState.Events, unsigned.InviteRoomState...)
res.InviteState.Events = unsigned.InviteRoomState
}
} }
return &res return &res
} }