mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 05:12:46 +00:00
Synchronous invites (#1273)
* Refactor invites to be synchronous * Fix synchronous invites * Fix client API return type for send invite error * Linter * Restore PerformError on rsAPI.PerformInvite * Update sytest-whitelist * Don't override PerformError with normal errors * Fix error passing * Un-whitelist a couple of tests * Update sytest-whitelist * Try to handle multiple invite rejections better * nolint * Update gomatrixserverlib * Fix /v1/invite test * Remove replace from go.mod
This commit is contained in:
parent
6820b3e024
commit
6cb1a65809
23 changed files with 334 additions and 443 deletions
|
@ -22,7 +22,7 @@ type RoomserverInternalAPI interface {
|
|||
ctx context.Context,
|
||||
req *PerformInviteRequest,
|
||||
res *PerformInviteResponse,
|
||||
)
|
||||
) error
|
||||
|
||||
PerformJoin(
|
||||
ctx context.Context,
|
||||
|
|
|
@ -33,9 +33,9 @@ func (t *RoomserverInternalAPITrace) PerformInvite(
|
|||
ctx context.Context,
|
||||
req *PerformInviteRequest,
|
||||
res *PerformInviteResponse,
|
||||
) {
|
||||
t.Impl.PerformInvite(ctx, req, res)
|
||||
) error {
|
||||
util.GetLogger(ctx).Infof("PerformInvite req=%+v res=%+v", js(req), js(res))
|
||||
return t.Impl.PerformInvite(ctx, req, res)
|
||||
}
|
||||
|
||||
func (t *RoomserverInternalAPITrace) PerformJoin(
|
||||
|
|
|
@ -105,7 +105,6 @@ type PerformInviteRequest struct {
|
|||
}
|
||||
|
||||
type PerformInviteResponse struct {
|
||||
// If non-nil, the invite request failed. Contains more information why it failed.
|
||||
Error *PerformError
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
|
@ -99,21 +100,41 @@ func SendInvite(
|
|||
rsAPI RoomserverInternalAPI, inviteEvent gomatrixserverlib.HeaderedEvent,
|
||||
inviteRoomState []gomatrixserverlib.InviteV2StrippedState,
|
||||
sendAsServer gomatrixserverlib.ServerName, txnID *TransactionID,
|
||||
) *PerformError {
|
||||
request := PerformInviteRequest{
|
||||
) error {
|
||||
// Start by sending the invite request into the roomserver. This will
|
||||
// trigger the federation request amongst other things if needed.
|
||||
request := &PerformInviteRequest{
|
||||
Event: inviteEvent,
|
||||
InviteRoomState: inviteRoomState,
|
||||
RoomVersion: inviteEvent.RoomVersion,
|
||||
SendAsServer: string(sendAsServer),
|
||||
TransactionID: txnID,
|
||||
}
|
||||
var response PerformInviteResponse
|
||||
rsAPI.PerformInvite(ctx, &request, &response)
|
||||
// we need to do this because many places people will use `var err error` as the return
|
||||
// arg and a nil interface != nil pointer to a concrete interface (in this case PerformError)
|
||||
if response.Error != nil && response.Error.Msg != "" {
|
||||
response := &PerformInviteResponse{}
|
||||
if err := rsAPI.PerformInvite(ctx, request, response); err != nil {
|
||||
return fmt.Errorf("rsAPI.PerformInvite: %w", err)
|
||||
}
|
||||
if response.Error != nil {
|
||||
return response.Error
|
||||
}
|
||||
|
||||
// Now send the invite event into the roomserver. If the room is known
|
||||
// locally then this will succeed, notifying existing users in the room
|
||||
// about the new invite. If the room isn't known locally then this will
|
||||
// fail - and that's also OK.
|
||||
inputReq := &InputRoomEventsRequest{
|
||||
InputRoomEvents: []InputRoomEvent{
|
||||
{
|
||||
Kind: KindNew,
|
||||
Event: inviteEvent,
|
||||
AuthEventIDs: inviteEvent.AuthEventIDs(),
|
||||
SendAsServer: string(sendAsServer),
|
||||
},
|
||||
},
|
||||
}
|
||||
inputRes := &InputRoomEventsResponse{}
|
||||
_ = rsAPI.InputRoomEvents(ctx, inputReq, inputRes)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue