mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-09-17 02:34:37 -04:00
fix thinkos galore
This commit is contained in:
parent
cd3697e8b7
commit
a4bb133b68
3 changed files with 41 additions and 20 deletions
|
@ -16,6 +16,7 @@
|
|||
from twisted.internet import defer
|
||||
|
||||
from synapse.storage.roommember import ProfileInfo
|
||||
from synapse.api.errors import StoreError
|
||||
|
||||
from ._base import SQLBaseStore
|
||||
|
||||
|
@ -28,16 +29,28 @@ class ProfileStore(SQLBaseStore):
|
|||
desc="create_profile",
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_profileinfo(self, user_localpart):
|
||||
profile = self._simple_select_one(
|
||||
table="profiles",
|
||||
keyvalues={"user_id": user_localpart},
|
||||
retcols=("displayname", "avatar_url"),
|
||||
desc="get_profileinfo",
|
||||
)
|
||||
return ProfileInfo(
|
||||
avatar_url=profile.avatar_url,
|
||||
displayname=profile.displayname,
|
||||
try:
|
||||
profile = yield self._simple_select_one(
|
||||
table="profiles",
|
||||
keyvalues={"user_id": user_localpart},
|
||||
retcols=("displayname", "avatar_url"),
|
||||
desc="get_profileinfo",
|
||||
)
|
||||
except StoreError, e:
|
||||
if e.code == 404:
|
||||
# no match
|
||||
defer.returnValue(ProfileInfo(None, None))
|
||||
return
|
||||
else:
|
||||
raise
|
||||
|
||||
defer.returnValue(
|
||||
ProfileInfo(
|
||||
avatar_url=profile['avatar_url'],
|
||||
display_name=profile['displayname'],
|
||||
)
|
||||
)
|
||||
|
||||
def get_profile_displayname(self, user_localpart):
|
||||
|
|
|
@ -640,13 +640,17 @@ class UserDirectoryStore(SQLBaseStore):
|
|||
}
|
||||
"""
|
||||
|
||||
include_pattern_clause = ""
|
||||
include_pattern_join = ""
|
||||
include_pattern_where_clause = ""
|
||||
if self.hs.config.user_directory_include_pattern:
|
||||
include_pattern_clause = "OR d.user_id LIKE '%s'" % (
|
||||
self.hs.config.user_directory_include_pattern
|
||||
)
|
||||
include_pattern_join = """
|
||||
LEFT JOIN (
|
||||
SELECT user_id FROM user_directory
|
||||
WHERE user_id LIKE '%s'
|
||||
) AS ld USING (user_id)
|
||||
""" % ( self.hs.config.user_directory_include_pattern )
|
||||
|
||||
logger.error("include pattern is %s" % (include_pattern))
|
||||
include_pattern_where_clause = "OR ld.user_id IS NOT NULL"
|
||||
|
||||
if isinstance(self.database_engine, PostgresEngine):
|
||||
full_query, exact_query, prefix_query = _parse_query_postgres(search_term)
|
||||
|
@ -665,6 +669,7 @@ class UserDirectoryStore(SQLBaseStore):
|
|||
SELECT other_user_id AS user_id FROM users_who_share_rooms
|
||||
WHERE user_id = ? AND share_private
|
||||
) AS s USING (user_id)
|
||||
%s
|
||||
WHERE
|
||||
(s.user_id IS NOT NULL OR p.user_id IS NOT NULL %s)
|
||||
AND vector @@ to_tsquery('english', ?)
|
||||
|
@ -690,7 +695,7 @@ class UserDirectoryStore(SQLBaseStore):
|
|||
display_name IS NULL,
|
||||
avatar_url IS NULL
|
||||
LIMIT ?
|
||||
""" % ( include_pattern_clause )
|
||||
""" % ( include_pattern_join, include_pattern_where_clause )
|
||||
args = (user_id, full_query, exact_query, prefix_query, limit + 1,)
|
||||
elif isinstance(self.database_engine, Sqlite3Engine):
|
||||
search_query = _parse_query_sqlite(search_term)
|
||||
|
@ -704,6 +709,7 @@ class UserDirectoryStore(SQLBaseStore):
|
|||
SELECT other_user_id AS user_id FROM users_who_share_rooms
|
||||
WHERE user_id = ? AND share_private
|
||||
) AS s USING (user_id)
|
||||
%s
|
||||
WHERE
|
||||
(s.user_id IS NOT NULL OR p.user_id IS NOT NULL %s)
|
||||
AND value MATCH ?
|
||||
|
@ -712,7 +718,7 @@ class UserDirectoryStore(SQLBaseStore):
|
|||
display_name IS NULL,
|
||||
avatar_url IS NULL
|
||||
LIMIT ?
|
||||
""" % ( include_pattern_clause )
|
||||
""" % ( include_pattern_join, include_pattern_where_clause )
|
||||
args = (user_id, search_query, limit + 1)
|
||||
else:
|
||||
# This should be unreachable.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue