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.

MessageRecipient.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import React from 'react';
  2. import { Text, TouchableHighlight, View } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { translate } from '../../../base/i18n/functions';
  5. import Icon from '../../../base/icons/components/Icon';
  6. import { IconCloseLarge } from '../../../base/icons/svg';
  7. import {
  8. setParams
  9. } from '../../../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  10. import { setLobbyChatActiveState, setPrivateMessageRecipient } from '../../actions.any';
  11. import AbstractMessageRecipient, {
  12. type Props as AbstractProps
  13. } from '../AbstractMessageRecipient';
  14. import styles from './styles';
  15. type Props = AbstractProps & {
  16. /**
  17. * The Redux dispatch function.
  18. */
  19. dispatch: Function,
  20. /**
  21. * Is lobby messaging active.
  22. */
  23. isLobbyChatActive: boolean,
  24. /**
  25. * The participant string for lobby chat messaging.
  26. */
  27. lobbyMessageRecipient: Object,
  28. /**
  29. * The participant object set for private messaging.
  30. */
  31. privateMessageRecipient: Object,
  32. };
  33. /**
  34. * Class to implement the displaying of the recipient of the next message.
  35. */
  36. class MessageRecipient extends AbstractMessageRecipient<Props> {
  37. /**
  38. * Constructor of the component.
  39. *
  40. * @param {Props} props - The props of the component.
  41. */
  42. constructor(props: Props) {
  43. super(props);
  44. this._onResetPrivateMessageRecipient = this._onResetPrivateMessageRecipient.bind(this);
  45. this._onResetLobbyMessageRecipient = this._onResetLobbyMessageRecipient.bind(this);
  46. }
  47. _onResetLobbyMessageRecipient: () => void;
  48. /**
  49. * Resets lobby message recipient from state.
  50. *
  51. * @returns {void}
  52. */
  53. _onResetLobbyMessageRecipient() {
  54. const { dispatch } = this.props;
  55. dispatch(setLobbyChatActiveState(false));
  56. }
  57. _onResetPrivateMessageRecipient: () => void;
  58. /**
  59. * Resets private message recipient from state.
  60. *
  61. * @returns {void}
  62. */
  63. _onResetPrivateMessageRecipient() {
  64. const { dispatch } = this.props;
  65. dispatch(setPrivateMessageRecipient());
  66. setParams({
  67. privateMessageRecipient: undefined
  68. });
  69. }
  70. /**
  71. * Implements {@code PureComponent#render}.
  72. *
  73. * @inheritdoc
  74. * @returns {ReactElement}
  75. */
  76. render() {
  77. const {
  78. isLobbyChatActive,
  79. lobbyMessageRecipient,
  80. privateMessageRecipient,
  81. t
  82. } = this.props;
  83. if (isLobbyChatActive) {
  84. return (
  85. <View style = { styles.lobbyMessageRecipientContainer }>
  86. <Text style = { styles.messageRecipientText }>
  87. { t('chat.lobbyChatMessageTo', {
  88. recipient: lobbyMessageRecipient.name
  89. }) }
  90. </Text>
  91. <TouchableHighlight
  92. onPress = { this._onResetLobbyMessageRecipient }>
  93. <Icon
  94. src = { IconCloseLarge }
  95. style = { styles.messageRecipientCancelIcon } />
  96. </TouchableHighlight>
  97. </View>
  98. );
  99. }
  100. if (!privateMessageRecipient) {
  101. return null;
  102. }
  103. return (
  104. <View style = { styles.messageRecipientContainer }>
  105. <Text style = { styles.messageRecipientText }>
  106. { t('chat.messageTo', {
  107. recipient: privateMessageRecipient.name
  108. }) }
  109. </Text>
  110. <TouchableHighlight
  111. onPress = { this._onResetPrivateMessageRecipient }
  112. underlayColor = { 'transparent' }>
  113. <Icon
  114. src = { IconCloseLarge }
  115. style = { styles.messageRecipientCancelIcon } />
  116. </TouchableHighlight>
  117. </View>
  118. );
  119. }
  120. }
  121. /**
  122. * Maps part of the redux state to the props of this component.
  123. *
  124. * @param {Object} state - The Redux state.
  125. * @returns {Props}
  126. */
  127. function _mapStateToProps(state) {
  128. const { lobbyMessageRecipient, isLobbyChatActive } = state['features/chat'];
  129. return {
  130. isLobbyChatActive,
  131. lobbyMessageRecipient
  132. };
  133. }
  134. export default translate(connect(_mapStateToProps)(MessageRecipient));