Skip to content

Commit

Permalink
[lib] Include the rawChatName when constructing the chat mention sear…
Browse files Browse the repository at this point in the history
…ch index

Summary:
This diff is the final one in the stack. It allows us to actually @-mention a chat with ENS users with a cleared name by the member's wallet addresses. This is done in the same way we construct our search indexes for users - we take all possible search terms into an array for the thread ID and then join them by a space. For reference, here is the code for the [[ https://github.com/CommE2E/comm/blob/165d35ab1a3ff1ff5d776763a899101d03d4d0f9/lib/selectors/nav-selectors.js#L115 | user search index ]].

Part of [[ https://linear.app/comm/issue/ENG-5436/update-usechatmentioncandidatesobjandutils-to-support-ing-chats-by | ENG-5436 ]]

Depends on D10460

Test Plan:
Please see the videos below where I can now @-mention the chat both by ENS name and wallet addresses.

{F1007657}

{F1007714}

Reviewers: atul, ginsu, inka

Reviewed By: inka

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D10461
  • Loading branch information
RohanK6 committed Dec 29, 2023
1 parent 9e834fe commit 610946a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/components/chat-mention-provider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ThreadInfo,
} from '../types/thread-types.js';
import { useResolvedThreadInfosObj } from '../utils/entity-helpers.js';
import { getNameForThreadEntity } from '../utils/entity-text.js';
import { useSelector } from '../utils/redux-utils.js';

type Props = {
Expand Down Expand Up @@ -245,14 +246,23 @@ function useChatMentionSearchIndex(
uiName:
chatMentionCandidatesObj[communityThreadID][threadID].threadInfo
.uiName,
rawChatName:
chatMentionCandidatesObj[communityThreadID][threadID].rawChatName,
});
}
// Sort the keys so that the order of the search result is consistent
searchIndexEntries.sort(({ uiName: uiNameA }, { uiName: uiNameB }) =>
uiNameA.localeCompare(uiNameB),
);
for (const { id, uiName } of searchIndexEntries) {
searchIndex.addEntry(id, uiName);
for (const { id, uiName, rawChatName } of searchIndexEntries) {
const names = [uiName];
if (rawChatName) {
typeof rawChatName === 'string'
? names.push(rawChatName)
: names.push(getNameForThreadEntity(rawChatName));
}

searchIndex.addEntry(id, names.join(' '));
}
result[communityThreadID] = searchIndex;
}
Expand Down
1 change: 1 addition & 0 deletions lib/utils/entity-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ export {
ET,
entityTextToRawString,
entityTextToReact,
getNameForThreadEntity,
pluralizeEntityText,
useENSNamesForEntityText,
useEntityTextAsString,
Expand Down

0 comments on commit 610946a

Please sign in to comment.