mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 06:12:45 +00:00
Fix appsevice alias queries part 2 (#1684)
* Check membership of room * Use QueryStateAfterEventsResponse * Fix complexity * Add field ShouldHitAppservice to GetRoomIDForAlias * Hit appservice when trying to join a non-existent alias * remove unused * Changes that I made a long time ago * Rename to appserviceJoinedAtEvent * Check membership in GetMemberships * Update QueryMembershipsForRoom * Tweaks in client API * Update appserviceJoinedAtEvent * Comments * Try QueryMembershipForUser instead * Undo some changes to client API that shouldn't be needed * More /event tweaks * Refactor /event bit * Go back to QueryMembershipsForRoom because appservices are hard * Fix bugs in onMessage * Add comments * More logical naming, clean up a bit Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
This commit is contained in:
parent
a2773922d2
commit
9557ccada4
7 changed files with 49 additions and 26 deletions
|
@ -88,31 +88,35 @@ func (r *RoomserverInternalAPI) GetRoomIDForAlias(
|
|||
) error {
|
||||
// Look up the room ID in the database
|
||||
roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias)
|
||||
if err != nil {
|
||||
return err
|
||||
if err == nil && roomID != "" {
|
||||
response.RoomID = roomID
|
||||
return nil
|
||||
}
|
||||
|
||||
if r.asAPI != nil { // appservice component is wired in
|
||||
if 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 {
|
||||
// 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,
|
||||
}
|
||||
aliasRes := &asAPI.RoomAliasExistsResponse{}
|
||||
if err = r.asAPI.RoomAliasExists(ctx, aliasReq, aliasRes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if aliasRes.AliasExists {
|
||||
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if aliasResp.AliasExists {
|
||||
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
response.RoomID = roomID
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
response.RoomID = roomID
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
// GetAliasesForRoomID implements alias.RoomserverInternalAPI
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue