Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // @flow
  2. import { useIsFocused } from '@react-navigation/native';
  3. import React, { useEffect } from 'react';
  4. import { translate } from '../../../base/i18n';
  5. import JitsiScreen from '../../../base/modal/components/JitsiScreen';
  6. import { connect } from '../../../base/redux';
  7. import { closeChat, openChat } from '../../actions.native';
  8. import AbstractChat, {
  9. _mapStateToProps,
  10. type Props as AbstractProps
  11. } from '../AbstractChat';
  12. import ChatInputBar from './ChatInputBar';
  13. import MessageContainer from './MessageContainer';
  14. import MessageRecipient from './MessageRecipient';
  15. import styles from './styles';
  16. type Props = AbstractProps & {
  17. /**
  18. * Is this screen focused or not(React Navigation).
  19. */
  20. isChatScreenFocused: boolean,
  21. /**
  22. * Default prop for navigating between screen components(React Navigation).
  23. */
  24. navigation: Object,
  25. /**
  26. * Default prop for navigating between screen components(React Navigation).
  27. */
  28. route: Object
  29. };
  30. /**
  31. * Implements a React native component that renders the chat window (modal) of
  32. * the mobile client.
  33. */
  34. class Chat extends AbstractChat<Props> {
  35. /**
  36. * Implements React's {@link Component#render()}.
  37. *
  38. * @inheritdoc
  39. */
  40. render() {
  41. const { _messages, route } = this.props;
  42. const privateMessageRecipient = route.params?.privateMessageRecipient;
  43. return (
  44. <JitsiScreen
  45. hasBottomTextInput = { true }
  46. hasTabNavigator = { true }
  47. style = { styles.chatContainer }>
  48. <MessageContainer messages = { _messages } />
  49. <MessageRecipient privateMessageRecipient = { privateMessageRecipient } />
  50. <ChatInputBar onSend = { this._onSendMessage } />
  51. </JitsiScreen>
  52. );
  53. }
  54. _onSendMessage: (string) => void;
  55. }
  56. export default translate(connect(_mapStateToProps)(props => {
  57. const {
  58. _nbUnreadMessages,
  59. dispatch,
  60. navigation,
  61. route,
  62. t
  63. } = props;
  64. const isChatScreenFocused = useIsFocused();
  65. const privateMessageRecipient = route.params?.privateMessageRecipient;
  66. const nrUnreadMessages
  67. = !isChatScreenFocused && _nbUnreadMessages > 0
  68. ? `(${_nbUnreadMessages})` : '';
  69. useEffect(() => {
  70. dispatch(openChat(privateMessageRecipient));
  71. navigation.setOptions({
  72. tabBarLabel: `${t('chat.tabs.chat')} ${nrUnreadMessages}`
  73. });
  74. return () => dispatch(closeChat());
  75. }, [ nrUnreadMessages ]);
  76. return (
  77. <Chat
  78. { ...props }
  79. isChatScreenFocused = { isChatScreenFocused } />
  80. );
  81. }));