Page MenuHomePhorge

D7771.1765312910.diff
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

D7771.1765312910.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,12 +1,19 @@
// @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 { SearchMessagesResponse } from '../types/message-types.js';
import { userRelationshipStatus } from '../types/relationship-types.js';
import {
type ThreadInfo,
@@ -15,6 +22,10 @@
threadPermissions,
} 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';
@@ -172,4 +183,32 @@
);
}
-export { getPotentialMemberItems, notFriendNotice };
+function useSearchMessages(
+ query: string,
+ threadID: string,
+ cursor?: string,
+): SearchMessagesResponse {
+ const [searchResults, setSearchResults] = React.useState([]);
+ const [endReached, setEndReached] = React.useState(false);
+
+ const callSearchMessages = useServerCall(searchMessages);
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ React.useEffect(() => {
+ const searchMessagesPromise = (async () => {
+ const { messages, endReached: end } = await callSearchMessages({
+ query,
+ threadID,
+ cursor,
+ });
+ setSearchResults(messages);
+ setEndReached(end);
+ })();
+
+ dispatchActionPromise(searchMessagesActionTypes, searchMessagesPromise);
+ }, [callSearchMessages, query, threadID, cursor, dispatchActionPromise]);
+
+ return { messages: searchResults, endReached };
+}
+
+export { getPotentialMemberItems, notFriendNotice, useSearchMessages };

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 9, 8:41 PM (11 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5857672
Default Alt Text
D7771.1765312910.diff (1 KB)

Event Timeline