aboutsummaryrefslogtreecommitdiff
path: root/appservice
diff options
context:
space:
mode:
authorS7evinK <2353100+S7evinK@users.noreply.github.com>2022-03-24 22:45:44 +0100
committerGitHub <noreply@github.com>2022-03-24 22:45:44 +0100
commitf2e550efd832662e6c032bebfef4a68da0b4c8ee (patch)
treef46d0e82f85f0e30687fe568a26c0923e8f14a83 /appservice
parent8e76523b04e3ebc9546f2b019e86dcd3b516be5a (diff)
Refactor appservice & client API to use userapi internal (#2290)
* Refactor user api internal * Refactor clientapi to use internal userapi * Use internal userapi instead of user DB directly * Remove AccountDB dependency * Fix linter issues Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'appservice')
-rw-r--r--appservice/api/query.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/appservice/api/query.go b/appservice/api/query.go
index e53ad425..cf25a961 100644
--- a/appservice/api/query.go
+++ b/appservice/api/query.go
@@ -19,11 +19,10 @@ package api
import (
"context"
- "database/sql"
"errors"
"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"
)
@@ -85,7 +84,7 @@ func RetrieveUserProfile(
ctx context.Context,
userID string,
asAPI AppServiceQueryAPI,
- accountDB userdb.Database,
+ profileAPI userapi.UserProfileAPI,
) (*authtypes.Profile, error) {
localpart, _, err := gomatrixserverlib.SplitID('@', userID)
if err != nil {
@@ -93,10 +92,17 @@ func RetrieveUserProfile(
}
// Try to query the user from the local database
- profile, err := accountDB.GetProfileByLocalpart(ctx, localpart)
- if err != nil && err != sql.ErrNoRows {
+ res := &userapi.QueryProfileResponse{}
+ err = profileAPI.QueryProfile(ctx, &userapi.QueryProfileRequest{UserID: userID}, res)
+ if err != nil {
return nil, err
- } else if profile != nil {
+ }
+ profile := &authtypes.Profile{
+ Localpart: localpart,
+ DisplayName: res.DisplayName,
+ AvatarURL: res.AvatarURL,
+ }
+ if res.UserExists {
return profile, nil
}
@@ -113,11 +119,15 @@ func RetrieveUserProfile(
}
// 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 {
return nil, err
}
// profile should not be nil at this point
- return profile, nil
+ return &authtypes.Profile{
+ Localpart: localpart,
+ DisplayName: res.DisplayName,
+ AvatarURL: res.AvatarURL,
+ }, nil
}