2017-08-04 00:34:37 +00:00
|
|
|
import React from 'react';
|
2017-08-05 18:16:32 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2019-04-08 12:35:28 +00:00
|
|
|
Text, View, LayoutAnimation, InteractionManager
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { RectButton } from 'react-native-gesture-handler';
|
2019-03-12 16:23:06 +00:00
|
|
|
import { SafeAreaView } from 'react-navigation';
|
2019-02-07 15:48:10 +00:00
|
|
|
import equal from 'deep-equal';
|
2019-03-27 20:06:57 +00:00
|
|
|
import moment from 'moment';
|
2019-04-17 17:01:03 +00:00
|
|
|
import EJSON from 'ejson';
|
2019-06-28 17:07:17 +00:00
|
|
|
import * as Haptics from 'expo-haptics';
|
2017-08-13 01:35:09 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
import {
|
|
|
|
toggleReactionPicker as toggleReactionPickerAction,
|
|
|
|
actionsShow as actionsShowAction,
|
2019-05-20 20:43:50 +00:00
|
|
|
errorActionsShow as errorActionsShowAction,
|
2019-04-08 12:35:28 +00:00
|
|
|
editCancel as editCancelAction,
|
2019-05-20 20:43:50 +00:00
|
|
|
replyCancel as replyCancelAction,
|
|
|
|
replyBroadcast as replyBroadcastAction
|
2019-04-08 12:35:28 +00:00
|
|
|
} from '../../actions/messages';
|
2019-03-27 20:06:57 +00:00
|
|
|
import { List } from './List';
|
2019-04-04 18:08:40 +00:00
|
|
|
import database, { safeAddListener } from '../../lib/realm';
|
2017-12-08 19:13:21 +00:00
|
|
|
import RocketChat from '../../lib/rocketchat';
|
|
|
|
import Message from '../../containers/message';
|
|
|
|
import MessageActions from '../../containers/MessageActions';
|
2017-12-13 15:00:26 +00:00
|
|
|
import MessageErrorActions from '../../containers/MessageErrorActions';
|
2017-12-08 19:13:21 +00:00
|
|
|
import MessageBox from '../../containers/MessageBox';
|
2018-01-30 19:48:26 +00:00
|
|
|
import ReactionPicker from './ReactionPicker';
|
2018-07-17 19:10:27 +00:00
|
|
|
import UploadProgress from './UploadProgress';
|
2017-12-08 19:13:21 +00:00
|
|
|
import styles from './styles';
|
2018-05-18 17:55:08 +00:00
|
|
|
import log from '../../utils/log';
|
2019-01-29 19:52:56 +00:00
|
|
|
import { isIOS } from '../../utils/deviceInfo';
|
2019-04-17 17:01:03 +00:00
|
|
|
import EventEmitter from '../../utils/events';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../../i18n';
|
2019-04-17 17:01:03 +00:00
|
|
|
import RoomHeaderView, { RightButtons } from './Header';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-03-27 20:06:57 +00:00
|
|
|
import Separator from './Separator';
|
2019-03-29 19:36:07 +00:00
|
|
|
import { COLOR_WHITE } from '../../constants/colors';
|
2019-04-08 12:35:28 +00:00
|
|
|
import debounce from '../../utils/debounce';
|
2019-04-17 17:01:03 +00:00
|
|
|
import buildMessage from '../../lib/methods/helpers/buildMessage';
|
2019-05-20 20:43:50 +00:00
|
|
|
import FileModal from '../../containers/FileModal';
|
|
|
|
import ReactionsModal from '../../containers/ReactionsModal';
|
2019-07-23 14:02:57 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
2019-07-18 17:44:02 +00:00
|
|
|
import { isReadOnly, isBlocked } from '../../utils/room';
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
@connect(state => ({
|
|
|
|
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
|
|
|
|
},
|
|
|
|
actionMessage: state.messages.actionMessage,
|
2019-04-24 18:36:29 +00:00
|
|
|
editing: state.messages.editing,
|
|
|
|
replying: state.messages.replying,
|
2018-07-10 13:40:32 +00:00
|
|
|
showActions: state.messages.showActions,
|
2018-12-05 20:52:08 +00:00
|
|
|
showErrorActions: state.messages.showErrorActions,
|
2019-04-08 12:35:28 +00:00
|
|
|
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
2019-04-17 17:01:03 +00:00
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
2019-05-20 20:43:50 +00:00
|
|
|
isAuthenticated: state.login.isAuthenticated,
|
|
|
|
Message_GroupingPeriod: state.settings.Message_GroupingPeriod,
|
|
|
|
Message_TimeFormat: state.settings.Message_TimeFormat,
|
2019-05-21 12:12:15 +00:00
|
|
|
useMarkdown: state.markdown.useMarkdown,
|
2019-06-10 18:36:31 +00:00
|
|
|
baseUrl: state.settings.baseUrl || state.server ? state.server.server : '',
|
|
|
|
Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled
|
2018-07-10 13:40:32 +00:00
|
|
|
}), dispatch => ({
|
2019-04-08 12:35:28 +00:00
|
|
|
editCancel: () => dispatch(editCancelAction()),
|
|
|
|
replyCancel: () => dispatch(replyCancelAction()),
|
2018-09-25 19:28:42 +00:00
|
|
|
toggleReactionPicker: message => dispatch(toggleReactionPickerAction(message)),
|
2019-05-20 20:43:50 +00:00
|
|
|
errorActionsShow: actionMessage => dispatch(errorActionsShowAction(actionMessage)),
|
|
|
|
actionsShow: actionMessage => dispatch(actionsShowAction(actionMessage)),
|
|
|
|
replyBroadcast: message => dispatch(replyBroadcastAction(message))
|
2018-07-10 13:40:32 +00:00
|
|
|
}))
|
2019-05-28 13:03:08 +00:00
|
|
|
export default class RoomView extends React.Component {
|
2019-03-12 16:23:06 +00:00
|
|
|
static navigationOptions = ({ navigation }) => {
|
|
|
|
const rid = navigation.getParam('rid');
|
2019-04-08 12:35:28 +00:00
|
|
|
const prid = navigation.getParam('prid');
|
|
|
|
const title = navigation.getParam('name');
|
2019-03-12 16:23:06 +00:00
|
|
|
const t = navigation.getParam('t');
|
2019-04-17 17:01:03 +00:00
|
|
|
const tmid = navigation.getParam('tmid');
|
2019-05-15 19:33:30 +00:00
|
|
|
const toggleFollowThread = navigation.getParam('toggleFollowThread', () => {});
|
2018-10-23 21:39:48 +00:00
|
|
|
return {
|
2019-04-17 17:01:03 +00:00
|
|
|
headerTitleContainerStyle: styles.headerTitleContainerStyle,
|
|
|
|
headerTitle: (
|
2019-04-30 19:31:51 +00:00
|
|
|
<RoomHeaderView
|
|
|
|
rid={rid}
|
|
|
|
prid={prid}
|
|
|
|
tmid={tmid}
|
|
|
|
title={title}
|
|
|
|
type={t}
|
|
|
|
widthOffset={tmid ? 95 : 130}
|
|
|
|
/>
|
2019-04-17 17:01:03 +00:00
|
|
|
),
|
2019-05-15 19:33:30 +00:00
|
|
|
headerRight: (
|
|
|
|
<RightButtons
|
|
|
|
rid={rid}
|
|
|
|
tmid={tmid}
|
|
|
|
t={t}
|
|
|
|
navigation={navigation}
|
|
|
|
toggleFollowThread={toggleFollowThread}
|
|
|
|
/>
|
|
|
|
)
|
2018-10-23 21:39:48 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-08-05 18:16:32 +00:00
|
|
|
static propTypes = {
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2018-07-10 13:40:32 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
username: PropTypes.string.isRequired,
|
|
|
|
token: PropTypes.string.isRequired
|
|
|
|
}),
|
|
|
|
showActions: PropTypes.bool,
|
|
|
|
showErrorActions: PropTypes.bool,
|
2018-01-30 19:48:26 +00:00
|
|
|
actionMessage: PropTypes.object,
|
2018-12-05 20:52:08 +00:00
|
|
|
appState: PropTypes.string,
|
2019-04-08 12:35:28 +00:00
|
|
|
useRealName: PropTypes.bool,
|
2019-04-17 17:01:03 +00:00
|
|
|
isAuthenticated: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
Message_GroupingPeriod: PropTypes.number,
|
|
|
|
Message_TimeFormat: PropTypes.string,
|
2019-06-10 18:36:31 +00:00
|
|
|
Message_Read_Receipt_Enabled: PropTypes.bool,
|
2019-04-24 18:36:29 +00:00
|
|
|
editing: PropTypes.bool,
|
|
|
|
replying: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
baseUrl: PropTypes.string,
|
2019-05-21 12:12:15 +00:00
|
|
|
useMarkdown: PropTypes.bool,
|
2019-05-20 20:43:50 +00:00
|
|
|
toggleReactionPicker: PropTypes.func,
|
2018-07-10 13:40:32 +00:00
|
|
|
actionsShow: PropTypes.func,
|
2019-04-08 12:35:28 +00:00
|
|
|
editCancel: PropTypes.func,
|
2019-05-20 20:43:50 +00:00
|
|
|
replyCancel: PropTypes.func,
|
|
|
|
replyBroadcast: PropTypes.func,
|
|
|
|
errorActionsShow: PropTypes.func
|
2017-09-25 13:15:28 +00:00
|
|
|
};
|
2017-08-05 18:16:32 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
constructor(props) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2019-04-08 12:35:28 +00:00
|
|
|
console.time(`${ this.constructor.name } init`);
|
|
|
|
console.time(`${ this.constructor.name } mount`);
|
2019-03-12 16:23:06 +00:00
|
|
|
this.rid = props.navigation.getParam('rid');
|
2019-04-08 12:35:28 +00:00
|
|
|
this.t = props.navigation.getParam('t');
|
2019-04-17 17:01:03 +00:00
|
|
|
this.tmid = props.navigation.getParam('tmid');
|
2018-01-17 16:42:30 +00:00
|
|
|
this.rooms = database.objects('subscriptions').filtered('rid = $0', this.rid);
|
2019-06-28 17:02:30 +00:00
|
|
|
const canAutoTranslate = RocketChat.canAutoTranslate();
|
2017-08-07 18:42:02 +00:00
|
|
|
this.state = {
|
2018-09-19 14:18:32 +00:00
|
|
|
joined: this.rooms.length > 0,
|
2019-04-08 12:35:28 +00:00
|
|
|
room: this.rooms[0] || { rid: this.rid, t: this.t },
|
2019-05-20 20:43:50 +00:00
|
|
|
lastOpen: null,
|
|
|
|
photoModalVisible: false,
|
|
|
|
reactionsModalVisible: false,
|
|
|
|
selectedAttachment: {},
|
2019-06-28 17:02:30 +00:00
|
|
|
selectedMessage: {},
|
|
|
|
canAutoTranslate
|
2017-08-07 18:42:02 +00:00
|
|
|
};
|
2019-03-27 20:06:57 +00:00
|
|
|
this.beginAnimating = false;
|
2019-04-08 12:35:28 +00:00
|
|
|
this.beginAnimatingTimeout = setTimeout(() => this.beginAnimating = true, 300);
|
|
|
|
this.messagebox = React.createRef();
|
2019-05-03 14:54:57 +00:00
|
|
|
this.willBlurListener = props.navigation.addListener('willBlur', () => this.mounted = false);
|
|
|
|
this.mounted = false;
|
2019-04-08 12:35:28 +00:00
|
|
|
console.timeEnd(`${ this.constructor.name } init`);
|
2017-08-07 00:34:35 +00:00
|
|
|
}
|
2017-08-04 00:34:37 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
componentDidMount() {
|
2019-04-17 17:01:03 +00:00
|
|
|
this.didMountInteraction = InteractionManager.runAfterInteractions(() => {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { room } = this.state;
|
2019-04-17 17:01:03 +00:00
|
|
|
const { navigation, isAuthenticated } = this.props;
|
2019-04-08 12:35:28 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
if (room._id && !this.tmid) {
|
2019-04-08 12:35:28 +00:00
|
|
|
navigation.setParams({ name: this.getRoomTitle(room), t: room.t });
|
|
|
|
}
|
2019-05-15 19:33:30 +00:00
|
|
|
if (this.tmid) {
|
|
|
|
navigation.setParams({ toggleFollowThread: this.toggleFollowThread });
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
if (isAuthenticated) {
|
|
|
|
this.init();
|
|
|
|
} else {
|
|
|
|
EventEmitter.addEventListener('connected', this.handleConnected);
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
safeAddListener(this.rooms, this.updateRoom);
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = true;
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
|
|
|
console.timeEnd(`${ this.constructor.name } mount`);
|
2018-02-08 14:08:50 +00:00
|
|
|
}
|
2018-09-19 14:18:32 +00:00
|
|
|
|
2018-01-09 17:12:55 +00:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2018-09-26 13:56:36 +00:00
|
|
|
const {
|
2019-06-28 17:02:30 +00:00
|
|
|
room, joined, lastOpen, photoModalVisible, reactionsModalVisible, canAutoTranslate
|
2018-09-26 13:56:36 +00:00
|
|
|
} = this.state;
|
2018-12-05 20:52:08 +00:00
|
|
|
const { showActions, showErrorActions, appState } = this.props;
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
if (lastOpen !== nextState.lastOpen) {
|
|
|
|
return true;
|
2019-05-20 20:43:50 +00:00
|
|
|
} else if (photoModalVisible !== nextState.photoModalVisible) {
|
|
|
|
return true;
|
|
|
|
} else if (reactionsModalVisible !== nextState.reactionsModalVisible) {
|
|
|
|
return true;
|
2019-04-17 17:01:03 +00:00
|
|
|
} else if (room.ro !== nextState.room.ro) {
|
2018-09-26 13:56:36 +00:00
|
|
|
return true;
|
2018-10-23 21:39:48 +00:00
|
|
|
} else if (room.f !== nextState.room.f) {
|
|
|
|
return true;
|
2018-12-12 15:15:10 +00:00
|
|
|
} else if (room.blocked !== nextState.room.blocked) {
|
|
|
|
return true;
|
|
|
|
} else if (room.blocker !== nextState.room.blocker) {
|
|
|
|
return true;
|
|
|
|
} else if (room.archived !== nextState.room.archived) {
|
|
|
|
return true;
|
2018-09-26 13:56:36 +00:00
|
|
|
} else if (joined !== nextState.joined) {
|
|
|
|
return true;
|
2019-06-28 17:02:30 +00:00
|
|
|
} else if (canAutoTranslate !== nextState.canAutoTranslate) {
|
|
|
|
return true;
|
2018-09-26 13:56:36 +00:00
|
|
|
} else if (showActions !== nextProps.showActions) {
|
|
|
|
return true;
|
2018-11-16 11:06:29 +00:00
|
|
|
} else if (showErrorActions !== nextProps.showErrorActions) {
|
|
|
|
return true;
|
2018-12-05 20:52:08 +00:00
|
|
|
} else if (appState !== nextProps.appState) {
|
|
|
|
return true;
|
2019-02-07 15:48:10 +00:00
|
|
|
} else if (!equal(room.muted, nextState.room.muted)) {
|
|
|
|
return true;
|
2018-09-26 13:56:36 +00:00
|
|
|
}
|
|
|
|
return false;
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
componentDidUpdate(prevProps) {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { room } = this.state;
|
2019-04-08 12:35:28 +00:00
|
|
|
const { appState } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
if (appState === 'foreground' && appState !== prevProps.appState) {
|
|
|
|
this.onForegroundInteraction = InteractionManager.runAfterInteractions(() => {
|
|
|
|
RocketChat.loadMissedMessages(room).catch(e => console.log(e));
|
|
|
|
RocketChat.readMessages(room.rid).catch(e => console.log(e));
|
|
|
|
});
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-07 00:34:35 +00:00
|
|
|
componentWillUnmount() {
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = false;
|
2019-04-24 18:36:29 +00:00
|
|
|
const { editing, replying } = this.props;
|
2019-06-08 11:31:29 +00:00
|
|
|
if (!editing && this.messagebox && this.messagebox.current) {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { text } = this.messagebox.current;
|
2019-04-24 18:36:29 +00:00
|
|
|
let obj;
|
|
|
|
if (this.tmid) {
|
|
|
|
obj = database.objectForPrimaryKey('threads', this.tmid);
|
|
|
|
} else {
|
|
|
|
[obj] = this.rooms;
|
|
|
|
}
|
|
|
|
if (obj) {
|
2019-04-17 17:01:03 +00:00
|
|
|
database.write(() => {
|
2019-04-24 18:36:29 +00:00
|
|
|
obj.draftMessage = text;
|
2019-04-17 17:01:03 +00:00
|
|
|
});
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
this.rooms.removeAllListeners();
|
2019-04-08 12:35:28 +00:00
|
|
|
if (this.sub && this.sub.stop) {
|
|
|
|
this.sub.stop();
|
|
|
|
}
|
|
|
|
if (this.beginAnimatingTimeout) {
|
|
|
|
clearTimeout(this.beginAnimatingTimeout);
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
if (editing) {
|
|
|
|
const { editCancel } = this.props;
|
|
|
|
editCancel();
|
|
|
|
}
|
|
|
|
if (replying) {
|
|
|
|
const { replyCancel } = this.props;
|
|
|
|
replyCancel();
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
if (this.didMountInteraction && this.didMountInteraction.cancel) {
|
|
|
|
this.didMountInteraction.cancel();
|
|
|
|
}
|
|
|
|
if (this.onForegroundInteraction && this.onForegroundInteraction.cancel) {
|
|
|
|
this.onForegroundInteraction.cancel();
|
|
|
|
}
|
|
|
|
if (this.updateStateInteraction && this.updateStateInteraction.cancel) {
|
|
|
|
this.updateStateInteraction.cancel();
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
if (this.initInteraction && this.initInteraction.cancel) {
|
|
|
|
this.initInteraction.cancel();
|
|
|
|
}
|
2019-05-03 14:54:57 +00:00
|
|
|
if (this.willBlurListener && this.willBlurListener.remove) {
|
|
|
|
this.willBlurListener.remove();
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
2019-04-08 12:35:28 +00:00
|
|
|
console.countReset(`${ this.constructor.name }.render calls`);
|
2017-08-04 00:34:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
init = () => {
|
|
|
|
try {
|
|
|
|
this.initInteraction = InteractionManager.runAfterInteractions(async() => {
|
|
|
|
const { room } = this.state;
|
|
|
|
if (this.tmid) {
|
2019-04-24 18:36:29 +00:00
|
|
|
await this.getThreadMessages();
|
2019-04-17 17:01:03 +00:00
|
|
|
} else {
|
|
|
|
await this.getMessages(room);
|
|
|
|
|
|
|
|
// if room is joined
|
|
|
|
if (room._id) {
|
|
|
|
if (room.alert || room.unread || room.userMentions) {
|
|
|
|
this.setLastOpen(room.ls);
|
|
|
|
} else {
|
|
|
|
this.setLastOpen(null);
|
|
|
|
}
|
|
|
|
RocketChat.readMessages(room.rid).catch(e => console.log(e));
|
|
|
|
this.sub = await RocketChat.subscribeRoom(room);
|
|
|
|
}
|
|
|
|
}
|
2019-06-28 17:02:30 +00:00
|
|
|
|
|
|
|
// We run `canAutoTranslate` again in order to refetch auto translate permission
|
|
|
|
// in case of a missing connection or poor connection on room open
|
|
|
|
const canAutoTranslate = RocketChat.canAutoTranslate();
|
|
|
|
this.setState({ canAutoTranslate });
|
2019-04-17 17:01:03 +00:00
|
|
|
});
|
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_room_init', e);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-19 21:19:39 +00:00
|
|
|
onMessageLongPress = (message) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { actionsShow } = this.props;
|
2019-04-24 18:36:29 +00:00
|
|
|
actionsShow({ ...message, rid: this.rid });
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
onOpenFileModal = (attachment) => {
|
|
|
|
this.setState({ selectedAttachment: attachment, photoModalVisible: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
onCloseFileModal = () => {
|
|
|
|
this.setState({ selectedAttachment: {}, photoModalVisible: false });
|
|
|
|
}
|
|
|
|
|
2018-01-30 19:48:26 +00:00
|
|
|
onReactionPress = (shortname, messageId) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { actionMessage, toggleReactionPicker } = this.props;
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
|
|
|
if (!messageId) {
|
2018-09-25 19:28:42 +00:00
|
|
|
RocketChat.setReaction(shortname, actionMessage._id);
|
|
|
|
return toggleReactionPicker();
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
|
|
|
RocketChat.setReaction(shortname, messageId);
|
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_room_on_reaction_press', e);
|
2018-01-30 19:48:26 +00:00
|
|
|
}
|
|
|
|
};
|
2017-08-04 00:34:37 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
onReactionLongPress = (message) => {
|
|
|
|
this.setState({ selectedMessage: message, reactionsModalVisible: true });
|
2019-06-28 17:07:17 +00:00
|
|
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onCloseReactionsModal = () => {
|
|
|
|
this.setState({ selectedMessage: {}, reactionsModalVisible: false });
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
onDiscussionPress = debounce((item) => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.push('RoomView', {
|
|
|
|
rid: item.drid, prid: item.rid, name: item.msg, t: 'p'
|
|
|
|
});
|
|
|
|
}, 1000, true)
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
onThreadPress = debounce((item) => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
if (item.tmid) {
|
|
|
|
navigation.push('RoomView', {
|
|
|
|
rid: item.rid, tmid: item.tmid, name: item.tmsg, t: 'thread'
|
|
|
|
});
|
|
|
|
} else if (item.tlm) {
|
|
|
|
const title = item.msg || (item.attachments && item.attachments.length && item.attachments[0].title);
|
|
|
|
navigation.push('RoomView', {
|
|
|
|
rid: item.rid, tmid: item._id, name: title, t: 'thread'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 1000, true)
|
|
|
|
|
|
|
|
toggleReactionPicker = (message) => {
|
|
|
|
const { toggleReactionPicker } = this.props;
|
|
|
|
toggleReactionPicker(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
replyBroadcast = (message) => {
|
|
|
|
const { replyBroadcast } = this.props;
|
|
|
|
replyBroadcast(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
errorActionsShow = (message) => {
|
|
|
|
const { errorActionsShow } = this.props;
|
|
|
|
errorActionsShow(message);
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
handleConnected = () => {
|
|
|
|
this.init();
|
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
internalSetState = (...args) => {
|
2019-05-03 14:54:57 +00:00
|
|
|
if (!this.mounted) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-27 20:06:57 +00:00
|
|
|
if (isIOS && this.beginAnimating) {
|
2018-10-29 13:54:23 +00:00
|
|
|
LayoutAnimation.easeInEaseOut();
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
this.setState(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRoom = () => {
|
2019-04-08 12:35:28 +00:00
|
|
|
this.updateStateInteraction = InteractionManager.runAfterInteractions(() => {
|
2019-04-17 17:01:03 +00:00
|
|
|
if (this.rooms[0]) {
|
|
|
|
const room = JSON.parse(JSON.stringify(this.rooms[0] || {}));
|
|
|
|
this.internalSetState({ room });
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
2019-03-12 16:23:06 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
sendMessage = (message, tmid) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { user } = this.props;
|
2018-06-20 13:40:33 +00:00
|
|
|
LayoutAnimation.easeInEaseOut();
|
2019-07-29 16:33:28 +00:00
|
|
|
RocketChat.sendMessage(this.rid, message, this.tmid || tmid, user).then(() => {
|
2019-03-27 20:06:57 +00:00
|
|
|
this.setLastOpen(null);
|
2018-02-08 14:08:50 +00:00
|
|
|
});
|
|
|
|
};
|
2017-08-09 01:40:55 +00:00
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
getRoomTitle = (room) => {
|
|
|
|
const { useRealName } = this.props;
|
|
|
|
return ((room.prid || useRealName) && room.fname) || room.name;
|
|
|
|
}
|
|
|
|
|
2019-04-30 19:31:51 +00:00
|
|
|
getMessages = async() => {
|
2019-04-17 17:01:03 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
try {
|
|
|
|
if (room.lastOpen) {
|
2019-04-30 19:31:51 +00:00
|
|
|
await RocketChat.loadMissedMessages(room);
|
2019-04-17 17:01:03 +00:00
|
|
|
} else {
|
2019-04-30 19:31:51 +00:00
|
|
|
await RocketChat.loadMessagesForRoom(room);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2019-04-30 19:31:51 +00:00
|
|
|
return Promise.resolve();
|
2019-04-17 17:01:03 +00:00
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_get_messages', e);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-24 18:36:29 +00:00
|
|
|
getThreadMessages = () => {
|
|
|
|
try {
|
|
|
|
return RocketChat.loadThreadMessages({ tmid: this.tmid });
|
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_get_thread_messages', e);
|
2019-04-24 18:36:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
setLastOpen = lastOpen => this.setState({ lastOpen });
|
2019-03-27 20:06:57 +00:00
|
|
|
|
2017-09-21 17:08:00 +00:00
|
|
|
joinRoom = async() => {
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2019-06-20 19:02:50 +00:00
|
|
|
await RocketChat.joinRoom(this.rid, this.t);
|
|
|
|
this.internalSetState({
|
|
|
|
joined: true
|
|
|
|
});
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_join_room', e);
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2017-08-10 16:16:32 +00:00
|
|
|
};
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
fetchThreadName = async(tmid) => {
|
|
|
|
try {
|
|
|
|
// TODO: we should build a tmid queue here in order to search for a single tmid only once
|
|
|
|
const thread = await RocketChat.getSingleMessage(tmid);
|
|
|
|
database.write(() => {
|
|
|
|
database.create('threads', buildMessage(EJSON.fromJSONValue(thread)), true);
|
|
|
|
});
|
|
|
|
} catch (error) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_fetch_thread_name', error);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 19:33:30 +00:00
|
|
|
toggleFollowThread = async(isFollowingThread) => {
|
|
|
|
try {
|
|
|
|
await RocketChat.toggleFollowMessage(this.tmid, !isFollowingThread);
|
2019-07-23 14:02:57 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: isFollowingThread ? 'Unfollowed thread' : 'Following thread' });
|
2019-05-15 19:33:30 +00:00
|
|
|
} catch (e) {
|
2019-05-28 16:18:46 +00:00
|
|
|
log('err_toggle_follow_thread', e);
|
2019-05-15 19:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
renderItem = (item, previousItem) => {
|
2019-06-28 17:02:30 +00:00
|
|
|
const { room, lastOpen, canAutoTranslate } = this.state;
|
2019-05-20 20:43:50 +00:00
|
|
|
const {
|
2019-06-10 18:36:31 +00:00
|
|
|
user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, useMarkdown, Message_Read_Receipt_Enabled
|
2019-05-20 20:43:50 +00:00
|
|
|
} = this.props;
|
2019-03-27 20:06:57 +00:00
|
|
|
let dateSeparator = null;
|
|
|
|
let showUnreadSeparator = false;
|
|
|
|
|
|
|
|
if (!previousItem) {
|
|
|
|
dateSeparator = item.ts;
|
|
|
|
showUnreadSeparator = moment(item.ts).isAfter(lastOpen);
|
|
|
|
} else {
|
|
|
|
showUnreadSeparator = lastOpen
|
|
|
|
&& moment(item.ts).isAfter(lastOpen)
|
|
|
|
&& moment(previousItem.ts).isBefore(lastOpen);
|
|
|
|
if (!moment(item.ts).isSame(previousItem.ts, 'day')) {
|
2019-04-08 12:35:28 +00:00
|
|
|
dateSeparator = item.ts;
|
2019-03-27 20:06:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
const message = (
|
2018-09-25 19:28:42 +00:00
|
|
|
<Message
|
|
|
|
key={item._id}
|
|
|
|
item={item}
|
|
|
|
user={user}
|
|
|
|
archived={room.archived}
|
|
|
|
broadcast={room.broadcast}
|
2019-04-17 17:01:03 +00:00
|
|
|
status={item.status}
|
2018-09-25 19:28:42 +00:00
|
|
|
_updatedAt={item._updatedAt}
|
2019-04-17 17:01:03 +00:00
|
|
|
previousItem={previousItem}
|
|
|
|
fetchThreadName={this.fetchThreadName}
|
2018-09-25 19:28:42 +00:00
|
|
|
onReactionPress={this.onReactionPress}
|
2019-05-20 20:43:50 +00:00
|
|
|
onReactionLongPress={this.onReactionLongPress}
|
2018-09-25 19:28:42 +00:00
|
|
|
onLongPress={this.onMessageLongPress}
|
2019-04-08 12:35:28 +00:00
|
|
|
onDiscussionPress={this.onDiscussionPress}
|
2019-05-20 20:43:50 +00:00
|
|
|
onThreadPress={this.onThreadPress}
|
|
|
|
onOpenFileModal={this.onOpenFileModal}
|
|
|
|
toggleReactionPicker={this.toggleReactionPicker}
|
|
|
|
replyBroadcast={this.replyBroadcast}
|
|
|
|
errorActionsShow={this.errorActionsShow}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
Message_GroupingPeriod={Message_GroupingPeriod}
|
|
|
|
timeFormat={Message_TimeFormat}
|
|
|
|
useRealName={useRealName}
|
2019-05-21 12:12:15 +00:00
|
|
|
useMarkdown={useMarkdown}
|
2019-06-10 18:36:31 +00:00
|
|
|
isReadReceiptEnabled={Message_Read_Receipt_Enabled}
|
2019-06-28 17:02:30 +00:00
|
|
|
autoTranslateRoom={canAutoTranslate && room.autoTranslate}
|
|
|
|
autoTranslateLanguage={room.autoTranslateLanguage}
|
2018-09-25 19:28:42 +00:00
|
|
|
/>
|
|
|
|
);
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
if (showUnreadSeparator || dateSeparator) {
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
|
|
|
{message}
|
|
|
|
<Separator
|
|
|
|
ts={dateSeparator}
|
|
|
|
unread={showUnreadSeparator}
|
|
|
|
/>
|
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
2018-09-25 19:28:42 +00:00
|
|
|
}
|
2017-08-07 00:34:35 +00:00
|
|
|
|
2017-08-10 16:16:32 +00:00
|
|
|
renderFooter = () => {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { joined, room } = this.state;
|
2019-07-18 17:44:02 +00:00
|
|
|
const { navigation, user } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
if (!joined && !this.tmid) {
|
2018-09-19 14:18:32 +00:00
|
|
|
return (
|
2018-12-21 10:55:35 +00:00
|
|
|
<View style={styles.joinRoomContainer} key='room-view-join' testID='room-view-join'>
|
2018-09-19 14:18:32 +00:00
|
|
|
<Text style={styles.previewMode}>{I18n.t('You_are_in_preview_mode')}</Text>
|
|
|
|
<RectButton
|
|
|
|
onPress={this.joinRoom}
|
|
|
|
style={styles.joinRoomButton}
|
|
|
|
activeOpacity={0.5}
|
2019-03-29 19:36:07 +00:00
|
|
|
underlayColor={COLOR_WHITE}
|
2018-09-19 14:18:32 +00:00
|
|
|
>
|
2018-12-21 10:55:35 +00:00
|
|
|
<Text style={styles.joinRoomText} testID='room-view-join-button'>{I18n.t('Join')}</Text>
|
2018-09-19 14:18:32 +00:00
|
|
|
</RectButton>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
if (isReadOnly(room, user)) {
|
2018-01-17 16:42:30 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.readOnly}>
|
2019-03-29 19:36:07 +00:00
|
|
|
<Text style={styles.previewMode}>{I18n.t('This_room_is_read_only')}</Text>
|
2018-01-17 16:42:30 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-07-18 17:44:02 +00:00
|
|
|
if (isBlocked(room)) {
|
2018-05-24 20:17:45 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.readOnly}>
|
2019-03-29 19:36:07 +00:00
|
|
|
<Text style={styles.previewMode}>{I18n.t('This_room_is_blocked')}</Text>
|
2018-05-24 20:17:45 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
return (
|
|
|
|
<MessageBox
|
|
|
|
ref={this.messagebox}
|
|
|
|
onSubmit={this.sendMessage}
|
|
|
|
rid={this.rid}
|
|
|
|
tmid={this.tmid}
|
|
|
|
roomType={room.t}
|
|
|
|
isFocused={navigation.isFocused()}
|
|
|
|
/>
|
|
|
|
);
|
2017-09-25 13:15:28 +00:00
|
|
|
};
|
2017-08-09 20:08:50 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
renderActions = () => {
|
2019-04-08 12:35:28 +00:00
|
|
|
const { room } = this.state;
|
2019-04-17 17:01:03 +00:00
|
|
|
const {
|
|
|
|
user, showActions, showErrorActions, navigation
|
|
|
|
} = this.props;
|
|
|
|
if (!navigation.isFocused()) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-18 20:34:59 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<React.Fragment>
|
2019-04-17 17:01:03 +00:00
|
|
|
{room._id && showActions
|
2019-07-23 14:02:57 +00:00
|
|
|
? <MessageActions room={room} tmid={this.tmid} user={user} />
|
2019-04-17 17:01:03 +00:00
|
|
|
: null
|
|
|
|
}
|
|
|
|
{showErrorActions ? <MessageErrorActions /> : null}
|
2019-04-08 12:35:28 +00:00
|
|
|
</React.Fragment>
|
2018-07-18 20:34:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
render() {
|
2019-04-08 12:35:28 +00:00
|
|
|
console.count(`${ this.constructor.name }.render calls`);
|
2019-05-20 20:43:50 +00:00
|
|
|
const {
|
|
|
|
room, photoModalVisible, reactionsModalVisible, selectedAttachment, selectedMessage
|
|
|
|
} = this.state;
|
|
|
|
const { user, baseUrl } = this.props;
|
2019-04-17 17:01:03 +00:00
|
|
|
const { rid, t } = room;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
return (
|
2018-10-23 21:39:48 +00:00
|
|
|
<SafeAreaView style={styles.container} testID='room-view' forceInset={{ bottom: 'never' }}>
|
2019-03-12 16:23:06 +00:00
|
|
|
<StatusBar />
|
2019-04-17 17:01:03 +00:00
|
|
|
<List rid={rid} t={t} tmid={this.tmid} renderRow={this.renderItem} />
|
|
|
|
{this.renderFooter()}
|
|
|
|
{this.renderActions()}
|
2018-01-30 19:48:26 +00:00
|
|
|
<ReactionPicker onEmojiSelected={this.onReactionPress} />
|
2019-07-29 16:33:28 +00:00
|
|
|
<UploadProgress rid={this.rid} user={user} baseUrl={baseUrl} />
|
2019-05-20 20:43:50 +00:00
|
|
|
<FileModal
|
|
|
|
attachment={selectedAttachment}
|
|
|
|
isVisible={photoModalVisible}
|
|
|
|
onClose={this.onCloseFileModal}
|
|
|
|
user={user}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
/>
|
|
|
|
<ReactionsModal
|
|
|
|
message={selectedMessage}
|
|
|
|
isVisible={reactionsModalVisible}
|
|
|
|
onClose={this.onCloseReactionsModal}
|
|
|
|
user={user}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
/>
|
2018-08-01 19:35:06 +00:00
|
|
|
</SafeAreaView>
|
2017-08-04 00:34:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|