More logical naming, clean up a bit

This commit is contained in:
Neil Alexander 2021-03-03 16:44:06 +00:00
parent 6a880df844
commit b50694eb8f
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
6 changed files with 38 additions and 29 deletions

View file

@ -218,7 +218,7 @@ func createRoom(
// check it's free TODO: This races but is better than nothing
hasAliasReq := roomserverAPI.GetRoomIDForAliasRequest{
Alias: roomAlias,
ShouldHitAppservice: false,
IncludeAppservices: false,
}
var aliasResp roomserverAPI.GetRoomIDForAliasResponse

View file

@ -61,9 +61,12 @@ func DirectoryRoom(
var res roomDirectoryResponse
// Query the roomserver API to check if the alias exists locally.
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias, ShouldHitAppservice: true}
var queryRes roomserverAPI.GetRoomIDForAliasResponse
if err = rsAPI.GetRoomIDForAlias(req.Context(), &queryReq, &queryRes); err != nil {
queryReq := &roomserverAPI.GetRoomIDForAliasRequest{
Alias: roomAlias,
IncludeAppservices: true,
}
queryRes := &roomserverAPI.GetRoomIDForAliasResponse{}
if err = rsAPI.GetRoomIDForAlias(req.Context(), queryReq, queryRes); err != nil {
util.GetLogger(req.Context()).WithError(err).Error("rsAPI.GetRoomIDForAlias failed")
return jsonerror.InternalServerError()
}

View file

@ -53,9 +53,12 @@ func RoomAliasToID(
var resp gomatrixserverlib.RespDirectory
if domain == cfg.Matrix.ServerName {
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias, ShouldHitAppservice: true}
var queryRes roomserverAPI.GetRoomIDForAliasResponse
if err = rsAPI.GetRoomIDForAlias(httpReq.Context(), &queryReq, &queryRes); err != nil {
queryReq := &roomserverAPI.GetRoomIDForAliasRequest{
Alias: roomAlias,
IncludeAppservices: true,
}
queryRes := &roomserverAPI.GetRoomIDForAliasResponse{}
if err = rsAPI.GetRoomIDForAlias(httpReq.Context(), queryReq, queryRes); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("aliasAPI.GetRoomIDForAlias failed")
return jsonerror.InternalServerError()
}

View file

@ -34,7 +34,9 @@ type SetRoomAliasResponse struct {
type GetRoomIDForAliasRequest struct {
// Alias we want to lookup
Alias string `json:"alias"`
ShouldHitAppservice bool `json:"shouldHitAppservice"`
// Should we ask appservices for their aliases as a part of
// the request?
IncludeAppservices bool `json:"include_appservices"`
}
// GetRoomIDForAliasResponse is a response to GetRoomIDForAlias

View file

@ -93,18 +93,20 @@ func (r *RoomserverInternalAPI) GetRoomIDForAlias(
return nil
}
// Check appservice on err
if r.asAPI != nil && request.ShouldHitAppservice { // appservice component is wired in
if roomID == "" {
// Check appservice on err, but only if the appservice API is
// wired in and no room ID was found.
if r.asAPI != nil && request.IncludeAppservices && roomID == "" {
// No room found locally, try our application services by making a call to
// the appservice component
aliasReq := asAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp asAPI.RoomAliasExistsResponse
if err = r.asAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
aliasReq := &asAPI.RoomAliasExistsRequest{
Alias: request.Alias,
}
aliasRes := &asAPI.RoomAliasExistsResponse{}
if err = r.asAPI.RoomAliasExists(ctx, aliasReq, aliasRes); err != nil {
return err
}
if aliasResp.AliasExists {
if aliasRes.AliasExists {
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
if err != nil {
return err
@ -113,7 +115,6 @@ func (r *RoomserverInternalAPI) GetRoomIDForAlias(
return nil
}
}
}
return err
}

View file

@ -125,7 +125,7 @@ func (r *Joiner) performJoinRoomByAlias(
} else {
var getRoomReq = rsAPI.GetRoomIDForAliasRequest{
Alias: req.RoomIDOrAlias,
ShouldHitAppservice: true,
IncludeAppservices: true,
}
var getRoomRes = rsAPI.GetRoomIDForAliasResponse{}
// Otherwise, look up if we know this room alias locally.