rommserver/alias: Do not call appserviceAPI in GetRoomIDForAlias if local alias found #631 (#702)

A conditional is added to wrap the call to appserviceAPI if a local alias is not found in the database.

Fixes #631

Signed-off-by: Serra Allgood <serra@allgood.dev>
This commit is contained in:
Serra Allgood 2019-06-25 05:43:18 -07:00 committed by Andrew Morgan
parent 7792f12e6f
commit a0dec456c1
2 changed files with 211 additions and 6 deletions

View file

@ -96,12 +96,21 @@ func (r *RoomserverAliasAPI) GetRoomIDForAlias(
return err
}
// No rooms found locally, try our application services by making a call to
// the appservice component
aliasReq := appserviceAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp appserviceAPI.RoomAliasExistsResponse
if err = r.AppserviceAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
return err
if roomID == "" {
// No room found locally, try our application services by making a call to
// the appservice component
aliasReq := appserviceAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp appserviceAPI.RoomAliasExistsResponse
if err = r.AppserviceAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
return err
}
if aliasResp.AliasExists {
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
if err != nil {
return err
}
}
}
response.RoomID = roomID