Compare commits
9 commits
main
...
neilalexan
Author | SHA1 | Date | |
---|---|---|---|
72d756371d | |||
711ed108f9 | |||
404d73a24c | |||
cdfbe604fd | |||
b5388eee84 | |||
d38f302c85 | |||
b39f38263e | |||
9437126bd8 | |||
201f363d30 |
|
@ -57,6 +57,11 @@ func (p *PerformError) JSONResponse() util.JSONResponse {
|
||||||
// TODO: Should we assert this is in fact JSON? E.g gjson parse?
|
// TODO: Should we assert this is in fact JSON? E.g gjson parse?
|
||||||
JSON: json.RawMessage(p.Msg),
|
JSON: json.RawMessage(p.Msg),
|
||||||
}
|
}
|
||||||
|
case PerformErrorNotFound:
|
||||||
|
return util.JSONResponse{
|
||||||
|
Code: http.StatusNotFound,
|
||||||
|
JSON: jsonerror.NotFound(p.Msg),
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return util.ErrorResponse(p)
|
return util.ErrorResponse(p)
|
||||||
}
|
}
|
||||||
|
@ -73,6 +78,8 @@ const (
|
||||||
PerformErrorNoOperation PerformErrorCode = 4
|
PerformErrorNoOperation PerformErrorCode = 4
|
||||||
// PerformErrRemote means that the request failed and the PerformError.Msg is the raw remote JSON error response
|
// PerformErrRemote means that the request failed and the PerformError.Msg is the raw remote JSON error response
|
||||||
PerformErrRemote PerformErrorCode = 5
|
PerformErrRemote PerformErrorCode = 5
|
||||||
|
// PerformErrorNotFound means the thing they were trying to do was not found.
|
||||||
|
PerformErrorNotFound PerformErrorCode = 6
|
||||||
)
|
)
|
||||||
|
|
||||||
type PerformJoinRequest struct {
|
type PerformJoinRequest struct {
|
||||||
|
|
|
@ -193,6 +193,7 @@ func (r *RoomserverInternalAPI) SetFederationAPI(fsAPI fsAPI.RoomserverFederatio
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RoomserverInternalAPI) SetUserAPI(userAPI userapi.RoomserverUserAPI) {
|
func (r *RoomserverInternalAPI) SetUserAPI(userAPI userapi.RoomserverUserAPI) {
|
||||||
|
r.Inviter.UserAPI = userAPI
|
||||||
r.Leaver.UserAPI = userAPI
|
r.Leaver.UserAPI = userAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,7 +211,7 @@ func (r *RoomserverInternalAPI) PerformInvite(
|
||||||
sentry.CaptureException(err)
|
sentry.CaptureException(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(outputEvents) == 0 {
|
if res.Error != nil || len(outputEvents) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return r.OutputProducer.ProduceRoomEvents(req.Event.RoomID(), outputEvents)
|
return r.OutputProducer.ProduceRoomEvents(req.Event.RoomID(), outputEvents)
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
"github.com/matrix-org/dendrite/roomserver/storage/shared"
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
|
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -36,6 +37,7 @@ type Inviter struct {
|
||||||
DB storage.Database
|
DB storage.Database
|
||||||
Cfg *config.RoomServer
|
Cfg *config.RoomServer
|
||||||
FSAPI federationAPI.RoomserverFederationAPI
|
FSAPI federationAPI.RoomserverFederationAPI
|
||||||
|
UserAPI userAPI.RoomserverUserAPI
|
||||||
Inputer *input.Inputer
|
Inputer *input.Inputer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +64,7 @@ func (r *Inviter) PerformInvite(
|
||||||
return nil, fmt.Errorf("failed to load RoomInfo: %w", err)
|
return nil, fmt.Errorf("failed to load RoomInfo: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, domain, err := gomatrixserverlib.SplitID('@', targetUserID)
|
localpart, domain, err := gomatrixserverlib.SplitID('@', targetUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.Error = &api.PerformError{
|
res.Error = &api.PerformError{
|
||||||
Code: api.PerformErrorBadRequest,
|
Code: api.PerformErrorBadRequest,
|
||||||
|
@ -80,6 +82,24 @@ func (r *Inviter) PerformInvite(
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isTargetLocal {
|
||||||
|
userReq := &userAPI.QueryAccountAvailabilityRequest{
|
||||||
|
Localpart: localpart,
|
||||||
|
}
|
||||||
|
userRes := &userAPI.QueryAccountAvailabilityResponse{}
|
||||||
|
if err = r.UserAPI.QueryAccountAvailability(ctx, userReq, userRes); err != nil {
|
||||||
|
return nil, fmt.Errorf("r.UserAPI.QueryAccountAvailability: %w", err)
|
||||||
|
}
|
||||||
|
// If the user ID is "available" then that user doesn't exist.
|
||||||
|
if userRes.Available {
|
||||||
|
res.Error = &api.PerformError{
|
||||||
|
Code: api.PerformErrorNotFound,
|
||||||
|
Msg: fmt.Sprintf("The user ID %q does not exist!", targetUserID),
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger := util.GetLogger(ctx).WithFields(map[string]interface{}{
|
logger := util.GetLogger(ctx).WithFields(map[string]interface{}{
|
||||||
"inviter": event.Sender(),
|
"inviter": event.Sender(),
|
||||||
"invitee": *event.StateKey(),
|
"invitee": *event.StateKey(),
|
||||||
|
|
|
@ -50,6 +50,7 @@ type KeyserverUserAPI interface {
|
||||||
|
|
||||||
type RoomserverUserAPI interface {
|
type RoomserverUserAPI interface {
|
||||||
QueryAccountData(ctx context.Context, req *QueryAccountDataRequest, res *QueryAccountDataResponse) error
|
QueryAccountData(ctx context.Context, req *QueryAccountDataRequest, res *QueryAccountDataResponse) error
|
||||||
|
QueryAccountAvailability(ctx context.Context, req *QueryAccountAvailabilityRequest, res *QueryAccountAvailabilityResponse) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// api functions required by the media api
|
// api functions required by the media api
|
||||||
|
|
Loading…
Reference in a new issue