您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

MessageRecipient.tsx 4.7KB

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