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
import (
"encoding/json"
"fmt"
"net/http"
"time"
@ -126,10 +124,6 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
if !syncData.IsEmpty() || hasTimedOut {
logger.WithField("next", syncData.NextBatch).WithField("timed_out", hasTimedOut).Info("Responding")
j, _ := json.MarshalIndent(syncData, "", " ")
fmt.Println(string(j))
return util.JSONResponse{
Code: http.StatusOK,
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.
type InviteResponse struct {
InviteState struct {
Events json.RawMessage `json:"events,omitempty"`
} `json:"invite_state,omitempty"`
Events []json.RawMessage `json:"events"`
} `json:"invite_state"`
}
// NewInviteResponse creates an empty response with initialised arrays.
func NewInviteResponse(ev gomatrixserverlib.HeaderedEvent) *InviteResponse {
res := InviteResponse{}
res.InviteState.Events = []json.RawMessage{}
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 len(unsigned.InviteRoomState) > 0 {
res.InviteState.Events = unsigned.InviteRoomState
}
res.InviteState.Events = append(res.InviteState.Events, unsigned.InviteRoomState...)
}
return &res
}