You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Chat.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. hasTabNavigator = { true }
  46. style = { styles.chatContainer }>
  47. <MessageContainer messages = { _messages } />
  48. <MessageRecipient privateMessageRecipient = { privateMessageRecipient } />
  49. <ChatInputBar onSend = { this._onSendMessage } />
  50. </JitsiScreen>
  51. );
  52. }
  53. _onSendMessage: (string) => void;
  54. }
  55. export default translate(connect(_mapStateToProps)(props => {
  56. const {
  57. _nbUnreadMessages,
  58. dispatch,
  59. navigation,
  60. route,
  61. t
  62. } = props;
  63. const isChatScreenFocused = useIsFocused();
  64. const privateMessageRecipient = route.params?.privateMessageRecipient;
  65. const nrUnreadMessages
  66. = !isChatScreenFocused && _nbUnreadMessages > 0
  67. ? `(${_nbUnreadMessages})` : '';
  68. useEffect(() => {
  69. dispatch(openChat(privateMessageRecipient));
  70. navigation.setOptions({
  71. tabBarLabel: `${t('chat.tabs.chat')} ${nrUnreadMessages}`
  72. });
  73. return () => dispatch(closeChat());
  74. }, [ nrUnreadMessages ]);
  75. return (
  76. <Chat
  77. { ...props }
  78. isChatScreenFocused = { isChatScreenFocused } />
  79. );
  80. }));