mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-07 06:03:09 -06:00
Don't create a new FullyQualifiedProfile
This commit is contained in:
parent
c62bdaadab
commit
25a3ab8c79
|
|
@ -82,14 +82,12 @@ knownUsersLoop:
|
||||||
if err := provider.QuerySearchProfiles(ctx, userReq, userRes); err != nil {
|
if err := provider.QuerySearchProfiles(ctx, userReq, userRes); err != nil {
|
||||||
return util.ErrorResponse(fmt.Errorf("userAPI.QuerySearchProfiles: %w", err))
|
return util.ErrorResponse(fmt.Errorf("userAPI.QuerySearchProfiles: %w", err))
|
||||||
}
|
}
|
||||||
for _, profile := range userRes.Profiles {
|
for _, p := range userRes.Profiles {
|
||||||
if strings.Contains(userRes.Profiles[0].DisplayName, searchString) ||
|
if strings.Contains(p.DisplayName, searchString) ||
|
||||||
strings.Contains(userRes.Profiles[0].Localpart, searchString) {
|
strings.Contains(p.Localpart, searchString) {
|
||||||
results[userID] = authtypes.FullyQualifiedProfile{
|
profile.DisplayName = p.DisplayName
|
||||||
UserID: userID,
|
profile.AvatarURL = p.AvatarURL
|
||||||
DisplayName: profile.DisplayName,
|
results[userID] = profile
|
||||||
AvatarURL: profile.AvatarURL,
|
|
||||||
}
|
|
||||||
if len(results) == limit {
|
if len(results) == limit {
|
||||||
response.Limited = true
|
response.Limited = true
|
||||||
break knownUsersLoop
|
break knownUsersLoop
|
||||||
|
|
@ -97,20 +95,18 @@ knownUsersLoop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If the username already contains the search string, don't bother hitting federation
|
// If the username already contains the search string, don't bother hitting federation.
|
||||||
|
// This will result in missing avatars and displaynames, but saves the federation roundtrip.
|
||||||
if strings.Contains(localpart, searchString) {
|
if strings.Contains(localpart, searchString) {
|
||||||
results[userID] = authtypes.FullyQualifiedProfile{
|
results[userID] = profile
|
||||||
UserID: userID,
|
|
||||||
DisplayName: profile.DisplayName,
|
|
||||||
AvatarURL: profile.AvatarURL,
|
|
||||||
}
|
|
||||||
if len(results) == limit {
|
if len(results) == limit {
|
||||||
response.Limited = true
|
response.Limited = true
|
||||||
break knownUsersLoop
|
break knownUsersLoop
|
||||||
}
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
// TODO: We should probably cache/store this
|
// TODO: We should probably cache/store this
|
||||||
profile, fedErr := federation.LookupProfile(ctx, serverName, userID, "")
|
fedProfile, 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 {
|
||||||
if x.Code == http.StatusNotFound {
|
if x.Code == http.StatusNotFound {
|
||||||
|
|
@ -118,12 +114,10 @@ knownUsersLoop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.Contains(profile.DisplayName, searchString) {
|
if strings.Contains(fedProfile.DisplayName, searchString) {
|
||||||
results[userID] = authtypes.FullyQualifiedProfile{
|
profile.DisplayName = fedProfile.DisplayName
|
||||||
UserID: userID,
|
profile.AvatarURL = fedProfile.AvatarURL
|
||||||
DisplayName: profile.DisplayName,
|
results[userID] = profile
|
||||||
AvatarURL: profile.AvatarURL,
|
|
||||||
}
|
|
||||||
if len(results) == limit {
|
if len(results) == limit {
|
||||||
response.Limited = true
|
response.Limited = true
|
||||||
break knownUsersLoop
|
break knownUsersLoop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue