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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // @flow
  2. import React from 'react';
  3. import { View } from 'react-native';
  4. import { Button } from 'react-native-paper';
  5. import { translate } from '../../../base/i18n';
  6. import { JitsiModal } from '../../../base/modal';
  7. import { connect } from '../../../base/redux';
  8. import { PollsPane } from '../../../polls/components';
  9. import { closeChat } from '../../actions.any';
  10. import { BUTTON_MODES, CHAT_VIEW_MODAL_ID } from '../../constants';
  11. import AbstractChat, {
  12. _mapStateToProps,
  13. type Props
  14. } from '../AbstractChat';
  15. import ChatInputBar from './ChatInputBar';
  16. import MessageContainer from './MessageContainer';
  17. import MessageRecipient from './MessageRecipient';
  18. import styles from './styles';
  19. /**
  20. * Implements a React native component that renders the chat window (modal) of
  21. * the mobile client.
  22. */
  23. class Chat extends AbstractChat<Props> {
  24. /**
  25. * Creates a new instance.
  26. *
  27. * @inheritdoc
  28. */
  29. constructor(props: Props) {
  30. super(props);
  31. this._onClose = this._onClose.bind(this);
  32. }
  33. /**
  34. * Implements React's {@link Component#render()}.
  35. *
  36. * @inheritdoc
  37. */
  38. render() {
  39. return (
  40. <JitsiModal
  41. headerProps = {{
  42. headerLabelKey: 'chat.title'
  43. }}
  44. modalId = { CHAT_VIEW_MODAL_ID }
  45. onClose = { this._onClose }>
  46. {this.props._isPollsEnabled && <View style = { styles.tabContainer }>
  47. <Button
  48. color = '#17a0db'
  49. mode = {
  50. this.props._isPollsTabFocused
  51. ? BUTTON_MODES.CONTAINED
  52. : BUTTON_MODES.TEXT
  53. }
  54. onPress = { this._onToggleChatTab }
  55. style = { styles.tabLeftButton }
  56. uppercase = { false }>
  57. {`${this.props.t('chat.tabs.chat')}${this.props._isPollsTabFocused
  58. && this.props._nbUnreadMessages > 0
  59. ? `(${this.props._nbUnreadMessages})`
  60. : ''
  61. }`}
  62. </Button>
  63. <Button
  64. color = '#17a0db'
  65. mode = {
  66. this.props._isPollsTabFocused
  67. ? BUTTON_MODES.TEXT
  68. : BUTTON_MODES.CONTAINED
  69. }
  70. onPress = { this._onTogglePollsTab }
  71. style = { styles.tabRightButton }
  72. uppercase = { false }>
  73. {`${this.props.t('chat.tabs.polls')}${!this.props._isPollsTabFocused
  74. && this.props._nbUnreadPolls > 0
  75. ? `(${this.props._nbUnreadPolls})`
  76. : ''
  77. }`}
  78. </Button>
  79. </View>}
  80. {this.props._isPollsTabFocused
  81. ? <PollsPane />
  82. : (
  83. <>
  84. <MessageContainer messages = { this.props._messages } />
  85. <MessageRecipient />
  86. <ChatInputBar onSend = { this._onSendMessage } />
  87. </>
  88. )}
  89. </JitsiModal>
  90. );
  91. }
  92. _onSendMessage: (string) => void;
  93. _onClose: () => boolean
  94. _onTogglePollsTab: () => void;
  95. _onToggleChatTab: () => void;
  96. /**
  97. * Closes the modal.
  98. *
  99. * @returns {boolean}
  100. */
  101. _onClose() {
  102. this.props.dispatch(closeChat());
  103. return true;
  104. }
  105. }
  106. export default translate(connect(_mapStateToProps)(Chat));