Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3529822
D9704.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D9704.diff
View Options
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
@@ -2,6 +2,7 @@
import * as React from 'react';
+import { messageID } from './message-utils.js';
import SearchIndex from './search-index.js';
import {
userIsMember,
@@ -20,10 +21,8 @@
import type {
ChatMessageInfoItem,
MessageListData,
- ChatMessageItem,
} from '../selectors/chat-selectors.js';
import type { MessageInfo, RawMessageInfo } from '../types/message-types.js';
-import { isComposableMessageType } from '../types/message-types.js';
import type { MinimallyEncodedThreadInfo } from '../types/minimally-encoded-thread-permissions-types.js';
import { userRelationshipStatus } from '../types/relationship-types.js';
import { threadPermissions } from '../types/thread-permission-types.js';
@@ -137,12 +136,19 @@
let userResults = values(results);
if (text === '') {
- userResults = userResults.filter(userInfo =>
- containingThreadInfo
- ? userInfo.isMemberOfContainingThread &&
- !blockedRelationshipsStatuses.has(userInfo.relationshipStatus)
- : userInfo?.relationshipStatus === userRelationshipStatus.FRIEND,
- );
+ userResults = userResults.filter(userInfo => {
+ if (!containingThreadInfo) {
+ return userInfo.relationshipStatus === userRelationshipStatus.FRIEND;
+ }
+ if (!userInfo.isMemberOfContainingThread) {
+ return false;
+ }
+ const { relationshipStatus } = userInfo;
+ if (!relationshipStatus) {
+ return true;
+ }
+ return !blockedRelationshipsStatuses.has(relationshipStatus);
+ });
}
const nonFriends = [];
@@ -152,8 +158,11 @@
const parentThreadMembers = [];
for (const userResult of userResults) {
- const relationshipStatus = userResult.relationshipStatus;
- if (blockedRelationshipsStatuses.has(relationshipStatus)) {
+ const { relationshipStatus } = userResult;
+ if (
+ relationshipStatus &&
+ blockedRelationshipsStatuses.has(relationshipStatus)
+ ) {
blockedUsers.push(userResult);
} else if (userResult.isMemberOfParentThread) {
parentThreadMembers.push(userResult);
@@ -181,7 +190,10 @@
}) => {
let notice, alert;
const username = result.username;
- if (blockedRelationshipsStatuses.has(relationshipStatus)) {
+ if (
+ relationshipStatus &&
+ blockedRelationshipsStatuses.has(relationshipStatus)
+ ) {
notice = 'user is blocked';
alert = {
title: 'User is blocked',
@@ -312,31 +324,28 @@
return null;
}
- const idSet = new Set(translatedSearchResults.map(item => item.id));
-
- const chatMessageInfoItems = chatMessageInfos.filter(
- item =>
- item.messageInfo &&
- idSet.has(item.messageInfo.id) &&
- isComposableMessageType(item.messageInfo.type),
- );
+ const idSet = new Set(translatedSearchResults.map(messageID));
- const uniqueChatMessageInfoItemsMap = new Map<string, ChatMessageItem>();
- chatMessageInfoItems.forEach(
- item =>
- item.messageInfo &&
- item.messageInfo.id &&
- uniqueChatMessageInfoItemsMap.set(item.messageInfo.id, item),
- );
+ const uniqueChatMessageInfoItemsMap = new Map<string, ChatMessageInfoItem>();
+ for (const item of chatMessageInfos) {
+ if (item.itemType !== 'message' || item.messageInfoType !== 'composable') {
+ continue;
+ }
+ const id = messageID(item.messageInfo);
+ if (idSet.has(id)) {
+ uniqueChatMessageInfoItemsMap.set(id, item);
+ }
+ }
- const sortedChatMessageInfoItems = [];
+ const sortedChatMessageInfoItems: ChatMessageInfoItem[] = [];
for (let i = 0; i < translatedSearchResults.length; i++) {
- sortedChatMessageInfoItems.push(
- uniqueChatMessageInfoItemsMap.get(translatedSearchResults[i].id),
- );
+ const id = messageID(translatedSearchResults[i]);
+ const match = uniqueChatMessageInfoItemsMap.get(id);
+ if (match) {
+ sortedChatMessageInfoItems.push(match);
+ }
}
-
- return sortedChatMessageInfoItems.filter(Boolean);
+ return sortedChatMessageInfoItems;
}
export {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 25, 9:22 PM (11 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2703212
Default Alt Text
D9704.diff (4 KB)
Attached To
Mode
D9704: [Flow202][lib][skip-ci] [12/23] Fix Flow issues with search-utils.js
Attached
Detach File
Event Timeline
Log In to Comment