mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-08 07:23:10 -06:00
Cleanup & fix invite response creation
This commit is contained in:
parent
b593f29fce
commit
8ee7b9de3c
|
|
@ -534,26 +534,14 @@ type InviteResponse struct {
|
||||||
|
|
||||||
// NewInviteResponse creates an empty response with initialised arrays.
|
// NewInviteResponse creates an empty response with initialised arrays.
|
||||||
func NewInviteResponse(ctx context.Context, rsAPI api.QuerySenderIDAPI, event *types.HeaderedEvent, userID spec.UserID, stateKey *string, eventFormat synctypes.ClientEventFormat) (*InviteResponse, error) {
|
func NewInviteResponse(ctx context.Context, rsAPI api.QuerySenderIDAPI, event *types.HeaderedEvent, userID spec.UserID, stateKey *string, eventFormat synctypes.ClientEventFormat) (*InviteResponse, error) {
|
||||||
res, err := updateInviteRoomState(ctx, rsAPI, event, userID, stateKey, eventFormat)
|
res := InviteResponse{}
|
||||||
if err != nil {
|
res.InviteState.Events = []json.RawMessage{}
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return res, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func updateInviteRoomState(ctx context.Context, rsAPI api.QuerySenderIDAPI, event *types.HeaderedEvent, inviterUserID spec.UserID, stateKey *string, eventFormat synctypes.ClientEventFormat) (*InviteResponse, error) {
|
|
||||||
inv := InviteResponse{}
|
|
||||||
inv.InviteState.Events = []json.RawMessage{}
|
|
||||||
|
|
||||||
// First see if there's invite_room_state in the unsigned key of the invite.
|
// First see if there's invite_room_state in the unsigned key of the invite.
|
||||||
// If there is then unmarshal it into the response. This will contain the
|
// If there is then unmarshal it into the response. This will contain the
|
||||||
// partial room state such as join rules, room name etc.
|
// partial room state such as join rules, room name etc.
|
||||||
if inviteRoomState := gjson.GetBytes(event.Unsigned(), "invite_room_state"); inviteRoomState.Exists() {
|
if inviteRoomState := gjson.GetBytes(event.Unsigned(), "invite_room_state"); inviteRoomState.Exists() {
|
||||||
err := json.Unmarshal([]byte(inviteRoomState.Raw), &inv.InviteState.Events)
|
_ = json.Unmarshal([]byte(inviteRoomState.Raw), &res.InviteState.Events)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear unsigned so it doesn't have pseudoIDs converted during ToClientEvent
|
// Clear unsigned so it doesn't have pseudoIDs converted during ToClientEvent
|
||||||
|
|
@ -566,7 +554,7 @@ func updateInviteRoomState(ctx context.Context, rsAPI api.QuerySenderIDAPI, even
|
||||||
// This is needed for clients to work out *who* sent the invite.
|
// This is needed for clients to work out *who* sent the invite.
|
||||||
inviteEvent, err := synctypes.ToClientEvent(eventNoUnsigned, eventFormat, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
inviteEvent, err := synctypes.ToClientEvent(eventNoUnsigned, eventFormat, func(roomID spec.RoomID, senderID spec.SenderID) (*spec.UserID, error) {
|
||||||
return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
|
return rsAPI.QueryUserIDForSender(ctx, roomID, senderID)
|
||||||
}, inviterUserID.String(), stateKey)
|
}, userID.String(), stateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -575,10 +563,10 @@ func updateInviteRoomState(ctx context.Context, rsAPI api.QuerySenderIDAPI, even
|
||||||
inviteEvent.Unsigned = nil
|
inviteEvent.Unsigned = nil
|
||||||
|
|
||||||
if ev, err := json.Marshal(*inviteEvent); err == nil {
|
if ev, err := json.Marshal(*inviteEvent); err == nil {
|
||||||
inv.InviteState.Events = append(inv.InviteState.Events, ev)
|
res.InviteState.Events = append(res.InviteState.Events, ev)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &inv, nil
|
return &res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeaveResponse represents a /sync response for a room which is under the 'leave' key.
|
// LeaveResponse represents a /sync response for a room which is under the 'leave' key.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue