Rocket.Chat.ReactNative/app/views/ForwardMessageView/index.tsx

105 lines
3.7 KiB
TypeScript
Raw Permalink Normal View History

import React, { useLayoutEffect, useState } from 'react';
import { Alert, ScrollView, View } from 'react-native';
import { StackNavigationOptions } from '@react-navigation/stack';
import { RouteProp, StackActions, useNavigation, useRoute } from '@react-navigation/native';
import { getPermalinkMessage } from '../../lib/methods';
import KeyboardView from '../../containers/KeyboardView';
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
import I18n from '../../i18n';
import * as HeaderButton from '../../containers/HeaderButton';
import StatusBar from '../../containers/StatusBar';
import { useTheme } from '../../theme';
import { getUserSelector } from '../../selectors/login';
import SafeAreaView from '../../containers/SafeAreaView';
import styles from './styles';
import SelectPersonOrChannel from './SelectPersonOrChannel';
import { useAppSelector } from '../../lib/hooks';
import { NewMessageStackParamList } from '../../stacks/types';
import { postMessage } from '../../lib/services/restApi';
import MessagePreview from '../../containers/message/Preview';
import EventEmitter from '../../lib/methods/helpers/events';
import { LISTENER } from '../../containers/Toast';
const ForwardMessageView = () => {
const [rooms, setRooms] = useState<string[]>([]);
const [sending, setSending] = useState(false);
const navigation = useNavigation();
const { colors } = useTheme();
const {
params: { message }
} = useRoute<RouteProp<NewMessageStackParamList, 'ForwardMessageView'>>();
const { blockUnauthenticatedAccess, server, serverVersion, user } = useAppSelector(state => ({
user: getUserSelector(state),
server: state.server.server,
blockUnauthenticatedAccess: !!state.settings.Accounts_AvatarBlockUnauthenticatedAccess ?? true,
serverVersion: state.server.version as string
}));
useLayoutEffect(() => {
const isSendButtonEnabled = rooms.length && !sending;
navigation.setOptions({
title: I18n.t('Forward_message'),
headerRight: () => (
<HeaderButton.Container>
<HeaderButton.Item
title={I18n.t('Send')}
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
color={isSendButtonEnabled ? colors.fontHint : colors.fontSecondaryInfo}
disabled={!isSendButtonEnabled}
onPress={handlePostMessage}
testID='forward-message-view-send'
/>
</HeaderButton.Container>
),
headerLeft: () => <HeaderButton.CloseModal />
} as StackNavigationOptions);
}, [rooms.length, navigation, sending]);
const handlePostMessage = async () => {
setSending(true);
const permalink = await getPermalinkMessage(message);
const msg = `[ ](${permalink})\n`;
try {
await Promise.all(rooms.map(roomId => postMessage(roomId, msg)));
EventEmitter.emit(LISTENER, { message: I18n.t('Message_has_been_shared') });
navigation.dispatch(StackActions.pop());
} catch (e: any) {
Alert.alert(I18n.t('Oops'), e.message);
}
setSending(false);
};
const selectRooms = ({ value }: { value: string[] }) => {
setRooms(value);
};
return (
<KeyboardView
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
style={{ backgroundColor: colors.surfaceHover }}
contentContainerStyle={styles.container}
keyboardVerticalOffset={128}
>
<StatusBar />
<SafeAreaView testID='forward-message-view' style={styles.container}>
<ScrollView {...scrollPersistTaps}>
<SelectPersonOrChannel
server={server}
userId={user.id}
token={user.token}
onRoomSelect={selectRooms}
blockUnauthenticatedAccess={blockUnauthenticatedAccess}
serverVersion={serverVersion}
/>
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<View pointerEvents='none' style={[styles.messageContainer, { backgroundColor: colors.surfaceRoom }]}>
<MessagePreview message={message} />
</View>
</ScrollView>
</SafeAreaView>
</KeyboardView>
);
};
export default ForwardMessageView;