aboutsummaryrefslogtreecommitdiff
path: root/roomserver/api
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-08-17 11:40:49 +0100
committerGitHub <noreply@github.com>2020-08-17 11:40:49 +0100
commit6cb1a65809ccfbeaede6ff164c281ba0ddf90ab7 (patch)
tree56406ef5a5d4335d03e7805c19fa35aad805871e /roomserver/api
parent6820b3e024474e2c44f7a0632261d2dc86257d77 (diff)
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
Diffstat (limited to 'roomserver/api')
-rw-r--r--roomserver/api/api.go2
-rw-r--r--roomserver/api/api_trace.go4
-rw-r--r--roomserver/api/perform.go1
-rw-r--r--roomserver/api/wrapper.go35
4 files changed, 31 insertions, 11 deletions
diff --git a/roomserver/api/api.go b/roomserver/api/api.go
index 0a5845dd..0fe30b8b 100644
--- a/roomserver/api/api.go
+++ b/roomserver/api/api.go
@@ -22,7 +22,7 @@ type RoomserverInternalAPI interface {
ctx context.Context,
req *PerformInviteRequest,
res *PerformInviteResponse,
- )
+ ) error
PerformJoin(
ctx context.Context,
diff --git a/roomserver/api/api_trace.go b/roomserver/api/api_trace.go
index bdebc57b..9b53aa88 100644
--- a/roomserver/api/api_trace.go
+++ b/roomserver/api/api_trace.go
@@ -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(
diff --git a/roomserver/api/perform.go b/roomserver/api/perform.go
index 9e844733..24e958bb 100644
--- a/roomserver/api/perform.go
+++ b/roomserver/api/perform.go
@@ -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
}
diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go
index b6a4c888..ed3daf67 100644
--- a/roomserver/api/wrapper.go
+++ b/roomserver/api/wrapper.go
@@ -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
}