Skip to content

Commit

Permalink
stream action buttons: Implement search messages in stream
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentCruzer committed Feb 18, 2022
1 parent fe6e01a commit 2246e6b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/action-sheets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ import type { PmKeyRecipients } from '../utils/recipient';
import { isTopicMuted } from '../mute/muteModel';
import * as api from '../api';
import { showToast } from '../utils/info';
import { doNarrow, deleteOutboxMessage, navigateToEmojiPicker, navigateToStream } from '../actions';
import {
doNarrow,
deleteOutboxMessage,
navigateToEmojiPicker,
navigateToStream,
navigateToSearch,
} from '../actions';
import {
navigateToMessageReactionScreen,
navigateToPmConversationDetails,
Expand Down Expand Up @@ -236,6 +242,12 @@ const unsubscribe = async ({ auth, streamId, subscriptions }) => {
unsubscribe.title = 'Unsubscribe';
unsubscribe.errorMessage = 'Failed to unsubscribe';

const searchMessage = ({ streamId }) => {
NavigationService.dispatch(navigateToSearch(streamId));
};
searchMessage.title = 'Search Message';
searchMessage.errorMessage = 'Failed to open search';

const pinToTop = async ({ auth, streamId }) => {
await api.setSubscriptionProperty(auth, streamId, 'pin_to_top', true);
};
Expand Down Expand Up @@ -339,6 +351,7 @@ export const constructStreamActionButtons = ({
buttons.push(subscribe);
}
buttons.push(showStreamSettings);
buttons.push(searchMessage);
buttons.push(cancel);
return buttons;
};
Expand Down
3 changes: 2 additions & 1 deletion src/nav/navActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const replaceWithChat = (narrow: Narrow): GenericNavigationAction =>

export const navigateToUsersScreen = (): GenericNavigationAction => StackActions.push('users');

export const navigateToSearch = (): GenericNavigationAction => StackActions.push('search-messages');
export const navigateToSearch = (streamId?: number): GenericNavigationAction =>
StackActions.push('search-messages', { streamId });

export const navigateToEmojiPicker = (messageId: number): GenericNavigationAction =>
StackActions.push('emoji-picker', { messageId });
Expand Down
6 changes: 3 additions & 3 deletions src/search/SearchMessagesScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { fetchMessages } from '../message/fetchActions';
type OuterProps = $ReadOnly<{|
// These should be passed from React Navigation
navigation: AppNavigationProp<'search-messages'>,
route: RouteProp<'search-messages', void>,
route: RouteProp<'search-messages', {| streamId: number |}>,
|}>;

type SelectorProps = $ReadOnly<{|
Expand Down Expand Up @@ -65,7 +65,7 @@ class SearchMessagesScreenInner extends PureComponent<Props, State> {
*/
fetchSearchMessages = async (query: string): Promise<$ReadOnlyArray<Message>> => {
const fetchArgs = {
narrow: SEARCH_NARROW(query),
narrow: SEARCH_NARROW(query, this.props.route.params.streamId),
anchor: LAST_MESSAGE_ANCHOR,
numBefore: 20,
numAfter: 0,
Expand Down Expand Up @@ -144,7 +144,7 @@ class SearchMessagesScreenInner extends PureComponent<Props, State> {
<SearchMessagesCard
messages={messages}
isFetching={isFetching}
narrow={SEARCH_NARROW(this.state.query)}
narrow={SEARCH_NARROW(this.state.query, this.props.route.params.streamId)}
/>
</Screen>
);
Expand Down
2 changes: 2 additions & 0 deletions static/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@
"Failed to delete topic": "Failed to delete topic",
"Stream settings": "Stream settings",
"Failed to show stream settings": "Failed to show stream settings",
"Search Message": "Search Message",
"Failed to open search": "Failed to open search",
"show": "show",
"hide": "hide",
"Debug": "Debug",
Expand Down

0 comments on commit 2246e6b

Please sign in to comment.