mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Send invite partial state properly
This commit is contained in:
parent
c30b12b5a1
commit
2de420f9c0
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,6 @@ func updateToInviteMembership(
|
|||
// is invited, rather than having to combine multiple streams themselves.
|
||||
onie := api.OutputNewInviteEvent{
|
||||
Event: (*add).Headered(roomVersion),
|
||||
RoomVersion: roomVersion,
|
||||
}
|
||||
updates = append(updates, api.OutputEvent{
|
||||
Type: api.OutputTypeNewInviteEvent,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue