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.7KB

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 { screen } from '../../../conference/components/native/routes';
  8. import { closeChat, openChat } from '../../actions.native';
  9. import AbstractChat, {
  10. _mapStateToProps,
  11. type Props as AbstractProps
  12. } from '../AbstractChat';
  13. import ChatInputBar from './ChatInputBar';
  14. import MessageContainer from './MessageContainer';
  15. import MessageRecipient from './MessageRecipient';
  16. import styles from './styles';
  17. type Props = AbstractProps & {
  18. /**
  19. * Is this screen focused or not(React Navigation)
  20. */
  21. isChatScreenFocused: boolean,
  22. /**
  23. * Default prop for navigating between screen components(React Navigation)
  24. */
  25. navigation: Object,
  26. /**
  27. * Default prop for navigating between screen components(React Navigation)
  28. */
  29. route: Object
  30. };
  31. /**
  32. * Implements a React native component that renders the chat window (modal) of
  33. * the mobile client.
  34. */
  35. class Chat extends AbstractChat<Props> {
  36. /**
  37. * Implements React's {@link Component#render()}.
  38. *
  39. * @inheritdoc
  40. */
  41. render() {
  42. const { _messages, route } = this.props;
  43. const privateMessageRecipient = route.params?.privateMessageRecipient;
  44. return (
  45. <JitsiScreen
  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. } = 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: `${screen.conference.chatandpolls.tab.chat} ${nrUnreadMessages}`
  72. });
  73. return () => dispatch(closeChat());
  74. }, [ nrUnreadMessages ]);
  75. return (
  76. <Chat
  77. { ...props }
  78. isChatScreenFocused = { isChatScreenFocused } />
  79. );
  80. }));