2018-12-21 10:55:35 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-08-09 13:12:00 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2019-06-10 18:36:56 +00:00
|
|
|
View, TextInput, FlatList, Text, TouchableOpacity, Alert, ScrollView
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2017-11-21 16:55:32 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-09-16 20:50:51 +00:00
|
|
|
import { shortnameToUnicode } from 'emoji-toolkit';
|
2018-02-08 14:08:50 +00:00
|
|
|
import { KeyboardAccessoryView } from 'react-native-keyboard-input';
|
2018-07-17 19:10:27 +00:00
|
|
|
import ImagePicker from 'react-native-image-crop-picker';
|
2018-12-21 10:55:35 +00:00
|
|
|
import equal from 'deep-equal';
|
2019-07-18 17:25:18 +00:00
|
|
|
import DocumentPicker from 'react-native-document-picker';
|
2019-05-27 16:19:39 +00:00
|
|
|
import ActionSheet from 'react-native-action-sheet';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
2018-03-07 00:17:20 +00:00
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
import { userTyping as userTypingAction } from '../../actions/room';
|
2017-12-08 19:36:03 +00:00
|
|
|
import RocketChat from '../../lib/rocketchat';
|
2018-02-08 14:08:50 +00:00
|
|
|
import styles from './styles';
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
2017-12-20 20:14:07 +00:00
|
|
|
import Avatar from '../Avatar';
|
2018-01-30 19:48:26 +00:00
|
|
|
import CustomEmoji from '../EmojiPicker/CustomEmoji';
|
|
|
|
import { emojis } from '../../emojis';
|
2018-03-07 00:17:20 +00:00
|
|
|
import Recording from './Recording';
|
2018-07-17 19:10:27 +00:00
|
|
|
import UploadModal from './UploadModal';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log from '../../utils/log';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../../i18n';
|
2018-07-20 19:54:46 +00:00
|
|
|
import ReplyPreview from './ReplyPreview';
|
2019-02-27 14:23:40 +00:00
|
|
|
import debounce from '../../utils/debounce';
|
2019-05-27 16:19:39 +00:00
|
|
|
import { COLOR_TEXT_DESCRIPTION } from '../../constants/colors';
|
|
|
|
import LeftButtons from './LeftButtons';
|
|
|
|
import RightButtons from './RightButtons';
|
|
|
|
import { isAndroid } from '../../utils/deviceInfo';
|
2019-06-10 18:36:56 +00:00
|
|
|
import CommandPreview from './CommandPreview';
|
2019-09-24 20:16:59 +00:00
|
|
|
import { canUploadFile } from '../../utils/media';
|
2018-03-07 00:17:20 +00:00
|
|
|
|
2017-12-20 20:14:07 +00:00
|
|
|
const MENTIONS_TRACKING_TYPE_USERS = '@';
|
2018-01-30 19:48:26 +00:00
|
|
|
const MENTIONS_TRACKING_TYPE_EMOJIS = ':';
|
2019-06-10 18:36:56 +00:00
|
|
|
const MENTIONS_TRACKING_TYPE_COMMANDS = '/';
|
|
|
|
const MENTIONS_COUNT_TO_DISPLAY = 4;
|
2017-12-20 20:14:07 +00:00
|
|
|
|
2018-07-17 19:10:27 +00:00
|
|
|
const imagePickerConfig = {
|
|
|
|
cropping: true,
|
|
|
|
compressImageQuality: 0.8,
|
2019-07-16 14:30:29 +00:00
|
|
|
avoidEmptySpaceAroundImage: false
|
2018-07-17 19:10:27 +00:00
|
|
|
};
|
|
|
|
|
2019-07-18 17:07:37 +00:00
|
|
|
const libraryPickerConfig = {
|
|
|
|
mediaType: 'any'
|
|
|
|
};
|
|
|
|
|
|
|
|
const videoPickerConfig = {
|
|
|
|
mediaType: 'video'
|
|
|
|
};
|
|
|
|
|
2019-05-27 16:19:39 +00:00
|
|
|
const FILE_CANCEL_INDEX = 0;
|
|
|
|
const FILE_PHOTO_INDEX = 1;
|
2019-07-18 17:07:37 +00:00
|
|
|
const FILE_VIDEO_INDEX = 2;
|
|
|
|
const FILE_LIBRARY_INDEX = 3;
|
2019-07-18 17:25:18 +00:00
|
|
|
const FILE_DOCUMENT_INDEX = 4;
|
2019-05-27 16:19:39 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
class MessageBox extends Component {
|
2017-08-09 13:12:00 +00:00
|
|
|
static propTypes = {
|
2017-11-21 14:55:50 +00:00
|
|
|
rid: PropTypes.string.isRequired,
|
2017-12-20 20:14:07 +00:00
|
|
|
baseUrl: PropTypes.string.isRequired,
|
2017-11-21 14:55:50 +00:00
|
|
|
message: PropTypes.object,
|
2018-07-20 19:54:46 +00:00
|
|
|
replying: PropTypes.bool,
|
2017-11-21 17:09:22 +00:00
|
|
|
editing: PropTypes.bool,
|
2019-04-17 17:01:03 +00:00
|
|
|
threadsEnabled: PropTypes.bool,
|
2019-04-24 18:36:29 +00:00
|
|
|
isFocused: PropTypes.bool,
|
2019-02-07 19:58:20 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
username: PropTypes.string,
|
|
|
|
token: PropTypes.string
|
|
|
|
}),
|
2018-07-20 19:54:46 +00:00
|
|
|
roomType: PropTypes.string,
|
2019-04-24 18:36:29 +00:00
|
|
|
tmid: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
replyWithMention: PropTypes.bool,
|
2019-09-24 20:16:59 +00:00
|
|
|
FileUpload_MediaTypeWhiteList: PropTypes.string,
|
|
|
|
FileUpload_MaxFileSize: PropTypes.number,
|
2019-09-16 20:26:32 +00:00
|
|
|
getCustomEmoji: PropTypes.func,
|
2018-07-20 19:54:46 +00:00
|
|
|
editCancel: PropTypes.func.isRequired,
|
|
|
|
editRequest: PropTypes.func.isRequired,
|
|
|
|
onSubmit: PropTypes.func.isRequired,
|
2017-11-24 20:44:52 +00:00
|
|
|
typing: PropTypes.func,
|
2019-09-16 20:26:32 +00:00
|
|
|
replyCancel: PropTypes.func
|
2017-11-21 14:55:50 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 16:27:06 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-12-20 20:14:07 +00:00
|
|
|
mentions: [],
|
2018-02-08 14:08:50 +00:00
|
|
|
showEmojiKeyboard: false,
|
2018-11-05 19:03:17 +00:00
|
|
|
showSend: false,
|
2018-07-17 19:10:27 +00:00
|
|
|
recording: false,
|
2019-02-27 14:23:40 +00:00
|
|
|
trackingType: '',
|
2018-07-17 19:10:27 +00:00
|
|
|
file: {
|
|
|
|
isVisible: false
|
2019-06-10 18:36:56 +00:00
|
|
|
},
|
2019-09-25 21:32:13 +00:00
|
|
|
commandPreview: [],
|
|
|
|
showCommandPreview: false
|
2017-11-28 16:27:06 +00:00
|
|
|
};
|
2018-09-25 19:28:42 +00:00
|
|
|
this.onEmojiSelected = this.onEmojiSelected.bind(this);
|
2018-11-05 19:03:17 +00:00
|
|
|
this.text = '';
|
2019-07-16 14:30:29 +00:00
|
|
|
this.fileOptions = [
|
|
|
|
I18n.t('Cancel'),
|
|
|
|
I18n.t('Take_a_photo'),
|
2019-07-18 17:07:37 +00:00
|
|
|
I18n.t('Take_a_video'),
|
2019-07-18 17:25:18 +00:00
|
|
|
I18n.t('Choose_from_library'),
|
|
|
|
I18n.t('Choose_file')
|
2019-07-16 14:30:29 +00:00
|
|
|
];
|
2019-07-18 17:07:37 +00:00
|
|
|
const libPickerLabels = {
|
|
|
|
cropperChooseText: I18n.t('Choose'),
|
|
|
|
cropperCancelText: I18n.t('Cancel'),
|
|
|
|
loadingLabelText: I18n.t('Processing')
|
|
|
|
};
|
2019-07-16 14:30:29 +00:00
|
|
|
this.imagePickerConfig = {
|
|
|
|
...imagePickerConfig,
|
2019-07-18 17:07:37 +00:00
|
|
|
...libPickerLabels
|
|
|
|
};
|
|
|
|
this.libraryPickerConfig = {
|
|
|
|
...libraryPickerConfig,
|
|
|
|
...libPickerLabels
|
|
|
|
};
|
|
|
|
this.videoPickerConfig = {
|
|
|
|
...videoPickerConfig,
|
|
|
|
...libPickerLabels
|
2019-07-16 14:30:29 +00:00
|
|
|
};
|
2017-11-28 16:27:06 +00:00
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
async componentDidMount() {
|
|
|
|
const db = database.active;
|
2019-04-24 18:36:29 +00:00
|
|
|
const { rid, tmid } = this.props;
|
|
|
|
let msg;
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const threadsCollection = db.collections.get('threads');
|
|
|
|
const subsCollection = db.collections.get('subscriptions');
|
|
|
|
if (tmid) {
|
|
|
|
try {
|
|
|
|
const thread = await threadsCollection.find(tmid);
|
|
|
|
if (thread) {
|
|
|
|
msg = thread.draftMessage;
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Messagebox.didMount: Thread not found');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const room = await subsCollection.find(rid);
|
|
|
|
msg = room.draftMessage;
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Messagebox.didMount: Room not found');
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-04-24 18:36:29 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2019-04-24 18:36:29 +00:00
|
|
|
if (msg) {
|
|
|
|
this.setInput(msg);
|
2019-04-08 12:35:28 +00:00
|
|
|
this.setShowSend(true);
|
2019-04-01 14:45:17 +00:00
|
|
|
}
|
2019-05-27 16:19:39 +00:00
|
|
|
|
|
|
|
if (isAndroid) {
|
|
|
|
require('./EmojiKeyboard');
|
|
|
|
}
|
2019-04-01 14:45:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 14:55:50 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { isFocused, editing, replying } = this.props;
|
2019-04-24 18:36:29 +00:00
|
|
|
if (!isFocused) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
if (editing !== nextProps.editing && nextProps.editing) {
|
2018-11-05 19:03:17 +00:00
|
|
|
this.setInput(nextProps.message.msg);
|
2019-04-08 12:35:28 +00:00
|
|
|
if (this.text) {
|
|
|
|
this.setShowSend(true);
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
} else if (replying !== nextProps.replying && nextProps.replying) {
|
2019-03-06 13:27:40 +00:00
|
|
|
this.focus();
|
2017-11-24 20:44:52 +00:00
|
|
|
} else if (!nextProps.message) {
|
2018-11-05 19:03:17 +00:00
|
|
|
this.clearInput();
|
2017-11-21 14:55:50 +00:00
|
|
|
}
|
2017-08-09 13:12:00 +00:00
|
|
|
}
|
2017-12-20 20:14:07 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
const {
|
2019-06-10 18:36:56 +00:00
|
|
|
showEmojiKeyboard, showSend, recording, mentions, file, commandPreview
|
2018-12-21 10:55:35 +00:00
|
|
|
} = this.state;
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
const {
|
2019-04-24 18:36:29 +00:00
|
|
|
roomType, replying, editing, isFocused
|
2018-12-21 10:55:35 +00:00
|
|
|
} = this.props;
|
2019-04-24 18:36:29 +00:00
|
|
|
if (!isFocused) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (nextProps.roomType !== roomType) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.replying !== replying) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextProps.editing !== editing) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.showEmojiKeyboard !== showEmojiKeyboard) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.showSend !== showSend) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (nextState.recording !== recording) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!equal(nextState.mentions, mentions)) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-06-10 18:36:56 +00:00
|
|
|
if (!equal(nextState.commandPreview, commandPreview)) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
if (!equal(nextState.file, file)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
console.countReset(`${ this.constructor.name }.render calls`);
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeText = debounce(async(text) => {
|
|
|
|
const db = database.active;
|
2019-02-27 14:23:40 +00:00
|
|
|
const isTextEmpty = text.length === 0;
|
|
|
|
this.setShowSend(!isTextEmpty);
|
|
|
|
this.handleTyping(!isTextEmpty);
|
2018-11-05 19:03:17 +00:00
|
|
|
this.setInput(text);
|
2019-06-10 18:36:56 +00:00
|
|
|
// matches if their is text that stats with '/' and group the command and params so we can use it "/command params"
|
|
|
|
const slashCommand = text.match(/^\/([a-z0-9._-]+) (.+)/im);
|
|
|
|
if (slashCommand) {
|
|
|
|
const [, name, params] = slashCommand;
|
2019-09-16 20:26:32 +00:00
|
|
|
const commandsCollection = db.collections.get('slash_commands');
|
|
|
|
try {
|
|
|
|
const command = await commandsCollection.find(name);
|
|
|
|
if (command.providesPreview) {
|
|
|
|
return this.setCommandPreview(name, params);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Slash command not found');
|
2019-06-10 18:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-25 14:04:20 +00:00
|
|
|
|
2019-05-30 17:19:26 +00:00
|
|
|
if (!isTextEmpty) {
|
2019-05-27 16:19:39 +00:00
|
|
|
const { start, end } = this.component._lastNativeSelection;
|
|
|
|
const cursor = Math.max(start, end);
|
|
|
|
const lastNativeText = this.component._lastNativeText;
|
2019-06-10 18:36:56 +00:00
|
|
|
// matches if text either starts with '/' or have (@,#,:) then it groups whatever comes next of mention type
|
|
|
|
const regexp = /(#|@|:|^\/)([a-z0-9._-]+)$/im;
|
2019-05-27 16:19:39 +00:00
|
|
|
const result = lastNativeText.substr(0, cursor).match(regexp);
|
|
|
|
if (!result) {
|
2019-06-10 18:36:56 +00:00
|
|
|
const slash = lastNativeText.match(/^\/$/); // matches only '/' in input
|
|
|
|
if (slash) {
|
|
|
|
return this.identifyMentionKeyword('', MENTIONS_TRACKING_TYPE_COMMANDS);
|
|
|
|
}
|
2019-05-27 16:19:39 +00:00
|
|
|
return this.stopTrackingMention();
|
|
|
|
}
|
|
|
|
const [, lastChar, name] = result;
|
|
|
|
this.identifyMentionKeyword(name, lastChar);
|
2019-06-03 16:56:16 +00:00
|
|
|
} else {
|
|
|
|
this.stopTrackingMention();
|
2019-03-06 13:27:40 +00:00
|
|
|
}
|
2019-05-27 16:19:39 +00:00
|
|
|
}, 100)
|
2017-12-20 20:14:07 +00:00
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
onKeyboardResigned = () => {
|
2018-02-08 14:08:50 +00:00
|
|
|
this.closeEmoji();
|
|
|
|
}
|
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
onPressMention = (item) => {
|
2019-03-06 13:27:40 +00:00
|
|
|
if (!this.component) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
const { trackingType } = this.state;
|
2018-11-05 19:03:17 +00:00
|
|
|
const msg = this.text;
|
2018-09-25 19:28:42 +00:00
|
|
|
const { start, end } = this.component._lastNativeSelection;
|
|
|
|
const cursor = Math.max(start, end);
|
|
|
|
const regexp = /([a-z0-9._-]+)$/im;
|
|
|
|
const result = msg.substr(0, cursor).replace(regexp, '');
|
|
|
|
const mentionName = trackingType === MENTIONS_TRACKING_TYPE_EMOJIS
|
|
|
|
? `${ item.name || item }:`
|
2019-06-10 18:36:56 +00:00
|
|
|
: (item.username || item.name || item.command);
|
2018-09-25 19:28:42 +00:00
|
|
|
const text = `${ result }${ mentionName } ${ msg.slice(cursor) }`;
|
2019-06-10 18:36:56 +00:00
|
|
|
if ((trackingType === MENTIONS_TRACKING_TYPE_COMMANDS) && item.providesPreview) {
|
2019-09-25 21:32:13 +00:00
|
|
|
this.setState({ showCommandPreview: true });
|
2019-06-10 18:36:56 +00:00
|
|
|
}
|
2018-11-05 19:03:17 +00:00
|
|
|
this.setInput(text);
|
2019-03-06 13:27:40 +00:00
|
|
|
this.focus();
|
2018-09-25 19:28:42 +00:00
|
|
|
requestAnimationFrame(() => this.stopTrackingMention());
|
|
|
|
}
|
|
|
|
|
2019-06-10 18:36:56 +00:00
|
|
|
onPressCommandPreview = (item) => {
|
|
|
|
const { rid } = this.props;
|
|
|
|
const { text } = this;
|
|
|
|
const command = text.substr(0, text.indexOf(' ')).slice(1);
|
|
|
|
const params = text.substr(text.indexOf(' ') + 1) || 'params';
|
2019-09-25 21:32:13 +00:00
|
|
|
this.setState({ commandPreview: [], showCommandPreview: false });
|
2019-06-10 18:36:56 +00:00
|
|
|
this.stopTrackingMention();
|
|
|
|
this.clearInput();
|
2019-09-25 21:32:13 +00:00
|
|
|
this.handleTyping(false);
|
2019-06-10 18:36:56 +00:00
|
|
|
try {
|
|
|
|
RocketChat.executeCommandPreview(command, params, rid, item);
|
|
|
|
} catch (e) {
|
2019-08-30 12:43:23 +00:00
|
|
|
log(e);
|
2019-06-10 18:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
onEmojiSelected = (keyboardId, params) => {
|
2018-11-05 19:03:17 +00:00
|
|
|
const { text } = this;
|
2018-09-25 19:28:42 +00:00
|
|
|
const { emoji } = params;
|
|
|
|
let newText = '';
|
|
|
|
|
|
|
|
// if messagebox has an active cursor
|
2019-03-06 13:27:40 +00:00
|
|
|
if (this.component && this.component._lastNativeSelection) {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { start, end } = this.component._lastNativeSelection;
|
|
|
|
const cursor = Math.max(start, end);
|
|
|
|
newText = `${ text.substr(0, cursor) }${ emoji }${ text.substr(cursor) }`;
|
|
|
|
} else {
|
|
|
|
// if messagebox doesn't have a cursor, just append selected emoji
|
|
|
|
newText = `${ text }${ emoji }`;
|
|
|
|
}
|
2018-11-05 19:03:17 +00:00
|
|
|
this.setInput(newText);
|
2019-02-28 18:03:26 +00:00
|
|
|
this.setShowSend(true);
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 19:54:46 +00:00
|
|
|
getPermalink = async(message) => {
|
|
|
|
try {
|
2019-05-29 21:19:12 +00:00
|
|
|
return await RocketChat.getPermalinkMessage(message);
|
2018-07-20 19:54:46 +00:00
|
|
|
} catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
getFixedMentions = (keyword) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
let result = [];
|
2018-09-25 19:28:42 +00:00
|
|
|
if ('all'.indexOf(keyword) !== -1) {
|
2019-09-16 20:26:32 +00:00
|
|
|
result = [{ _id: -1, username: 'all' }];
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
|
|
|
if ('here'.indexOf(keyword) !== -1) {
|
2019-09-16 20:26:32 +00:00
|
|
|
result = [{ _id: -2, username: 'here' }, ...result];
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
return result;
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
getUsers = debounce(async(keyword) => {
|
|
|
|
let res = await RocketChat.search({ text: keyword, filterRooms: false, filterUsers: true });
|
|
|
|
res = [...this.getFixedMentions(keyword), ...res];
|
|
|
|
this.setState({ mentions: res });
|
|
|
|
}, 300)
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
getRooms = debounce(async(keyword = '') => {
|
|
|
|
const res = await RocketChat.search({ text: keyword, filterRooms: true, filterUsers: false });
|
|
|
|
this.setState({ mentions: res });
|
|
|
|
}, 300)
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
getEmojis = debounce(async(keyword) => {
|
|
|
|
const db = database.active;
|
2018-09-25 19:28:42 +00:00
|
|
|
if (keyword) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const customEmojisCollection = db.collections.get('custom_emojis');
|
|
|
|
let customEmojis = await customEmojisCollection.query(
|
|
|
|
Q.where('name', Q.like(`${ Q.sanitizeLikeString(keyword) }%`))
|
|
|
|
).fetch();
|
|
|
|
customEmojis = customEmojis.slice(0, MENTIONS_COUNT_TO_DISPLAY);
|
|
|
|
const filteredEmojis = emojis.filter(emoji => emoji.indexOf(keyword) !== -1).slice(0, MENTIONS_COUNT_TO_DISPLAY);
|
|
|
|
const mergedEmojis = [...customEmojis, ...filteredEmojis].slice(0, MENTIONS_COUNT_TO_DISPLAY);
|
|
|
|
this.setState({ mentions: mergedEmojis || [] });
|
|
|
|
}
|
|
|
|
}, 300)
|
|
|
|
|
|
|
|
getSlashCommands = debounce(async(keyword) => {
|
|
|
|
const db = database.active;
|
|
|
|
const commandsCollection = db.collections.get('slash_commands');
|
|
|
|
const commands = await commandsCollection.query(
|
|
|
|
Q.where('id', Q.like(`${ Q.sanitizeLikeString(keyword) }%`))
|
|
|
|
).fetch();
|
|
|
|
this.setState({ mentions: commands || [] });
|
|
|
|
}, 300)
|
2019-06-10 18:36:56 +00:00
|
|
|
|
2019-03-06 13:27:40 +00:00
|
|
|
focus = () => {
|
|
|
|
if (this.component && this.component.focus) {
|
|
|
|
this.component.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-25 16:22:48 +00:00
|
|
|
handleTyping = (isTyping) => {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { typing, rid } = this.props;
|
2019-02-25 16:22:48 +00:00
|
|
|
if (!isTyping) {
|
|
|
|
if (this.typingTimeout) {
|
|
|
|
clearTimeout(this.typingTimeout);
|
|
|
|
this.typingTimeout = false;
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
typing(rid, false);
|
2019-02-25 16:22:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.typingTimeout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.typingTimeout = setTimeout(() => {
|
2019-04-08 12:35:28 +00:00
|
|
|
typing(rid, true);
|
2019-02-25 16:22:48 +00:00
|
|
|
this.typingTimeout = false;
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
2019-06-10 18:36:56 +00:00
|
|
|
setCommandPreview = async(command, params) => {
|
|
|
|
const { rid } = this.props;
|
|
|
|
try {
|
|
|
|
const { preview } = await RocketChat.getCommandPreview(command, rid, params);
|
2019-09-25 21:32:13 +00:00
|
|
|
this.setState({ commandPreview: preview.items, showCommandPreview: true });
|
2019-06-10 18:36:56 +00:00
|
|
|
} catch (e) {
|
2019-09-25 21:32:13 +00:00
|
|
|
this.setState({ commandPreview: [], showCommandPreview: true });
|
2019-08-30 12:43:23 +00:00
|
|
|
log(e);
|
2019-06-10 18:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 19:03:17 +00:00
|
|
|
setInput = (text) => {
|
|
|
|
this.text = text;
|
2019-03-06 13:27:40 +00:00
|
|
|
if (this.component && this.component.setNativeProps) {
|
|
|
|
this.component.setNativeProps({ text });
|
|
|
|
}
|
2019-02-27 14:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setShowSend = (showSend) => {
|
|
|
|
this.setState({ showSend });
|
2018-11-05 19:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
clearInput = () => {
|
|
|
|
this.setInput('');
|
2019-02-27 14:23:40 +00:00
|
|
|
this.setShowSend(false);
|
2018-11-05 19:03:17 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 20:16:59 +00:00
|
|
|
canUploadFile = (file) => {
|
|
|
|
const { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize } = this.props;
|
|
|
|
const result = canUploadFile(file, { FileUpload_MediaTypeWhiteList, FileUpload_MaxFileSize });
|
|
|
|
if (result.success) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Alert.alert(I18n.t('Error_uploading'), I18n.t(result.error));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:07:37 +00:00
|
|
|
sendMediaMessage = async(file) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const {
|
|
|
|
rid, tmid, baseUrl: server, user
|
|
|
|
} = this.props;
|
2018-07-17 19:10:27 +00:00
|
|
|
this.setState({ file: { isVisible: false } });
|
|
|
|
const fileInfo = {
|
|
|
|
name: file.name,
|
|
|
|
description: file.description,
|
|
|
|
size: file.size,
|
|
|
|
type: file.mime,
|
|
|
|
store: 'Uploads',
|
|
|
|
path: file.path
|
2017-08-10 20:09:54 +00:00
|
|
|
};
|
2018-07-17 19:10:27 +00:00
|
|
|
try {
|
2019-07-29 16:33:28 +00:00
|
|
|
await RocketChat.sendFileMessage(rid, fileInfo, tmid, server, user);
|
2018-07-17 19:10:27 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-07-17 19:10:27 +00:00
|
|
|
}
|
2017-08-10 20:09:54 +00:00
|
|
|
}
|
2018-07-17 19:10:27 +00:00
|
|
|
|
|
|
|
takePhoto = async() => {
|
|
|
|
try {
|
2019-07-16 14:30:29 +00:00
|
|
|
const image = await ImagePicker.openCamera(this.imagePickerConfig);
|
2019-09-24 20:16:59 +00:00
|
|
|
if (this.canUploadFile(image)) {
|
|
|
|
this.showUploadModal(image);
|
|
|
|
}
|
2018-07-17 19:10:27 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-07-17 19:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:07:37 +00:00
|
|
|
takeVideo = async() => {
|
|
|
|
try {
|
|
|
|
const video = await ImagePicker.openCamera(this.videoPickerConfig);
|
2019-09-24 20:16:59 +00:00
|
|
|
if (this.canUploadFile(video)) {
|
|
|
|
this.showUploadModal(video);
|
|
|
|
}
|
2019-07-18 17:07:37 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-07-18 17:07:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:10:27 +00:00
|
|
|
chooseFromLibrary = async() => {
|
|
|
|
try {
|
2019-07-18 17:07:37 +00:00
|
|
|
const image = await ImagePicker.openPicker(this.libraryPickerConfig);
|
2019-09-24 20:16:59 +00:00
|
|
|
if (this.canUploadFile(image)) {
|
|
|
|
this.showUploadModal(image);
|
|
|
|
}
|
2018-07-17 19:10:27 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-07-17 19:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:25:18 +00:00
|
|
|
chooseFile = async() => {
|
|
|
|
try {
|
|
|
|
const res = await DocumentPicker.pick({
|
|
|
|
type: [DocumentPicker.types.allFiles]
|
|
|
|
});
|
2019-09-24 20:16:59 +00:00
|
|
|
const file = {
|
2019-07-18 17:25:18 +00:00
|
|
|
filename: res.name,
|
|
|
|
size: res.size,
|
|
|
|
mime: res.type,
|
|
|
|
path: res.uri
|
2019-09-24 20:16:59 +00:00
|
|
|
};
|
|
|
|
if (this.canUploadFile(file)) {
|
|
|
|
this.showUploadModal(file);
|
|
|
|
}
|
2019-08-30 12:43:23 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (!DocumentPicker.isCancel(e)) {
|
|
|
|
log(e);
|
2019-07-18 17:25:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-17 19:10:27 +00:00
|
|
|
showUploadModal = (file) => {
|
|
|
|
this.setState({ file: { ...file, isVisible: true } });
|
|
|
|
}
|
|
|
|
|
2019-05-27 16:19:39 +00:00
|
|
|
showFileActions = () => {
|
|
|
|
ActionSheet.showActionSheetWithOptions({
|
2019-07-16 14:30:29 +00:00
|
|
|
options: this.fileOptions,
|
2019-05-27 16:19:39 +00:00
|
|
|
cancelButtonIndex: FILE_CANCEL_INDEX
|
|
|
|
}, (actionIndex) => {
|
|
|
|
this.handleFileActionPress(actionIndex);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFileActionPress = (actionIndex) => {
|
|
|
|
switch (actionIndex) {
|
|
|
|
case FILE_PHOTO_INDEX:
|
|
|
|
this.takePhoto();
|
|
|
|
break;
|
2019-07-18 17:07:37 +00:00
|
|
|
case FILE_VIDEO_INDEX:
|
|
|
|
this.takeVideo();
|
|
|
|
break;
|
2019-05-27 16:19:39 +00:00
|
|
|
case FILE_LIBRARY_INDEX:
|
|
|
|
this.chooseFromLibrary();
|
|
|
|
break;
|
2019-07-18 17:25:18 +00:00
|
|
|
case FILE_DOCUMENT_INDEX:
|
|
|
|
this.chooseFile();
|
|
|
|
break;
|
2019-05-27 16:19:39 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
editCancel = () => {
|
|
|
|
const { editCancel } = this.props;
|
|
|
|
editCancel();
|
2018-11-05 19:03:17 +00:00
|
|
|
this.clearInput();
|
2017-11-24 20:44:52 +00:00
|
|
|
}
|
2018-07-17 19:10:27 +00:00
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
openEmoji = async() => {
|
2018-01-30 19:48:26 +00:00
|
|
|
await this.setState({
|
2018-02-08 14:08:50 +00:00
|
|
|
showEmojiKeyboard: true
|
2018-01-30 19:48:26 +00:00
|
|
|
});
|
2018-01-16 18:48:05 +00:00
|
|
|
}
|
2018-03-07 00:17:20 +00:00
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
recordAudioMessage = async() => {
|
2018-03-07 00:17:20 +00:00
|
|
|
const recording = await Recording.permission();
|
|
|
|
this.setState({ recording });
|
|
|
|
}
|
|
|
|
|
|
|
|
finishAudioMessage = async(fileInfo) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const {
|
|
|
|
rid, tmid, baseUrl: server, user
|
|
|
|
} = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-03-07 00:17:20 +00:00
|
|
|
this.setState({
|
|
|
|
recording: false
|
|
|
|
});
|
2018-05-29 17:10:40 +00:00
|
|
|
if (fileInfo) {
|
|
|
|
try {
|
2019-09-24 20:16:59 +00:00
|
|
|
if (this.canUploadFile(fileInfo)) {
|
|
|
|
await RocketChat.sendFileMessage(rid, fileInfo, tmid, server, user);
|
2018-05-29 17:10:40 +00:00
|
|
|
}
|
2019-09-24 20:16:59 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-05-29 17:10:40 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-07 00:17:20 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
closeEmoji = () => {
|
2018-02-08 14:08:50 +00:00
|
|
|
this.setState({ showEmojiKeyboard: false });
|
2017-12-08 19:36:03 +00:00
|
|
|
}
|
2018-03-07 00:17:20 +00:00
|
|
|
|
2018-11-05 19:03:17 +00:00
|
|
|
submit = async() => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
onSubmit, rid: roomId
|
2018-09-25 19:28:42 +00:00
|
|
|
} = this.props;
|
2018-11-05 19:03:17 +00:00
|
|
|
const message = this.text;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-05-27 16:19:39 +00:00
|
|
|
this.clearInput();
|
2018-01-16 18:48:05 +00:00
|
|
|
this.closeEmoji();
|
2017-12-20 20:14:07 +00:00
|
|
|
this.stopTrackingMention();
|
2019-02-25 16:22:48 +00:00
|
|
|
this.handleTyping(false);
|
2018-03-02 21:31:44 +00:00
|
|
|
if (message.trim() === '') {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2018-07-20 19:54:46 +00:00
|
|
|
const {
|
|
|
|
editing, replying
|
|
|
|
} = this.props;
|
|
|
|
|
2019-06-10 18:36:56 +00:00
|
|
|
// Slash command
|
|
|
|
if (message[0] === MENTIONS_TRACKING_TYPE_COMMANDS) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
|
|
|
const commandsCollection = db.collections.get('slash_commands');
|
2019-06-10 18:36:56 +00:00
|
|
|
const command = message.replace(/ .*/, '').slice(1);
|
2019-09-16 20:26:32 +00:00
|
|
|
const slashCommand = await commandsCollection.query(
|
|
|
|
Q.where('id', Q.like(`${ Q.sanitizeLikeString(command) }%`))
|
|
|
|
).fetch();
|
2019-06-10 18:36:56 +00:00
|
|
|
if (slashCommand.length > 0) {
|
|
|
|
try {
|
|
|
|
const messageWithoutCommand = message.substr(message.indexOf(' ') + 1);
|
|
|
|
RocketChat.runSlashCommand(command, roomId, messageWithoutCommand);
|
|
|
|
} catch (e) {
|
2019-08-30 12:43:23 +00:00
|
|
|
log(e);
|
2019-06-10 18:36:56 +00:00
|
|
|
}
|
|
|
|
this.clearInput();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
// Edit
|
2018-03-02 21:31:44 +00:00
|
|
|
if (editing) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { message: editingMessage, editRequest } = this.props;
|
|
|
|
const { id, subscription: { id: rid } } = editingMessage;
|
|
|
|
editRequest({ id, msg: message, rid });
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
// Reply
|
2018-07-20 19:54:46 +00:00
|
|
|
} else if (replying) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const {
|
|
|
|
message: replyingMessage, replyCancel, threadsEnabled, replyWithMention
|
|
|
|
} = this.props;
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
// Thread
|
2019-09-16 20:26:32 +00:00
|
|
|
if (threadsEnabled && replyWithMention) {
|
|
|
|
onSubmit(message, replyingMessage.id);
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2019-05-03 13:33:38 +00:00
|
|
|
// Legacy reply or quote (quote is a reply without mention)
|
2019-04-17 17:01:03 +00:00
|
|
|
} else {
|
|
|
|
const { user, roomType } = this.props;
|
2019-09-16 20:26:32 +00:00
|
|
|
const permalink = await this.getPermalink(replyingMessage);
|
2019-04-17 17:01:03 +00:00
|
|
|
let msg = `[ ](${ permalink }) `;
|
2018-07-20 19:54:46 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
// if original message wasn't sent by current user and neither from a direct room
|
2019-09-16 20:26:32 +00:00
|
|
|
if (user.username !== replyingMessage.u.username && roomType !== 'd' && replyWithMention) {
|
|
|
|
msg += `@${ replyingMessage.u.username } `;
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg = `${ msg } ${ message }`;
|
|
|
|
onSubmit(msg);
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
replyCancel();
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
// Normal message
|
2018-03-02 21:31:44 +00:00
|
|
|
} else {
|
2018-09-25 19:28:42 +00:00
|
|
|
onSubmit(message);
|
2018-03-02 21:31:44 +00:00
|
|
|
}
|
2017-11-24 20:44:52 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
updateMentions = (keyword, type) => {
|
|
|
|
if (type === MENTIONS_TRACKING_TYPE_USERS) {
|
|
|
|
this.getUsers(keyword);
|
|
|
|
} else if (type === MENTIONS_TRACKING_TYPE_EMOJIS) {
|
|
|
|
this.getEmojis(keyword);
|
2019-06-10 18:36:56 +00:00
|
|
|
} else if (type === MENTIONS_TRACKING_TYPE_COMMANDS) {
|
|
|
|
this.getSlashCommands(keyword);
|
2018-09-25 19:28:42 +00:00
|
|
|
} else {
|
|
|
|
this.getRooms(keyword);
|
2017-12-20 20:14:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
identifyMentionKeyword = (keyword, type) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
this.setState({
|
|
|
|
showEmojiKeyboard: false,
|
|
|
|
trackingType: type
|
2017-12-20 20:14:07 +00:00
|
|
|
});
|
2018-09-25 19:28:42 +00:00
|
|
|
this.updateMentions(keyword, type);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
stopTrackingMention = () => {
|
2019-09-25 21:32:13 +00:00
|
|
|
const { trackingType, showCommandPreview } = this.state;
|
|
|
|
if (!trackingType && !showCommandPreview) {
|
2018-11-05 19:03:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-12-20 20:14:07 +00:00
|
|
|
this.setState({
|
2018-01-30 19:48:26 +00:00
|
|
|
mentions: [],
|
2019-06-10 18:36:56 +00:00
|
|
|
trackingType: '',
|
2019-09-25 21:32:13 +00:00
|
|
|
commandPreview: [],
|
|
|
|
showCommandPreview: false
|
2017-12-20 20:14:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-19 12:38:14 +00:00
|
|
|
renderFixedMentionItem = item => (
|
2017-12-20 20:14:07 +00:00
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.mentionItem}
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress={() => this.onPressMention(item)}
|
2017-12-20 20:14:07 +00:00
|
|
|
>
|
2018-01-19 12:38:14 +00:00
|
|
|
<Text style={styles.fixedMentionAvatar}>{item.username}</Text>
|
2019-03-29 19:36:07 +00:00
|
|
|
<Text style={styles.mentionText}>{item.username === 'here' ? I18n.t('Notify_active_in_this_room') : I18n.t('Notify_all_in_this_room')}</Text>
|
2017-12-20 20:14:07 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
)
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
renderMentionEmoji = (item) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { baseUrl } = this.props;
|
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
if (item.name) {
|
|
|
|
return (
|
|
|
|
<CustomEmoji
|
|
|
|
key='mention-item-avatar'
|
2018-02-08 14:08:50 +00:00
|
|
|
style={styles.mentionItemCustomEmoji}
|
2018-01-30 19:48:26 +00:00
|
|
|
emoji={item}
|
2018-09-25 19:28:42 +00:00
|
|
|
baseUrl={baseUrl}
|
2018-01-30 19:48:26 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Text
|
|
|
|
key='mention-item-avatar'
|
2018-02-08 14:08:50 +00:00
|
|
|
style={styles.mentionItemEmoji}
|
2018-01-30 19:48:26 +00:00
|
|
|
>
|
2019-09-16 20:50:51 +00:00
|
|
|
{shortnameToUnicode(`:${ item }:`)}
|
2018-01-30 19:48:26 +00:00
|
|
|
</Text>
|
|
|
|
);
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-06-10 18:36:56 +00:00
|
|
|
renderMentionItem = ({ item }) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { trackingType } = this.state;
|
2019-02-07 19:58:20 +00:00
|
|
|
const { baseUrl, user } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-01-19 12:38:14 +00:00
|
|
|
if (item.username === 'all' || item.username === 'here') {
|
|
|
|
return this.renderFixedMentionItem(item);
|
|
|
|
}
|
2019-06-10 18:36:56 +00:00
|
|
|
const defineTestID = (type) => {
|
|
|
|
switch (type) {
|
|
|
|
case MENTIONS_TRACKING_TYPE_EMOJIS:
|
|
|
|
return `mention-item-${ item.name || item }`;
|
|
|
|
case MENTIONS_TRACKING_TYPE_COMMANDS:
|
|
|
|
return `mention-item-${ item.command || item }`;
|
|
|
|
default:
|
|
|
|
return `mention-item-${ item.username || item.name || item }`;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const testID = defineTestID(trackingType);
|
|
|
|
|
2018-01-19 12:38:14 +00:00
|
|
|
return (
|
|
|
|
<TouchableOpacity
|
|
|
|
style={styles.mentionItem}
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress={() => this.onPressMention(item)}
|
2019-06-10 18:36:56 +00:00
|
|
|
testID={testID}
|
2018-01-19 12:38:14 +00:00
|
|
|
>
|
2019-06-10 18:36:56 +00:00
|
|
|
|
|
|
|
{(() => {
|
|
|
|
switch (trackingType) {
|
|
|
|
case MENTIONS_TRACKING_TYPE_EMOJIS:
|
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2019-06-10 18:36:56 +00:00
|
|
|
{this.renderMentionEmoji(item)}
|
|
|
|
<Text key='mention-item-name' style={styles.mentionText}>:{ item.name || item }:</Text>
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2019-06-10 18:36:56 +00:00
|
|
|
);
|
|
|
|
case MENTIONS_TRACKING_TYPE_COMMANDS:
|
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2019-06-10 18:36:56 +00:00
|
|
|
<Text key='mention-item-command' style={styles.slash}>/</Text>
|
|
|
|
<Text key='mention-item-param'>{ item.command}</Text>
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2019-06-10 18:36:56 +00:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2019-06-10 18:36:56 +00:00
|
|
|
<Avatar
|
|
|
|
key='mention-item-avatar'
|
|
|
|
style={styles.avatar}
|
|
|
|
text={item.username || item.name}
|
|
|
|
size={30}
|
2019-09-16 20:26:32 +00:00
|
|
|
type={item.t}
|
2019-06-10 18:36:56 +00:00
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={user.id}
|
|
|
|
token={user.token}
|
|
|
|
/>
|
|
|
|
<Text key='mention-item-name' style={styles.mentionText}>{ item.username || item.name || item }</Text>
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2019-06-10 18:36:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
})()
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
2018-01-19 12:38:14 +00:00
|
|
|
</TouchableOpacity>
|
|
|
|
);
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-05-18 17:55:08 +00:00
|
|
|
renderMentions = () => {
|
|
|
|
const { mentions, trackingType } = this.state;
|
|
|
|
if (!trackingType) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
2019-06-10 18:36:56 +00:00
|
|
|
<ScrollView
|
|
|
|
testID='messagebox-container'
|
|
|
|
style={styles.scrollViewMention}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
>
|
2018-05-23 13:39:18 +00:00
|
|
|
<FlatList
|
|
|
|
style={styles.mentionList}
|
|
|
|
data={mentions}
|
2019-06-10 18:36:56 +00:00
|
|
|
renderItem={this.renderMentionItem}
|
|
|
|
keyExtractor={item => item._id || item.username || item.command || item}
|
2018-05-23 13:39:18 +00:00
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
/>
|
2019-06-10 18:36:56 +00:00
|
|
|
</ScrollView>
|
2018-05-18 17:55:08 +00:00
|
|
|
);
|
|
|
|
};
|
2018-02-08 14:08:50 +00:00
|
|
|
|
2019-06-10 18:36:56 +00:00
|
|
|
renderCommandPreviewItem = ({ item }) => (
|
|
|
|
<CommandPreview item={item} onPress={this.onPressCommandPreview} />
|
|
|
|
);
|
|
|
|
|
|
|
|
renderCommandPreview = () => {
|
2019-09-25 21:32:13 +00:00
|
|
|
const { commandPreview, showCommandPreview } = this.state;
|
|
|
|
if (!showCommandPreview) {
|
2019-06-10 18:36:56 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<View key='commandbox-container' testID='commandbox-container'>
|
|
|
|
<FlatList
|
|
|
|
style={styles.mentionList}
|
|
|
|
data={commandPreview}
|
|
|
|
renderItem={this.renderCommandPreviewItem}
|
|
|
|
keyExtractor={item => item.id}
|
|
|
|
keyboardShouldPersistTaps='always'
|
|
|
|
horizontal
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-20 19:54:46 +00:00
|
|
|
renderReplyPreview = () => {
|
2018-09-11 16:32:52 +00:00
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
message, replying, replyCancel, user, getCustomEmoji
|
2018-09-11 16:32:52 +00:00
|
|
|
} = this.props;
|
2018-07-20 19:54:46 +00:00
|
|
|
if (!replying) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
return <ReplyPreview key='reply-preview' message={message} close={replyCancel} username={user.username} getCustomEmoji={getCustomEmoji} />;
|
2018-07-20 19:54:46 +00:00
|
|
|
};
|
|
|
|
|
2019-02-27 14:23:40 +00:00
|
|
|
renderContent = () => {
|
2019-05-27 16:19:39 +00:00
|
|
|
const { recording, showEmojiKeyboard, showSend } = this.state;
|
2018-09-25 19:28:42 +00:00
|
|
|
const { editing } = this.props;
|
|
|
|
|
|
|
|
if (recording) {
|
2018-03-07 00:17:20 +00:00
|
|
|
return (<Recording onFinish={this.finishAudioMessage} />);
|
|
|
|
}
|
2017-08-09 13:12:00 +00:00
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2019-06-10 18:36:56 +00:00
|
|
|
{this.renderCommandPreview()}
|
2019-05-27 16:19:39 +00:00
|
|
|
{this.renderMentions()}
|
2018-09-11 16:32:52 +00:00
|
|
|
<View style={styles.composer} key='messagebox'>
|
|
|
|
{this.renderReplyPreview()}
|
|
|
|
<View
|
2018-09-25 19:28:42 +00:00
|
|
|
style={[styles.textArea, editing && styles.editing]}
|
2018-09-11 16:32:52 +00:00
|
|
|
testID='messagebox'
|
|
|
|
>
|
2019-05-27 16:19:39 +00:00
|
|
|
<LeftButtons
|
|
|
|
showEmojiKeyboard={showEmojiKeyboard}
|
|
|
|
editing={editing}
|
|
|
|
showFileActions={this.showFileActions}
|
|
|
|
editCancel={this.editCancel}
|
|
|
|
openEmoji={this.openEmoji}
|
|
|
|
closeEmoji={this.closeEmoji}
|
|
|
|
/>
|
2018-09-11 16:32:52 +00:00
|
|
|
<TextInput
|
|
|
|
ref={component => this.component = component}
|
|
|
|
style={styles.textBoxInput}
|
|
|
|
returnKeyType='default'
|
|
|
|
keyboardType='twitter'
|
|
|
|
blurOnSubmit={false}
|
|
|
|
placeholder={I18n.t('New_Message')}
|
2019-02-27 14:23:40 +00:00
|
|
|
onChangeText={this.onChangeText}
|
2018-09-11 16:32:52 +00:00
|
|
|
underlineColorAndroid='transparent'
|
|
|
|
defaultValue=''
|
|
|
|
multiline
|
2019-03-29 19:36:07 +00:00
|
|
|
placeholderTextColor={COLOR_TEXT_DESCRIPTION}
|
2018-09-11 16:32:52 +00:00
|
|
|
testID='messagebox-input'
|
|
|
|
/>
|
2019-05-27 16:19:39 +00:00
|
|
|
<RightButtons
|
|
|
|
showSend={showSend}
|
|
|
|
submit={this.submit}
|
|
|
|
recordAudioMessage={this.recordAudioMessage}
|
|
|
|
showFileActions={this.showFileActions}
|
|
|
|
/>
|
2018-09-11 16:32:52 +00:00
|
|
|
</View>
|
2018-04-10 13:03:54 +00:00
|
|
|
</View>
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2018-02-08 14:08:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-09-16 20:26:32 +00:00
|
|
|
console.count(`${ this.constructor.name }.render calls`);
|
2018-09-25 19:28:42 +00:00
|
|
|
const { showEmojiKeyboard, file } = this.state;
|
2018-02-08 14:08:50 +00:00
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2018-07-17 19:10:27 +00:00
|
|
|
<KeyboardAccessoryView
|
2019-02-27 14:23:40 +00:00
|
|
|
renderContent={this.renderContent}
|
2018-07-17 19:10:27 +00:00
|
|
|
kbInputRef={this.component}
|
2018-09-25 19:28:42 +00:00
|
|
|
kbComponent={showEmojiKeyboard ? 'EmojiKeyboard' : null}
|
2019-02-27 14:23:40 +00:00
|
|
|
onKeyboardResigned={this.onKeyboardResigned}
|
2018-09-25 19:28:42 +00:00
|
|
|
onItemSelected={this.onEmojiSelected}
|
2018-07-17 19:10:27 +00:00
|
|
|
trackInteractive
|
|
|
|
// revealKeyboardInteractive
|
|
|
|
requiresSameParentToManageScrollView
|
|
|
|
addBottomView
|
2019-05-27 16:19:39 +00:00
|
|
|
/>
|
2018-07-17 19:10:27 +00:00
|
|
|
<UploadModal
|
2018-09-25 19:28:42 +00:00
|
|
|
isVisible={(file && file.isVisible)}
|
|
|
|
file={file}
|
2018-07-17 19:10:27 +00:00
|
|
|
close={() => this.setState({ file: {} })}
|
2019-07-18 17:07:37 +00:00
|
|
|
submit={this.sendMediaMessage}
|
2018-07-17 19:10:27 +00:00
|
|
|
/>
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2017-08-09 13:12:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
baseUrl: state.settings.Site_Url || state.server ? state.server.server : '',
|
2019-04-17 17:01:03 +00:00
|
|
|
threadsEnabled: state.settings.Threads_enabled,
|
2019-04-08 12:35:28 +00:00
|
|
|
user: {
|
|
|
|
id: state.login.user && state.login.user.id,
|
|
|
|
username: state.login.user && state.login.user.username,
|
|
|
|
token: state.login.user && state.login.user.token
|
2019-09-24 20:16:59 +00:00
|
|
|
},
|
|
|
|
FileUpload_MediaTypeWhiteList: state.settings.FileUpload_MediaTypeWhiteList,
|
|
|
|
FileUpload_MaxFileSize: state.settings.FileUpload_MaxFileSize
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const dispatchToProps = ({
|
2019-09-16 20:26:32 +00:00
|
|
|
typing: (rid, status) => userTypingAction(rid, status)
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, dispatchToProps, null, { forwardRef: true })(MessageBox);
|