aboutsummaryrefslogtreecommitdiff
path: root/roomserver/internal/perform/perform_join.go
diff options
context:
space:
mode:
authorRyan W <twentybitdev@gmail.com>2021-09-08 17:31:03 +0100
committerGitHub <noreply@github.com>2021-09-08 17:31:03 +0100
commita624eab309ee6ee7b3540dfba884a42c9a4f4ad9 (patch)
tree92ec39ba2d0f512891dcb20635ee9bc660b45b18 /roomserver/internal/perform/perform_join.go
parent7dc8fb1fe780888d5758bf665949e9e09d21e56a (diff)
- Removed double imports (#1989)
- Lower cased error messages Signed-off-by: Ryan Whittington <twentybitdev@gmail.com> Co-authored-by: kegsay <kegan@matrix.org>
Diffstat (limited to 'roomserver/internal/perform/perform_join.go')
-rw-r--r--roomserver/internal/perform/perform_join.go75
1 files changed, 37 insertions, 38 deletions
diff --git a/roomserver/internal/perform/perform_join.go b/roomserver/internal/perform/perform_join.go
index 876888e2..772c9d7d 100644
--- a/roomserver/internal/perform/perform_join.go
+++ b/roomserver/internal/perform/perform_join.go
@@ -24,7 +24,6 @@ import (
"github.com/getsentry/sentry-go"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/internal/eventutil"
- "github.com/matrix-org/dendrite/roomserver/api"
rsAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/internal/helpers"
"github.com/matrix-org/dendrite/roomserver/internal/input"
@@ -49,17 +48,17 @@ type Joiner struct {
// PerformJoin handles joining matrix rooms, including over federation by talking to the federationsender.
func (r *Joiner) PerformJoin(
ctx context.Context,
- req *api.PerformJoinRequest,
- res *api.PerformJoinResponse,
+ req *rsAPI.PerformJoinRequest,
+ res *rsAPI.PerformJoinResponse,
) {
roomID, joinedVia, err := r.performJoin(ctx, req)
if err != nil {
sentry.CaptureException(err)
- perr, ok := err.(*api.PerformError)
+ perr, ok := err.(*rsAPI.PerformError)
if ok {
res.Error = perr
} else {
- res.Error = &api.PerformError{
+ res.Error = &rsAPI.PerformError{
Msg: err.Error(),
}
}
@@ -70,18 +69,18 @@ func (r *Joiner) PerformJoin(
func (r *Joiner) performJoin(
ctx context.Context,
- req *api.PerformJoinRequest,
+ req *rsAPI.PerformJoinRequest,
) (string, gomatrixserverlib.ServerName, error) {
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
if err != nil {
- return "", "", &api.PerformError{
- Code: api.PerformErrorBadRequest,
+ return "", "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrorBadRequest,
Msg: fmt.Sprintf("Supplied user ID %q in incorrect format", req.UserID),
}
}
if domain != r.Cfg.Matrix.ServerName {
- return "", "", &api.PerformError{
- Code: api.PerformErrorBadRequest,
+ return "", "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrorBadRequest,
Msg: fmt.Sprintf("User %q does not belong to this homeserver", req.UserID),
}
}
@@ -91,20 +90,20 @@ func (r *Joiner) performJoin(
if strings.HasPrefix(req.RoomIDOrAlias, "#") {
return r.performJoinRoomByAlias(ctx, req)
}
- return "", "", &api.PerformError{
- Code: api.PerformErrorBadRequest,
+ return "", "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrorBadRequest,
Msg: fmt.Sprintf("Room ID or alias %q is invalid", req.RoomIDOrAlias),
}
}
func (r *Joiner) performJoinRoomByAlias(
ctx context.Context,
- req *api.PerformJoinRequest,
+ req *rsAPI.PerformJoinRequest,
) (string, gomatrixserverlib.ServerName, error) {
// Get the domain part of the room alias.
_, domain, err := gomatrixserverlib.SplitID('#', req.RoomIDOrAlias)
if err != nil {
- return "", "", fmt.Errorf("Alias %q is not in the correct format", req.RoomIDOrAlias)
+ return "", "", fmt.Errorf("alias %q is not in the correct format", req.RoomIDOrAlias)
}
req.ServerNames = append(req.ServerNames, domain)
@@ -122,7 +121,7 @@ func (r *Joiner) performJoinRoomByAlias(
err = r.FSAPI.PerformDirectoryLookup(ctx, &dirReq, &dirRes)
if err != nil {
logrus.WithError(err).Errorf("error looking up alias %q", req.RoomIDOrAlias)
- return "", "", fmt.Errorf("Looking up alias %q over federation failed: %w", req.RoomIDOrAlias, err)
+ return "", "", fmt.Errorf("looking up alias %q over federation failed: %w", req.RoomIDOrAlias, err)
}
roomID = dirRes.RoomID
req.ServerNames = append(req.ServerNames, dirRes.ServerNames...)
@@ -135,14 +134,14 @@ func (r *Joiner) performJoinRoomByAlias(
// Otherwise, look up if we know this room alias locally.
err = r.RSAPI.GetRoomIDForAlias(ctx, &getRoomReq, &getRoomRes)
if err != nil {
- return "", "", fmt.Errorf("Lookup room alias %q failed: %w", req.RoomIDOrAlias, err)
+ return "", "", fmt.Errorf("lookup room alias %q failed: %w", req.RoomIDOrAlias, err)
}
roomID = getRoomRes.RoomID
}
// If the room ID is empty then we failed to look up the alias.
if roomID == "" {
- return "", "", fmt.Errorf("Alias %q not found", req.RoomIDOrAlias)
+ return "", "", fmt.Errorf("alias %q not found", req.RoomIDOrAlias)
}
// If we do, then pluck out the room ID and continue the join.
@@ -153,7 +152,7 @@ func (r *Joiner) performJoinRoomByAlias(
// TODO: Break this function up a bit
func (r *Joiner) performJoinRoomByID(
ctx context.Context,
- req *api.PerformJoinRequest,
+ req *rsAPI.PerformJoinRequest,
) (string, gomatrixserverlib.ServerName, error) {
// The original client request ?server_name=... may include this HS so filter that out so we
// don't attempt to make_join with ourselves
@@ -168,8 +167,8 @@ func (r *Joiner) performJoinRoomByID(
// Get the domain part of the room ID.
_, domain, err := gomatrixserverlib.SplitID('!', req.RoomIDOrAlias)
if err != nil {
- return "", "", &api.PerformError{
- Code: api.PerformErrorBadRequest,
+ return "", "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrorBadRequest,
Msg: fmt.Sprintf("Room ID %q is invalid: %s", req.RoomIDOrAlias, err),
}
}
@@ -207,10 +206,10 @@ func (r *Joiner) performJoinRoomByID(
// Force a federated join if we aren't in the room and we've been
// given some server names to try joining by.
- inRoomReq := &api.QueryServerJoinedToRoomRequest{
+ inRoomReq := &rsAPI.QueryServerJoinedToRoomRequest{
RoomID: req.RoomIDOrAlias,
}
- inRoomRes := &api.QueryServerJoinedToRoomResponse{}
+ inRoomRes := &rsAPI.QueryServerJoinedToRoomResponse{}
if err = r.Queryer.QueryServerJoinedToRoom(ctx, inRoomReq, inRoomRes); err != nil {
return "", "", fmt.Errorf("r.Queryer.QueryServerJoinedToRoom: %w", err)
}
@@ -267,21 +266,21 @@ func (r *Joiner) performJoinRoomByID(
// If we haven't already joined the room then send an event
// into the room changing our membership status.
if !alreadyJoined {
- inputReq := api.InputRoomEventsRequest{
- InputRoomEvents: []api.InputRoomEvent{
+ inputReq := rsAPI.InputRoomEventsRequest{
+ InputRoomEvents: []rsAPI.InputRoomEvent{
{
- Kind: api.KindNew,
+ Kind: rsAPI.KindNew,
Event: event.Headered(buildRes.RoomVersion),
AuthEventIDs: event.AuthEventIDs(),
SendAsServer: string(r.Cfg.Matrix.ServerName),
},
},
}
- inputRes := api.InputRoomEventsResponse{}
+ inputRes := rsAPI.InputRoomEventsResponse{}
r.Inputer.InputRoomEvents(ctx, &inputReq, &inputRes)
if err = inputRes.Err(); err != nil {
- return "", "", &api.PerformError{
- Code: api.PerformErrorNotAllowed,
+ return "", "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrorNotAllowed,
Msg: fmt.Sprintf("InputRoomEvents auth failed: %s", err),
}
}
@@ -296,9 +295,9 @@ func (r *Joiner) performJoinRoomByID(
// Otherwise we'll try a federated join as normal, since it's quite
// possible that the room still exists on other servers.
if len(req.ServerNames) == 0 {
- return "", "", &api.PerformError{
- Code: api.PerformErrorNoRoom,
- Msg: fmt.Sprintf("Room ID %q does not exist", req.RoomIDOrAlias),
+ return "", "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrorNoRoom,
+ Msg: fmt.Sprintf("room ID %q does not exist", req.RoomIDOrAlias),
}
}
}
@@ -309,7 +308,7 @@ func (r *Joiner) performJoinRoomByID(
default:
// Something else went wrong.
- return "", "", fmt.Errorf("Error joining local room: %q", err)
+ return "", "", fmt.Errorf("error joining local room: %q", err)
}
// By this point, if req.RoomIDOrAlias contained an alias, then
@@ -321,7 +320,7 @@ func (r *Joiner) performJoinRoomByID(
func (r *Joiner) performFederatedJoinRoomByID(
ctx context.Context,
- req *api.PerformJoinRequest,
+ req *rsAPI.PerformJoinRequest,
) (gomatrixserverlib.ServerName, error) {
// Try joining by all of the supplied server names.
fedReq := fsAPI.PerformJoinRequest{
@@ -333,8 +332,8 @@ func (r *Joiner) performFederatedJoinRoomByID(
fedRes := fsAPI.PerformJoinResponse{}
r.FSAPI.PerformJoin(ctx, &fedReq, &fedRes)
if fedRes.LastError != nil {
- return "", &api.PerformError{
- Code: api.PerformErrRemote,
+ return "", &rsAPI.PerformError{
+ Code: rsAPI.PerformErrRemote,
Msg: fedRes.LastError.Message,
RemoteCode: fedRes.LastError.Code,
}
@@ -344,7 +343,7 @@ func (r *Joiner) performFederatedJoinRoomByID(
func buildEvent(
ctx context.Context, db storage.Database, cfg *config.Global, builder *gomatrixserverlib.EventBuilder,
-) (*gomatrixserverlib.HeaderedEvent, *api.QueryLatestEventsAndStateResponse, error) {
+) (*gomatrixserverlib.HeaderedEvent, *rsAPI.QueryLatestEventsAndStateResponse, error) {
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
if err != nil {
return nil, nil, fmt.Errorf("gomatrixserverlib.StateNeededForEventBuilder: %w", err)
@@ -354,8 +353,8 @@ func buildEvent(
return nil, nil, errors.New("expecting state tuples for event builder, got none")
}
- var queryRes api.QueryLatestEventsAndStateResponse
- err = helpers.QueryLatestEventsAndState(ctx, db, &api.QueryLatestEventsAndStateRequest{
+ var queryRes rsAPI.QueryLatestEventsAndStateResponse
+ err = helpers.QueryLatestEventsAndState(ctx, db, &rsAPI.QueryLatestEventsAndStateRequest{
RoomID: builder.RoomID,
StateToFetch: eventsNeeded.Tuples(),
}, &queryRes)