Send invite partial state properly

This commit is contained in:
Neil Alexander 2020-04-22 17:06:26 +01:00
parent c30b12b5a1
commit 2de420f9c0
7 changed files with 23 additions and 18 deletions

View file

@ -116,8 +116,6 @@ type OutputNewRoomEvent struct {
// Invite events can be received outside of an existing room so have to be
// tracked separately from the room events themselves.
type OutputNewInviteEvent struct {
// The room version of the invited room.
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
// The "m.room.member" invite event.
Event gomatrixserverlib.HeaderedEvent `json:"event"`
}

View file

@ -143,8 +143,7 @@ func updateToInviteMembership(
// consider a single stream of events when determining whether a user
// is invited, rather than having to combine multiple streams themselves.
onie := api.OutputNewInviteEvent{
Event: (*add).Headered(roomVersion),
RoomVersion: roomVersion,
Event: (*add).Headered(roomVersion),
}
updates = append(updates, api.OutputEvent{
Type: api.OutputTypeNewInviteEvent,

View file

@ -17,6 +17,7 @@ package consumers
import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/Shopify/sarama"
@ -154,6 +155,10 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
func (s *OutputRoomEventConsumer) onNewInviteEvent(
ctx context.Context, msg api.OutputNewInviteEvent,
) error {
stateKey := msg.Event.StateKey()
if stateKey == nil {
return errors.New("invite has no state key")
}
pduPos, err := s.db.AddInviteEvent(ctx, msg.Event)
if err != nil {
// panic rather than continue with an inconsistent database
@ -164,7 +169,7 @@ func (s *OutputRoomEventConsumer) onNewInviteEvent(
}).Panicf("roomserver output log: write invite failure")
return nil
}
s.notifier.OnNewEvent(&msg.Event, "", nil, types.PaginationToken{PDUPosition: pduPos})
s.notifier.OnNewEvent(&msg.Event, "", []string{*stateKey}, types.PaginationToken{PDUPosition: pduPos})
return nil
}

View file

@ -752,11 +752,7 @@ func (d *SyncServerDatasource) addInvitesToResponse(
return err
}
for roomID, inviteEvent := range invites {
ir := types.NewInviteResponse()
ir.InviteState.Events = gomatrixserverlib.ToClientEvents(
[]gomatrixserverlib.Event{inviteEvent.Event}, gomatrixserverlib.FormatSync,
)
// TODO: add the invite state from the invite event.
ir := types.NewInviteResponse(inviteEvent)
res.Rooms.Invite[roomID] = *ir
}
return nil

View file

@ -799,11 +799,7 @@ func (d *SyncServerDatasource) addInvitesToResponse(
return err
}
for roomID, inviteEvent := range invites {
ir := types.NewInviteResponse()
ir.InviteState.Events = gomatrixserverlib.HeaderedToClientEvents(
[]gomatrixserverlib.HeaderedEvent{inviteEvent}, gomatrixserverlib.FormatSync,
)
// TODO: add the invite state from the invite event.
ir := types.NewInviteResponse(inviteEvent)
res.Rooms.Invite[roomID] = *ir
}
return nil

View file

@ -15,6 +15,8 @@
package sync
import (
"encoding/json"
"fmt"
"net/http"
"time"
@ -124,6 +126,10 @@ 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,14 +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 []gomatrixserverlib.ClientEvent `json:"events"`
Events json.RawMessage `json:"events"`
} `json:"invite_state"`
}
// NewInviteResponse creates an empty response with initialised arrays.
func NewInviteResponse() *InviteResponse {
func NewInviteResponse(ev gomatrixserverlib.HeaderedEvent) *InviteResponse {
res := InviteResponse{}
res.InviteState.Events = make([]gomatrixserverlib.ClientEvent, 0)
var unsigned struct {
InviteRoomState json.RawMessage `json:"invite_room_state"`
}
if err := json.Unmarshal(ev.Unsigned(), &unsigned); err == nil {
res.InviteState.Events = unsigned.InviteRoomState
}
return &res
}