mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-30 04:52:46 +00:00
More invite support (#979)
* Update gomatixserverlib * Try to build invite stripped state if not given to us * SendInvite improvements * Transpose invite_room_state into invite_state.events for sync API * Remove syncapi debugging output * Use RespInviteV2 * Update gomatrixserverlib * Send the invite event as a normal roomserver event too, for incorporating into room (should this be done by the roomserver automatically for invite inputs?) * Federation sender use invite_room_state, room server try to insert membership state * Check supported room versions on the invite endpoint * Prevent roomserver query API from trying to handle requests for stub rooms * Adding a nolint * Replace IsRoomStub with RoomNIDExcludingStubs, fix query API to use that instead * Review comments
This commit is contained in:
parent
be558f02aa
commit
3ab8ebf6b8
16 changed files with 175 additions and 77 deletions
|
@ -106,12 +106,15 @@ func (c *RoomserverProducer) SendInputRoomEvents(
|
|||
func (c *RoomserverProducer) SendInvite(
|
||||
ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent,
|
||||
inviteRoomState []gomatrixserverlib.InviteV2StrippedState,
|
||||
sendAsServer gomatrixserverlib.ServerName, txnID *api.TransactionID,
|
||||
) error {
|
||||
request := api.InputRoomEventsRequest{
|
||||
InputInviteEvents: []api.InputInviteEvent{{
|
||||
Event: inviteEvent,
|
||||
InviteRoomState: inviteRoomState,
|
||||
RoomVersion: inviteEvent.RoomVersion,
|
||||
SendAsServer: string(sendAsServer),
|
||||
TransactionID: txnID,
|
||||
}},
|
||||
}
|
||||
var response api.InputRoomEventsResponse
|
||||
|
|
|
@ -40,6 +40,8 @@ var errMissingUserID = errors.New("'user_id' must be supplied")
|
|||
|
||||
// SendMembership implements PUT /rooms/{roomID}/(join|kick|ban|unban|leave|invite)
|
||||
// by building a m.room.member event then sending it to the room server
|
||||
// TODO: Can we improve the cyclo count here? Separate code paths for invites?
|
||||
// nolint:gocyclo
|
||||
func SendMembership(
|
||||
req *http.Request, accountDB accounts.Database, device *authtypes.Device,
|
||||
roomID string, membership string, cfg *config.Dendrite,
|
||||
|
@ -104,23 +106,39 @@ func SendMembership(
|
|||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
if _, err := producer.SendEvents(
|
||||
req.Context(),
|
||||
[]gomatrixserverlib.HeaderedEvent{(*event).Headered(verRes.RoomVersion)},
|
||||
cfg.Matrix.ServerName,
|
||||
nil,
|
||||
); err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
var returnData interface{} = struct{}{}
|
||||
|
||||
// The join membership requires the room id to be sent in the response
|
||||
if membership == gomatrixserverlib.Join {
|
||||
switch membership {
|
||||
case gomatrixserverlib.Invite:
|
||||
// Invites need to be handled specially
|
||||
err = producer.SendInvite(
|
||||
req.Context(),
|
||||
event.Headered(verRes.RoomVersion),
|
||||
nil, // ask the roomserver to draw up invite room state for us
|
||||
cfg.Matrix.ServerName,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("producer.SendInvite failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
case gomatrixserverlib.Join:
|
||||
// The join membership requires the room id to be sent in the response
|
||||
returnData = struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}{roomID}
|
||||
default:
|
||||
}
|
||||
|
||||
_, err = producer.SendEvents(
|
||||
req.Context(),
|
||||
[]gomatrixserverlib.HeaderedEvent{event.Headered(verRes.RoomVersion)},
|
||||
cfg.Matrix.ServerName,
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("producer.SendEvents failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue