Page MenuHomePhorge

D7771.1765257436.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D7771.1765257436.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
@@ -1,17 +1,28 @@
// @flow
+import * as React from 'react';
+
import SearchIndex from './search-index.js';
import {
userIsMember,
threadMemberHasPermission,
getContainingThreadID,
} from './thread-utils.js';
+import {
+ searchMessages,
+ searchMessagesActionTypes,
+} from '../actions/message-actions.js';
import genesis from '../facts/genesis.js';
+import type { RawMessageInfo } from '../types/message-types.js';
import { userRelationshipStatus } from '../types/relationship-types.js';
import { threadPermissions } from '../types/thread-permission-types.js';
import { type ThreadType, threadTypes } from '../types/thread-types-enum.js';
import { type ThreadInfo } from '../types/thread-types.js';
import type { AccountUserInfo, UserListItem } from '../types/user-types.js';
+import {
+ useServerCall,
+ useDispatchActionPromise,
+} from '../utils/action-utils.js';
const notFriendNotice = 'not friend';
@@ -169,4 +180,37 @@
);
}
-export { getPotentialMemberItems, notFriendNotice };
+function useSearchMessages(): (
+ query: string,
+ threadID: string,
+ onResultsReceived: (
+ messages: $ReadOnlyArray<RawMessageInfo>,
+ endReached: boolean,
+ ) => mixed,
+ cursor?: string,
+) => void {
+ const callSearchMessages = useServerCall(searchMessages);
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(
+ (query, threadID, onResultsReceived, cursor) => {
+ const searchMessagesPromise = (async () => {
+ if (query === '') {
+ onResultsReceived([], true);
+ return;
+ }
+ const { messages, endReached } = await callSearchMessages({
+ query,
+ threadID,
+ cursor,
+ });
+ onResultsReceived(messages, endReached);
+ })();
+
+ dispatchActionPromise(searchMessagesActionTypes, searchMessagesPromise);
+ },
+ [callSearchMessages, dispatchActionPromise],
+ );
+}
+
+export { getPotentialMemberItems, notFriendNotice, useSearchMessages };

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 9, 5:17 AM (17 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5848562
Default Alt Text
D7771.1765257436.diff (2 KB)

Event Timeline