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

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