Use internal userapi instead of user DB directly

This commit is contained in:
Till Faelligen 2022-03-21 15:29:20 +01:00
parent c465b81692
commit 8d84ea453d

View file

@ -19,11 +19,10 @@ package api
import ( import (
"context" "context"
"database/sql"
"errors" "errors"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/authtypes"
userdb "github.com/matrix-org/dendrite/userapi/storage" userapi "github.com/matrix-org/dendrite/userapi/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
@ -85,7 +84,7 @@ func RetrieveUserProfile(
ctx context.Context, ctx context.Context,
userID string, userID string,
asAPI AppServiceQueryAPI, asAPI AppServiceQueryAPI,
accountDB userdb.Database, profileAPI userapi.UserProfileAPI,
) (*authtypes.Profile, error) { ) (*authtypes.Profile, error) {
localpart, _, err := gomatrixserverlib.SplitID('@', userID) localpart, _, err := gomatrixserverlib.SplitID('@', userID)
if err != nil { if err != nil {
@ -93,10 +92,17 @@ func RetrieveUserProfile(
} }
// Try to query the user from the local database // Try to query the user from the local database
profile, err := accountDB.GetProfileByLocalpart(ctx, localpart) res := &userapi.QueryProfileResponse{}
if err != nil && err != sql.ErrNoRows { err = profileAPI.QueryProfile(ctx, &userapi.QueryProfileRequest{UserID: userID}, res)
if err != nil {
return nil, err return nil, err
} else if profile != nil { }
profile := &authtypes.Profile{
Localpart: localpart,
DisplayName: res.DisplayName,
AvatarURL: res.AvatarURL,
}
if res.UserExists {
return profile, nil return profile, nil
} }
@ -113,11 +119,15 @@ func RetrieveUserProfile(
} }
// Try to query the user from the local database again // Try to query the user from the local database again
profile, err = accountDB.GetProfileByLocalpart(ctx, localpart) err = profileAPI.QueryProfile(ctx, &userapi.QueryProfileRequest{UserID: userID}, res)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// profile should not be nil at this point // profile should not be nil at this point
return profile, nil return &authtypes.Profile{
Localpart: localpart,
DisplayName: res.DisplayName,
AvatarURL: res.AvatarURL,
}, nil
} }