Page MenuHomePhabricator

D9885.id33219.diff
No OneTemporary

D9885.id33219.diff

diff --git a/lib/shared/search-utils.js b/lib/shared/search-utils.js
--- a/lib/shared/search-utils.js
+++ b/lib/shared/search-utils.js
@@ -3,6 +3,7 @@
import * as React from 'react';
import { useSelector } from 'react-redux';
+import { ensRegex } from './markdown.js';
import SearchIndex from './search-index.js';
import {
userIsMember,
@@ -17,6 +18,7 @@
searchUsers,
searchUsersActionTypes,
} from '../actions/user-actions.js';
+import { ENSCacheContext } from '../components/ens-cache-provider.react.js';
import genesis from '../facts/genesis.js';
import type {
ChatMessageInfoItem,
@@ -264,12 +266,39 @@
);
}
+function useForwardLookupSearchText(originalText: string): string {
+ const cacheContext = React.useContext(ENSCacheContext);
+ const { ensCache } = cacheContext;
+
+ const [usernameToSearch, setUsernameToSearch] =
+ React.useState<string>(originalText);
+
+ React.useEffect(() => {
+ (async () => {
+ if (!ensCache || !originalText.match(ensRegex)) {
+ setUsernameToSearch(originalText);
+ return;
+ }
+
+ const address = await ensCache.getAddressForName(originalText);
+ if (address) {
+ setUsernameToSearch(address);
+ } else {
+ setUsernameToSearch(originalText);
+ }
+ })();
+ }, [ensCache, originalText]);
+
+ return usernameToSearch;
+}
+
function useSearchUsers(
usernameInputText: string,
): $ReadOnlyArray<GlobalAccountUserInfo> {
const currentUserID = useSelector(
state => state.currentUserInfo && state.currentUserInfo.id,
);
+ const forwardLookupSearchText = useForwardLookupSearchText(usernameInputText);
const [serverSearchResults, setServerSearchResults] = React.useState<
$ReadOnlyArray<GlobalAccountUserInfo>,
@@ -278,11 +307,11 @@
const dispatchActionPromise = useDispatchActionPromise();
React.useEffect(() => {
const searchUsersPromise = (async () => {
- if (usernameInputText.length === 0) {
+ if (forwardLookupSearchText.length === 0) {
setServerSearchResults([]);
} else {
try {
- const { userInfos } = await callSearchUsers(usernameInputText);
+ const { userInfos } = await callSearchUsers(forwardLookupSearchText);
setServerSearchResults(
userInfos.filter(({ id }) => id !== currentUserID),
);
@@ -296,7 +325,7 @@
callSearchUsers,
currentUserID,
dispatchActionPromise,
- usernameInputText,
+ forwardLookupSearchText,
]);
return serverSearchResults;
@@ -343,4 +372,5 @@
useSearchMessages,
useSearchUsers,
filterChatMessageInfosForSearch,
+ useForwardLookupSearchText,
};
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -11,6 +11,7 @@
import { extractUserMentionsFromText } from './mention-utils.js';
import { getMessageTitle, isInvalidSidebarSource } from './message-utils.js';
import { relationshipBlockedInEitherDirection } from './relationship-utils.js';
+import { useForwardLookupSearchText } from './search-utils.js';
import threadWatcher from './thread-watcher.js';
import {
fetchMostRecentMessagesActionTypes,
@@ -1581,6 +1582,7 @@
): ThreadListSearchResult {
const callSearchUsers = useServerCall(searchUserCall);
const usersWithPersonalThread = useSelector(usersWithPersonalThreadSelector);
+ const forwardLookupSearchText = useForwardLookupSearchText(searchText);
const searchUsers = React.useCallback(
async (usernamePrefix: string) => {
if (usernamePrefix.length === 0) {
@@ -1604,10 +1606,10 @@
(async () => {
const results = threadSearchIndex.getSearchResults(searchText);
setThreadSearchResults(new Set(results));
- const usersResults = await searchUsers(searchText);
+ const usersResults = await searchUsers(forwardLookupSearchText);
setUsersSearchResults(usersResults);
})();
- }, [searchText, threadSearchIndex, searchUsers]);
+ }, [searchText, forwardLookupSearchText, threadSearchIndex, searchUsers]);
return { threadSearchResults, usersSearchResults };
}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 11:47 AM (1 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2584459
Default Alt Text
D9885.id33219.diff (4 KB)

Event Timeline