2018-09-11 16:32:52 +00:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2019-03-01 16:49:11 +00:00
|
|
|
View, Text, ViewPropTypes, TouchableWithoutFeedback
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2018-09-11 16:32:52 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
import { KeyboardUtils } from 'react-native-keyboard-input';
|
2019-04-08 12:35:28 +00:00
|
|
|
import Touchable from 'react-native-platform-touchable';
|
2019-04-24 18:36:29 +00:00
|
|
|
import { emojify } from 'react-emojione';
|
2019-04-25 17:18:49 +00:00
|
|
|
import removeMarkdown from 'remove-markdown';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
|
|
|
import Image from './Image';
|
|
|
|
import User from './User';
|
|
|
|
import Avatar from '../Avatar';
|
|
|
|
import Audio from './Audio';
|
|
|
|
import Video from './Video';
|
|
|
|
import Markdown from './Markdown';
|
|
|
|
import Url from './Url';
|
|
|
|
import Reply from './Reply';
|
|
|
|
import ReactionsModal from './ReactionsModal';
|
|
|
|
import Emoji from './Emoji';
|
|
|
|
import styles from './styles';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import messagesStatus from '../../constants/messagesStatus';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2019-04-08 12:35:28 +00:00
|
|
|
import { COLOR_DANGER } from '../../constants/colors';
|
2019-04-25 17:18:49 +00:00
|
|
|
import debounce from '../../utils/debounce';
|
2018-09-11 16:32:52 +00:00
|
|
|
|
|
|
|
const SYSTEM_MESSAGES = [
|
|
|
|
'r',
|
|
|
|
'au',
|
|
|
|
'ru',
|
|
|
|
'ul',
|
|
|
|
'uj',
|
2019-04-08 12:35:28 +00:00
|
|
|
'ut',
|
2018-09-11 16:32:52 +00:00
|
|
|
'rm',
|
|
|
|
'user-muted',
|
|
|
|
'user-unmuted',
|
|
|
|
'message_pinned',
|
|
|
|
'subscription-role-added',
|
|
|
|
'subscription-role-removed',
|
|
|
|
'room_changed_description',
|
|
|
|
'room_changed_announcement',
|
|
|
|
'room_changed_topic',
|
2018-12-12 15:15:10 +00:00
|
|
|
'room_changed_privacy',
|
2019-04-08 12:35:28 +00:00
|
|
|
'message_snippeted',
|
|
|
|
'thread-created'
|
2018-09-11 16:32:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const getInfoMessage = ({
|
2018-09-26 19:38:06 +00:00
|
|
|
type, role, msg, author
|
2018-09-11 16:32:52 +00:00
|
|
|
}) => {
|
2018-09-26 19:38:06 +00:00
|
|
|
const { username } = author;
|
2018-09-11 16:32:52 +00:00
|
|
|
if (type === 'rm') {
|
|
|
|
return I18n.t('Message_removed');
|
|
|
|
} else if (type === 'uj') {
|
|
|
|
return I18n.t('Has_joined_the_channel');
|
2019-04-08 12:35:28 +00:00
|
|
|
} else if (type === 'ut') {
|
|
|
|
return I18n.t('Has_joined_the_conversation');
|
2018-09-11 16:32:52 +00:00
|
|
|
} else if (type === 'r') {
|
|
|
|
return I18n.t('Room_name_changed', { name: msg, userBy: username });
|
|
|
|
} else if (type === 'message_pinned') {
|
|
|
|
return I18n.t('Message_pinned');
|
|
|
|
} else if (type === 'ul') {
|
|
|
|
return I18n.t('Has_left_the_channel');
|
|
|
|
} else if (type === 'ru') {
|
|
|
|
return I18n.t('User_removed_by', { userRemoved: msg, userBy: username });
|
|
|
|
} else if (type === 'au') {
|
|
|
|
return I18n.t('User_added_by', { userAdded: msg, userBy: username });
|
|
|
|
} else if (type === 'user-muted') {
|
|
|
|
return I18n.t('User_muted_by', { userMuted: msg, userBy: username });
|
|
|
|
} else if (type === 'user-unmuted') {
|
|
|
|
return I18n.t('User_unmuted_by', { userUnmuted: msg, userBy: username });
|
|
|
|
} else if (type === 'subscription-role-added') {
|
|
|
|
return `${ msg } was set ${ role } by ${ username }`;
|
|
|
|
} else if (type === 'subscription-role-removed') {
|
|
|
|
return `${ msg } is no longer ${ role } by ${ username }`;
|
|
|
|
} else if (type === 'room_changed_description') {
|
|
|
|
return I18n.t('Room_changed_description', { description: msg, userBy: username });
|
|
|
|
} else if (type === 'room_changed_announcement') {
|
|
|
|
return I18n.t('Room_changed_announcement', { announcement: msg, userBy: username });
|
|
|
|
} else if (type === 'room_changed_topic') {
|
|
|
|
return I18n.t('Room_changed_topic', { topic: msg, userBy: username });
|
|
|
|
} else if (type === 'room_changed_privacy') {
|
|
|
|
return I18n.t('Room_changed_privacy', { type: msg, userBy: username });
|
2018-12-12 15:15:10 +00:00
|
|
|
} else if (type === 'message_snippeted') {
|
|
|
|
return I18n.t('Created_snippet');
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
2019-04-08 12:35:28 +00:00
|
|
|
const BUTTON_HIT_SLOP = {
|
|
|
|
top: 4, right: 4, bottom: 4, left: 4
|
|
|
|
};
|
2018-09-11 16:32:52 +00:00
|
|
|
|
|
|
|
export default class Message extends PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
baseUrl: PropTypes.string.isRequired,
|
|
|
|
customEmojis: PropTypes.object.isRequired,
|
|
|
|
timeFormat: PropTypes.string.isRequired,
|
2019-04-17 17:01:03 +00:00
|
|
|
customThreadTimeFormat: PropTypes.string,
|
2018-09-11 16:32:52 +00:00
|
|
|
msg: PropTypes.string,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
token: PropTypes.string.isRequired
|
|
|
|
}),
|
|
|
|
author: PropTypes.shape({
|
|
|
|
_id: PropTypes.string.isRequired,
|
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
name: PropTypes.string
|
|
|
|
}),
|
|
|
|
status: PropTypes.any,
|
|
|
|
reactions: PropTypes.any,
|
|
|
|
editing: PropTypes.bool,
|
|
|
|
style: ViewPropTypes.style,
|
|
|
|
archived: PropTypes.bool,
|
|
|
|
broadcast: PropTypes.bool,
|
|
|
|
reactionsModal: PropTypes.bool,
|
|
|
|
type: PropTypes.string,
|
|
|
|
header: PropTypes.bool,
|
|
|
|
avatar: PropTypes.string,
|
|
|
|
alias: PropTypes.string,
|
2018-12-12 15:15:10 +00:00
|
|
|
ts: PropTypes.oneOfType([
|
|
|
|
PropTypes.instanceOf(Date),
|
|
|
|
PropTypes.string
|
|
|
|
]),
|
2018-09-11 16:32:52 +00:00
|
|
|
edited: PropTypes.bool,
|
|
|
|
attachments: PropTypes.oneOfType([
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.object
|
|
|
|
]),
|
|
|
|
urls: PropTypes.oneOfType([
|
|
|
|
PropTypes.array,
|
|
|
|
PropTypes.object
|
|
|
|
]),
|
|
|
|
useRealName: PropTypes.bool,
|
2019-04-08 12:35:28 +00:00
|
|
|
dcount: PropTypes.number,
|
|
|
|
dlm: PropTypes.instanceOf(Date),
|
2019-04-17 17:01:03 +00:00
|
|
|
tmid: PropTypes.string,
|
|
|
|
tcount: PropTypes.number,
|
|
|
|
tlm: PropTypes.instanceOf(Date),
|
|
|
|
tmsg: PropTypes.string,
|
2018-09-11 16:32:52 +00:00
|
|
|
// methods
|
|
|
|
closeReactions: PropTypes.func,
|
|
|
|
onErrorPress: PropTypes.func,
|
|
|
|
onLongPress: PropTypes.func,
|
|
|
|
onReactionLongPress: PropTypes.func,
|
|
|
|
onReactionPress: PropTypes.func,
|
2019-04-08 12:35:28 +00:00
|
|
|
onDiscussionPress: PropTypes.func,
|
2019-04-17 17:01:03 +00:00
|
|
|
onThreadPress: PropTypes.func,
|
2018-09-11 16:32:52 +00:00
|
|
|
replyBroadcast: PropTypes.func,
|
2019-04-17 17:01:03 +00:00
|
|
|
toggleReactionPicker: PropTypes.func,
|
|
|
|
fetchThreadName: PropTypes.func
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
archived: false,
|
|
|
|
broadcast: false,
|
|
|
|
attachments: [],
|
|
|
|
urls: [],
|
|
|
|
reactions: [],
|
|
|
|
onLongPress: () => {}
|
|
|
|
}
|
|
|
|
|
2019-04-25 17:18:49 +00:00
|
|
|
onPress = debounce(() => {
|
2018-09-11 16:32:52 +00:00
|
|
|
KeyboardUtils.dismiss();
|
2019-04-24 18:36:29 +00:00
|
|
|
|
|
|
|
const { onThreadPress, tlm, tmid } = this.props;
|
|
|
|
if ((tlm || tmid) && onThreadPress) {
|
|
|
|
onThreadPress();
|
|
|
|
}
|
2019-04-25 17:18:49 +00:00
|
|
|
}, 300, true)
|
2018-09-11 16:32:52 +00:00
|
|
|
|
2019-03-01 14:40:22 +00:00
|
|
|
onLongPress = () => {
|
|
|
|
const { archived, onLongPress } = this.props;
|
|
|
|
if (this.isInfoMessage() || this.hasError() || archived) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
onLongPress();
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
formatLastMessage = (lm) => {
|
|
|
|
const { customThreadTimeFormat } = this.props;
|
|
|
|
if (customThreadTimeFormat) {
|
|
|
|
return moment(lm).format(customThreadTimeFormat);
|
|
|
|
}
|
|
|
|
return lm ? moment(lm).calendar(null, {
|
|
|
|
lastDay: `[${ I18n.t('Yesterday') }]`,
|
|
|
|
sameDay: 'h:mm A',
|
|
|
|
lastWeek: 'dddd',
|
|
|
|
sameElse: 'MMM D'
|
|
|
|
}) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
formatMessageCount = (count, type) => {
|
|
|
|
const discussion = type === 'discussion';
|
|
|
|
let text = discussion ? I18n.t('No_messages_yet') : null;
|
|
|
|
if (count === 1) {
|
|
|
|
text = `${ count } ${ discussion ? I18n.t('message') : I18n.t('reply') }`;
|
|
|
|
} else if (count > 1 && count < 1000) {
|
|
|
|
text = `${ count } ${ discussion ? I18n.t('messages') : I18n.t('replies') }`;
|
|
|
|
} else if (count > 999) {
|
|
|
|
text = `+999 ${ discussion ? I18n.t('messages') : I18n.t('replies') }`;
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
isInfoMessage = () => {
|
|
|
|
const { type } = this.props;
|
|
|
|
return SYSTEM_MESSAGES.includes(type);
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
isOwn = () => {
|
|
|
|
const { author, user } = this.props;
|
|
|
|
return author._id === user.id;
|
|
|
|
}
|
2018-09-11 16:32:52 +00:00
|
|
|
|
|
|
|
isDeleted() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { type } = this.props;
|
|
|
|
return type === 'rm';
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isTemp() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { status } = this.props;
|
|
|
|
return status === messagesStatus.TEMP || status === messagesStatus.ERROR;
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hasError() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { status } = this.props;
|
|
|
|
return status === messagesStatus.ERROR;
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderAvatar = () => {
|
|
|
|
const {
|
2019-02-07 19:58:20 +00:00
|
|
|
header, avatar, author, baseUrl, user
|
2018-09-11 16:32:52 +00:00
|
|
|
} = this.props;
|
|
|
|
if (header) {
|
|
|
|
return (
|
|
|
|
<Avatar
|
|
|
|
style={styles.avatar}
|
|
|
|
text={avatar ? '' : author.username}
|
|
|
|
size={36}
|
|
|
|
borderRadius={4}
|
|
|
|
avatar={avatar}
|
|
|
|
baseUrl={baseUrl}
|
2019-04-18 20:57:35 +00:00
|
|
|
userId={user.id}
|
|
|
|
token={user.token}
|
2018-09-11 16:32:52 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderUsername = () => {
|
|
|
|
const {
|
|
|
|
header, timeFormat, author, alias, ts, useRealName
|
|
|
|
} = this.props;
|
|
|
|
if (header) {
|
|
|
|
return (
|
|
|
|
<User
|
2019-02-27 14:47:15 +00:00
|
|
|
onPress={this.onPress}
|
2018-09-11 16:32:52 +00:00
|
|
|
timeFormat={timeFormat}
|
|
|
|
username={(useRealName && author.name) || author.username}
|
|
|
|
alias={alias}
|
|
|
|
ts={ts}
|
|
|
|
temp={this.isTemp()}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderContent() {
|
|
|
|
if (this.isInfoMessage()) {
|
|
|
|
return <Text style={styles.textInfo}>{getInfoMessage({ ...this.props })}</Text>;
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
|
2018-09-11 16:32:52 +00:00
|
|
|
const {
|
2019-04-24 18:36:29 +00:00
|
|
|
customEmojis, msg, baseUrl, user, edited, tmid
|
2018-09-11 16:32:52 +00:00
|
|
|
} = this.props;
|
2019-04-24 18:36:29 +00:00
|
|
|
|
|
|
|
if (tmid && !msg) {
|
|
|
|
return <Text style={styles.text}>{I18n.t('Sent_an_attachment')}</Text>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Markdown
|
|
|
|
msg={msg}
|
|
|
|
customEmojis={customEmojis}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
username={user.username}
|
|
|
|
edited={edited}
|
|
|
|
numberOfLines={tmid ? 1 : 0}
|
|
|
|
/>
|
|
|
|
);
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderAttachment() {
|
|
|
|
const { attachments, timeFormat } = this.props;
|
|
|
|
|
|
|
|
if (attachments.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return attachments.map((file, index) => {
|
|
|
|
const { user, baseUrl, customEmojis } = this.props;
|
|
|
|
if (file.image_url) {
|
|
|
|
return <Image key={file.image_url} file={file} user={user} baseUrl={baseUrl} customEmojis={customEmojis} />;
|
|
|
|
}
|
|
|
|
if (file.audio_url) {
|
|
|
|
return <Audio key={file.audio_url} file={file} user={user} baseUrl={baseUrl} customEmojis={customEmojis} />;
|
|
|
|
}
|
|
|
|
if (file.video_url) {
|
|
|
|
return <Video key={file.video_url} file={file} user={user} baseUrl={baseUrl} customEmojis={customEmojis} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line react/no-array-index-key
|
|
|
|
return <Reply key={index} index={index} attachment={file} timeFormat={timeFormat} user={user} baseUrl={baseUrl} customEmojis={customEmojis} />;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderUrl = () => {
|
|
|
|
const { urls } = this.props;
|
|
|
|
if (urls.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return urls.map((url, index) => (
|
|
|
|
<Url url={url} key={url.url} index={index} />
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
renderError = () => {
|
|
|
|
if (!this.hasError()) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
const { onErrorPress } = this.props;
|
2018-11-16 11:06:29 +00:00
|
|
|
return (
|
2019-04-24 18:36:29 +00:00
|
|
|
<Touchable onPress={onErrorPress} style={styles.errorButton}>
|
2019-03-29 19:36:07 +00:00
|
|
|
<CustomIcon name='circle-cross' color={COLOR_DANGER} size={20} />
|
2019-04-24 18:36:29 +00:00
|
|
|
</Touchable>
|
2018-11-16 11:06:29 +00:00
|
|
|
);
|
2018-09-11 16:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderReaction = (reaction) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
|
|
|
user, onReactionLongPress, onReactionPress, customEmojis, baseUrl
|
|
|
|
} = this.props;
|
|
|
|
const reacted = reaction.usernames.findIndex(item => item.value === user.username) !== -1;
|
2018-09-11 16:32:52 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<Touchable
|
|
|
|
onPress={() => onReactionPress(reaction.emoji)}
|
|
|
|
onLongPress={onReactionLongPress}
|
2018-09-11 16:32:52 +00:00
|
|
|
key={reaction.emoji}
|
2019-04-08 12:35:28 +00:00
|
|
|
testID={`message-reaction-${ reaction.emoji }`}
|
|
|
|
style={[styles.reactionButton, reacted && styles.reactionButtonReacted]}
|
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
2018-09-11 16:32:52 +00:00
|
|
|
>
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={[styles.reactionContainer, reacted && styles.reactedContainer]}>
|
|
|
|
<Emoji
|
|
|
|
content={reaction.emoji}
|
|
|
|
customEmojis={customEmojis}
|
|
|
|
standardEmojiStyle={styles.reactionEmoji}
|
|
|
|
customEmojiStyle={styles.reactionCustomEmoji}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
/>
|
|
|
|
<Text style={styles.reactionCount}>{ reaction.usernames.length }</Text>
|
|
|
|
</View>
|
|
|
|
</Touchable>
|
2018-09-11 16:32:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderReactions() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { reactions, toggleReactionPicker } = this.props;
|
2018-09-11 16:32:52 +00:00
|
|
|
if (reactions.length === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View style={styles.reactionsContainer}>
|
|
|
|
{reactions.map(this.renderReaction)}
|
2019-04-08 12:35:28 +00:00
|
|
|
<Touchable
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress={toggleReactionPicker}
|
2018-09-11 16:32:52 +00:00
|
|
|
key='message-add-reaction'
|
|
|
|
testID='message-add-reaction'
|
2018-09-19 14:18:32 +00:00
|
|
|
style={styles.reactionButton}
|
2019-04-08 12:35:28 +00:00
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
2018-09-11 16:32:52 +00:00
|
|
|
>
|
2018-09-19 14:18:32 +00:00
|
|
|
<View style={styles.reactionContainer}>
|
2019-03-01 16:49:11 +00:00
|
|
|
<CustomIcon name='add-reaction' size={21} style={styles.addReaction} />
|
2018-09-19 14:18:32 +00:00
|
|
|
</View>
|
2019-04-08 12:35:28 +00:00
|
|
|
</Touchable>
|
2018-09-11 16:32:52 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBroadcastReply() {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { broadcast, replyBroadcast } = this.props;
|
|
|
|
if (broadcast && !this.isOwn()) {
|
2018-09-11 16:32:52 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<Touchable
|
|
|
|
onPress={replyBroadcast}
|
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
style={styles.button}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
>
|
|
|
|
<React.Fragment>
|
|
|
|
<CustomIcon name='back' size={20} style={styles.buttonIcon} />
|
|
|
|
<Text style={styles.buttonText}>{I18n.t('Reply')}</Text>
|
|
|
|
</React.Fragment>
|
|
|
|
</Touchable>
|
|
|
|
</View>
|
2018-09-11 16:32:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
renderDiscussion = () => {
|
|
|
|
const {
|
|
|
|
msg, dcount, dlm, onDiscussionPress
|
|
|
|
} = this.props;
|
2019-04-17 17:01:03 +00:00
|
|
|
const time = this.formatLastMessage(dlm);
|
|
|
|
const buttonText = this.formatMessageCount(dcount, 'discussion');
|
2019-04-08 12:35:28 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2019-04-17 17:01:03 +00:00
|
|
|
<Text style={styles.startedDiscussion}>{I18n.t('Started_discussion')}</Text>
|
2019-04-08 12:35:28 +00:00
|
|
|
<Text style={styles.text}>{msg}</Text>
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<Touchable
|
|
|
|
onPress={onDiscussionPress}
|
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
style={[styles.button, styles.smallButton]}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
>
|
|
|
|
<React.Fragment>
|
|
|
|
<CustomIcon name='chat' size={20} style={styles.buttonIcon} />
|
|
|
|
<Text style={styles.buttonText}>{buttonText}</Text>
|
|
|
|
</React.Fragment>
|
|
|
|
</Touchable>
|
|
|
|
<Text style={styles.time}>{time}</Text>
|
|
|
|
</View>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
renderThread = () => {
|
|
|
|
const {
|
|
|
|
tcount, tlm, onThreadPress, msg
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!tlm) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const time = this.formatLastMessage(tlm);
|
|
|
|
const buttonText = this.formatMessageCount(tcount, 'thread');
|
|
|
|
return (
|
|
|
|
<View style={styles.buttonContainer}>
|
|
|
|
<Touchable
|
|
|
|
onPress={onThreadPress}
|
|
|
|
background={Touchable.Ripple('#fff')}
|
|
|
|
style={[styles.button, styles.smallButton]}
|
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
testID={`message-thread-button-${ msg }`}
|
|
|
|
>
|
|
|
|
<React.Fragment>
|
|
|
|
<CustomIcon name='thread' size={20} style={styles.buttonIcon} />
|
|
|
|
<Text style={styles.buttonText}>{buttonText}</Text>
|
|
|
|
</React.Fragment>
|
|
|
|
</Touchable>
|
|
|
|
<Text style={styles.time}>{time}</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderRepliedThread = () => {
|
|
|
|
const {
|
2019-04-24 18:36:29 +00:00
|
|
|
tmid, tmsg, header, fetchThreadName
|
2019-04-17 17:01:03 +00:00
|
|
|
} = this.props;
|
|
|
|
if (!tmid || !header || this.isTemp()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tmsg) {
|
|
|
|
fetchThreadName(tmid);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-04-25 17:18:49 +00:00
|
|
|
let msg = emojify(tmsg, { output: 'unicode' });
|
|
|
|
msg = removeMarkdown(msg);
|
2019-04-24 18:36:29 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
return (
|
2019-04-24 18:36:29 +00:00
|
|
|
<View style={styles.repliedThread} testID={`message-thread-replied-on-${ msg }`}>
|
2019-04-25 17:18:49 +00:00
|
|
|
<CustomIcon name='thread' size={16} style={styles.repliedThreadIcon} />
|
2019-04-24 18:36:29 +00:00
|
|
|
<Text style={styles.repliedThreadName} numberOfLines={1}>{msg}</Text>
|
|
|
|
</View>
|
2019-04-17 17:01:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
renderInner = () => {
|
2019-04-24 18:36:29 +00:00
|
|
|
const { type, tmid } = this.props;
|
2019-04-08 12:35:28 +00:00
|
|
|
if (type === 'discussion-created') {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{this.renderUsername()}
|
|
|
|
{this.renderDiscussion()}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
if (tmid) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{this.renderUsername()}
|
|
|
|
{this.renderRepliedThread()}
|
|
|
|
{this.renderContent()}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{this.renderUsername()}
|
|
|
|
{this.renderContent()}
|
|
|
|
{this.renderAttachment()}
|
|
|
|
{this.renderUrl()}
|
2019-04-17 17:01:03 +00:00
|
|
|
{this.renderThread()}
|
2019-04-08 12:35:28 +00:00
|
|
|
{this.renderReactions()}
|
|
|
|
{this.renderBroadcastReply()}
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-09-11 16:32:52 +00:00
|
|
|
render() {
|
|
|
|
const {
|
2019-03-01 14:40:22 +00:00
|
|
|
editing, style, header, reactionsModal, closeReactions, msg, ts, reactions, author, user, timeFormat, customEmojis, baseUrl
|
2018-09-11 16:32:52 +00:00
|
|
|
} = this.props;
|
|
|
|
const accessibilityLabel = I18n.t('Message_accessibility', { user: author.username, time: moment(ts).format(timeFormat), message: msg });
|
|
|
|
|
|
|
|
return (
|
2018-11-16 11:06:29 +00:00
|
|
|
<View style={styles.root}>
|
|
|
|
{this.renderError()}
|
2019-02-27 14:47:15 +00:00
|
|
|
<TouchableWithoutFeedback
|
2019-03-01 14:40:22 +00:00
|
|
|
onLongPress={this.onLongPress}
|
2019-02-27 14:47:15 +00:00
|
|
|
onPress={this.onPress}
|
2018-09-19 14:18:32 +00:00
|
|
|
>
|
2019-02-27 14:47:15 +00:00
|
|
|
<View
|
2019-03-27 20:06:57 +00:00
|
|
|
style={[styles.container, header && styles.marginTop, editing && styles.editing, style]}
|
2019-02-27 14:47:15 +00:00
|
|
|
accessibilityLabel={accessibilityLabel}
|
2018-09-19 14:18:32 +00:00
|
|
|
>
|
2019-02-27 14:47:15 +00:00
|
|
|
<View style={styles.flex}>
|
|
|
|
{this.renderAvatar()}
|
|
|
|
<View
|
|
|
|
style={[
|
|
|
|
styles.messageContent,
|
|
|
|
header && styles.messageContentWithHeader,
|
|
|
|
this.hasError() && header && styles.messageContentWithHeader,
|
|
|
|
this.hasError() && !header && styles.messageContentWithError,
|
|
|
|
this.isTemp() && styles.temp
|
|
|
|
]}
|
|
|
|
>
|
2019-04-08 12:35:28 +00:00
|
|
|
{this.renderInner()}
|
2018-09-19 14:18:32 +00:00
|
|
|
</View>
|
2018-09-11 16:32:52 +00:00
|
|
|
</View>
|
2019-02-27 14:47:15 +00:00
|
|
|
{reactionsModal
|
|
|
|
? (
|
|
|
|
<ReactionsModal
|
|
|
|
isVisible={reactionsModal}
|
|
|
|
reactions={reactions}
|
|
|
|
user={user}
|
|
|
|
customEmojis={customEmojis}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
close={closeReactions}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null
|
|
|
|
}
|
|
|
|
</View>
|
|
|
|
</TouchableWithoutFeedback>
|
2018-11-16 11:06:29 +00:00
|
|
|
</View>
|
2018-09-11 16:32:52 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|