mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Query remote profiles
This commit is contained in:
parent
7ecb7b5c8e
commit
32d49de494
|
|
@ -908,6 +908,7 @@ func Setup(
|
||||||
postContent.SearchString,
|
postContent.SearchString,
|
||||||
postContent.Limit,
|
postContent.Limit,
|
||||||
federation,
|
federation,
|
||||||
|
cfg.Matrix.ServerName,
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
).Methods(http.MethodPost, http.MethodOptions)
|
).Methods(http.MethodPost, http.MethodOptions)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import (
|
||||||
"github.com/matrix-org/gomatrix"
|
"github.com/matrix-org/gomatrix"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserDirectoryResponse struct {
|
type UserDirectoryResponse struct {
|
||||||
|
|
@ -43,6 +42,7 @@ func SearchUserDirectory(
|
||||||
searchString string,
|
searchString string,
|
||||||
limit int,
|
limit int,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
|
localServerName gomatrixserverlib.ServerName,
|
||||||
) util.JSONResponse {
|
) util.JSONResponse {
|
||||||
if limit < 10 {
|
if limit < 10 {
|
||||||
limit = 10
|
limit = 10
|
||||||
|
|
@ -65,14 +65,15 @@ func SearchUserDirectory(
|
||||||
}
|
}
|
||||||
|
|
||||||
knownUsersLoop:
|
knownUsersLoop:
|
||||||
for userID, localUser := range knownUsersRes.Users {
|
for _, profile := range knownUsersRes.Users {
|
||||||
if len(results) == limit {
|
if len(results) == limit {
|
||||||
response.Limited = true
|
response.Limited = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
userID := profile.UserID
|
||||||
// get the full profile of the local user
|
// get the full profile of the local user
|
||||||
localpart, serverName, _ := gomatrixserverlib.SplitID('@', userID)
|
localpart, serverName, _ := gomatrixserverlib.SplitID('@', userID)
|
||||||
if localUser {
|
if serverName == localServerName {
|
||||||
userReq := &userapi.QuerySearchProfilesRequest{
|
userReq := &userapi.QuerySearchProfilesRequest{
|
||||||
SearchString: localpart,
|
SearchString: localpart,
|
||||||
Limit: limit,
|
Limit: limit,
|
||||||
|
|
@ -96,6 +97,19 @@ knownUsersLoop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// If the username already contains the search string, don't bother hitting federation
|
||||||
|
if strings.Contains(localpart, searchString) {
|
||||||
|
results[userID] = authtypes.FullyQualifiedProfile{
|
||||||
|
UserID: userID,
|
||||||
|
DisplayName: profile.DisplayName,
|
||||||
|
AvatarURL: profile.AvatarURL,
|
||||||
|
}
|
||||||
|
if len(results) == limit {
|
||||||
|
response.Limited = true
|
||||||
|
break knownUsersLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: We should probably cache/store this
|
||||||
profile, fedErr := federation.LookupProfile(ctx, serverName, userID, "")
|
profile, fedErr := federation.LookupProfile(ctx, serverName, userID, "")
|
||||||
if fedErr != nil {
|
if fedErr != nil {
|
||||||
if x, ok := fedErr.(gomatrix.HTTPError); ok {
|
if x, ok := fedErr.(gomatrix.HTTPError); ok {
|
||||||
|
|
@ -104,23 +118,23 @@ knownUsersLoop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if strings.Contains(profile.DisplayName, searchString) {
|
||||||
results[userID] = authtypes.FullyQualifiedProfile{
|
results[userID] = authtypes.FullyQualifiedProfile{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
DisplayName: profile.DisplayName,
|
DisplayName: profile.DisplayName,
|
||||||
AvatarURL: profile.AvatarURL,
|
AvatarURL: profile.AvatarURL,
|
||||||
|
}
|
||||||
|
if len(results) == limit {
|
||||||
|
response.Limited = true
|
||||||
|
break knownUsersLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logrus.Debugf("userID: %s - searchString: %s; localUser: %v", userID, searchString, localUser)
|
|
||||||
//if strings.Contains(userID, searchString) {
|
|
||||||
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
response.Results = append(response.Results, result)
|
response.Results = append(response.Results, result)
|
||||||
}
|
}
|
||||||
logrus.Debugf("Result: %+v", response.Results)
|
|
||||||
|
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: 200,
|
Code: 200,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue