Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit e22b718

Browse files
Clean up the user directory sample config section (#9385)
The user directory sample config section was a little messy, and didn't adhere to our [recommended config format guidelines](https://github.com/matrix-org/synapse/blob/develop/docs/code_style.md#configuration-file-format). This PR cleans that up a bit.
1 parent fc8b3d8 commit e22b718

File tree

3 files changed

+67
-50
lines changed

3 files changed

+67
-50
lines changed

changelog.d/9385.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a configuration option, `user_directory.prefer_local_users`, which when enabled will make it more likely for users on the same server as you to appear above other users.

docs/sample_config.yaml

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,24 +2544,35 @@ spam_checker:
25442544

25452545
# User Directory configuration
25462546
#
2547-
# 'enabled' defines whether users can search the user directory. If
2548-
# false then empty responses are returned to all queries. Defaults to
2549-
# true.
2550-
#
2551-
# 'search_all_users' defines whether to search all users visible to your HS
2552-
# when searching the user directory, rather than limiting to users visible
2553-
# in public rooms. Defaults to false. If you set it True, you'll have to
2554-
# rebuild the user_directory search indexes, see
2555-
# https://github.com/matrix-org/synapse/blob/master/docs/user_directory.md
2556-
#
2557-
# 'prefer_local_users' defines whether to prioritise local users in
2558-
# search query results. If True, local users are more likely to appear above
2559-
# remote users when searching the user directory. Defaults to false.
2560-
#
2561-
#user_directory:
2562-
# enabled: true
2563-
# search_all_users: false
2564-
# prefer_local_users: false
2547+
user_directory:
2548+
# Defines whether users can search the user directory. If false then
2549+
# empty responses are returned to all queries. Defaults to true.
2550+
#
2551+
# Uncomment to disable the user directory.
2552+
#
2553+
#enabled: false
2554+
2555+
# Defines whether to search all users visible to your HS when searching
2556+
# the user directory, rather than limiting to users visible in public
2557+
# rooms. Defaults to false.
2558+
#
2559+
# If you set it true, you'll have to rebuild the user_directory search
2560+
# indexes, see:
2561+
# https://github.com/matrix-org/synapse/blob/master/docs/user_directory.md
2562+
#
2563+
# Uncomment to return search results containing all known users, even if that
2564+
# user does not share a room with the requester.
2565+
#
2566+
#search_all_users: true
2567+
2568+
# Defines whether to prefer local users in search query results.
2569+
# If True, local users are more likely to appear above remote users
2570+
# when searching the user directory. Defaults to false.
2571+
#
2572+
# Uncomment to prefer local over remote users in user directory search
2573+
# results.
2574+
#
2575+
#prefer_local_users: true
25652576

25662577

25672578
# User Consent configuration

synapse/config/user_directory.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,46 @@ class UserDirectoryConfig(Config):
2424
section = "userdirectory"
2525

2626
def read_config(self, config, **kwargs):
27-
self.user_directory_search_enabled = True
28-
self.user_directory_search_all_users = False
29-
self.user_directory_search_prefer_local_users = False
30-
user_directory_config = config.get("user_directory", None)
31-
if user_directory_config:
32-
self.user_directory_search_enabled = user_directory_config.get(
33-
"enabled", True
34-
)
35-
self.user_directory_search_all_users = user_directory_config.get(
36-
"search_all_users", False
37-
)
38-
self.user_directory_search_prefer_local_users = user_directory_config.get(
39-
"prefer_local_users", False
40-
)
27+
user_directory_config = config.get("user_directory") or {}
28+
self.user_directory_search_enabled = user_directory_config.get("enabled", True)
29+
self.user_directory_search_all_users = user_directory_config.get(
30+
"search_all_users", False
31+
)
32+
self.user_directory_search_prefer_local_users = user_directory_config.get(
33+
"prefer_local_users", False
34+
)
4135

4236
def generate_config_section(self, config_dir_path, server_name, **kwargs):
4337
return """
4438
# User Directory configuration
4539
#
46-
# 'enabled' defines whether users can search the user directory. If
47-
# false then empty responses are returned to all queries. Defaults to
48-
# true.
49-
#
50-
# 'search_all_users' defines whether to search all users visible to your HS
51-
# when searching the user directory, rather than limiting to users visible
52-
# in public rooms. Defaults to false. If you set it True, you'll have to
53-
# rebuild the user_directory search indexes, see
54-
# https://github.com/matrix-org/synapse/blob/master/docs/user_directory.md
55-
#
56-
# 'prefer_local_users' defines whether to prioritise local users in
57-
# search query results. If True, local users are more likely to appear above
58-
# remote users when searching the user directory. Defaults to false.
59-
#
60-
#user_directory:
61-
# enabled: true
62-
# search_all_users: false
63-
# prefer_local_users: false
40+
user_directory:
41+
# Defines whether users can search the user directory. If false then
42+
# empty responses are returned to all queries. Defaults to true.
43+
#
44+
# Uncomment to disable the user directory.
45+
#
46+
#enabled: false
47+
48+
# Defines whether to search all users visible to your HS when searching
49+
# the user directory, rather than limiting to users visible in public
50+
# rooms. Defaults to false.
51+
#
52+
# If you set it true, you'll have to rebuild the user_directory search
53+
# indexes, see:
54+
# https://github.com/matrix-org/synapse/blob/master/docs/user_directory.md
55+
#
56+
# Uncomment to return search results containing all known users, even if that
57+
# user does not share a room with the requester.
58+
#
59+
#search_all_users: true
60+
61+
# Defines whether to prefer local users in search query results.
62+
# If True, local users are more likely to appear above remote users
63+
# when searching the user directory. Defaults to false.
64+
#
65+
# Uncomment to prefer local over remote users in user directory search
66+
# results.
67+
#
68+
#prefer_local_users: true
6469
"""

0 commit comments

Comments
 (0)