aboutsummaryrefslogtreecommitdiff
path: root/clientapi
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-03-28 16:25:26 +0100
committerGitHub <noreply@github.com>2022-03-28 16:25:26 +0100
commit7972915806348847ecd9a9b8a1b1ff0609cb883c (patch)
treedfbf719e8229dc4faeef133b150b2d7a6dc7eac8 /clientapi
parent0692be44d91a42945dde0eab3e2f7481cc2e0896 (diff)
User directory for nearby Pinecone peers (P2P demo) (#2311)
* User directory for nearby Pinecone peers * Fix mux routing * Use config to determine which server notices user to exclude
Diffstat (limited to 'clientapi')
-rw-r--r--clientapi/auth/authtypes/profile.go1
-rw-r--r--clientapi/clientapi.go3
-rw-r--r--clientapi/routing/routing.go2
-rw-r--r--clientapi/routing/userdirectory.go14
4 files changed, 15 insertions, 5 deletions
diff --git a/clientapi/auth/authtypes/profile.go b/clientapi/auth/authtypes/profile.go
index 902850bc..29468c16 100644
--- a/clientapi/auth/authtypes/profile.go
+++ b/clientapi/auth/authtypes/profile.go
@@ -17,6 +17,7 @@ package authtypes
// Profile represents the profile for a Matrix account.
type Profile struct {
Localpart string `json:"local_part"`
+ ServerName string `json:"server_name,omitempty"` // NOTSPEC: only set by Pinecone user provider
DisplayName string `json:"display_name"`
AvatarURL string `json:"avatar_url"`
}
diff --git a/clientapi/clientapi.go b/clientapi/clientapi.go
index 31a53a70..d0ef368d 100644
--- a/clientapi/clientapi.go
+++ b/clientapi/clientapi.go
@@ -45,6 +45,7 @@ func AddPublicRoutes(
transactionsCache *transactions.Cache,
fsAPI federationAPI.FederationInternalAPI,
userAPI userapi.UserInternalAPI,
+ userDirectoryProvider userapi.UserDirectoryProvider,
keyAPI keyserverAPI.KeyInternalAPI,
extRoomsProvider api.ExtraPublicRoomsProvider,
mscCfg *config.MSCs,
@@ -58,7 +59,7 @@ func AddPublicRoutes(
routing.Setup(
router, synapseAdminRouter, cfg, eduInputAPI, rsAPI, asAPI,
- userAPI, federation,
+ userAPI, userDirectoryProvider, federation,
syncProducer, transactionsCache, fsAPI, keyAPI,
extRoomsProvider, mscCfg,
)
diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go
index e173831a..218087bb 100644
--- a/clientapi/routing/routing.go
+++ b/clientapi/routing/routing.go
@@ -51,6 +51,7 @@ func Setup(
rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI,
userAPI userapi.UserInternalAPI,
+ userDirectoryProvider userapi.UserDirectoryProvider,
federation *gomatrixserverlib.FederationClient,
syncProducer *producers.SyncAPIProducer,
transactionsCache *transactions.Cache,
@@ -904,6 +905,7 @@ func Setup(
device,
userAPI,
rsAPI,
+ userDirectoryProvider,
cfg.Matrix.ServerName,
postContent.SearchString,
postContent.Limit,
diff --git a/clientapi/routing/userdirectory.go b/clientapi/routing/userdirectory.go
index 2659bc9c..ab73cf43 100644
--- a/clientapi/routing/userdirectory.go
+++ b/clientapi/routing/userdirectory.go
@@ -16,6 +16,7 @@ package routing
import (
"context"
+ "database/sql"
"fmt"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
@@ -35,6 +36,7 @@ func SearchUserDirectory(
device *userapi.Device,
userAPI userapi.UserInternalAPI,
rsAPI api.RoomserverInternalAPI,
+ provider userapi.UserDirectoryProvider,
serverName gomatrixserverlib.ServerName,
searchString string,
limit int,
@@ -50,13 +52,12 @@ func SearchUserDirectory(
}
// First start searching local users.
-
userReq := &userapi.QuerySearchProfilesRequest{
SearchString: searchString,
Limit: limit,
}
userRes := &userapi.QuerySearchProfilesResponse{}
- if err := userAPI.QuerySearchProfiles(ctx, userReq, userRes); err != nil {
+ if err := provider.QuerySearchProfiles(ctx, userReq, userRes); err != nil {
errRes := util.ErrorResponse(fmt.Errorf("userAPI.QuerySearchProfiles: %w", err))
return &errRes
}
@@ -67,7 +68,12 @@ func SearchUserDirectory(
break
}
- userID := fmt.Sprintf("@%s:%s", user.Localpart, serverName)
+ var userID string
+ if user.ServerName != "" {
+ userID = fmt.Sprintf("@%s:%s", user.Localpart, user.ServerName)
+ } else {
+ userID = fmt.Sprintf("@%s:%s", user.Localpart, serverName)
+ }
if _, ok := results[userID]; !ok {
results[userID] = authtypes.FullyQualifiedProfile{
UserID: userID,
@@ -87,7 +93,7 @@ func SearchUserDirectory(
Limit: limit - len(results),
}
stateRes := &api.QueryKnownUsersResponse{}
- if err := rsAPI.QueryKnownUsers(ctx, stateReq, stateRes); err != nil {
+ if err := rsAPI.QueryKnownUsers(ctx, stateReq, stateRes); err != nil && err != sql.ErrNoRows {
errRes := util.ErrorResponse(fmt.Errorf("rsAPI.QueryKnownUsers: %w", err))
return &errRes
}