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';
|
2019-09-19 13:32:24 +00:00
|
|
|
import { Text, View, InteractionManager } from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2019-10-02 12:18:08 +00:00
|
|
|
import { SafeAreaView } from 'react-navigation';
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
2019-03-27 20:06:57 +00:00
|
|
|
import moment from 'moment';
|
2019-06-28 17:07:17 +00:00
|
|
|
import * as Haptics from 'expo-haptics';
|
2019-09-16 20:26:32 +00:00
|
|
|
import { Q } from '@nozbe/watermelondb';
|
|
|
|
import isEqual from 'lodash/isEqual';
|
2017-08-13 01:35:09 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import Touch from '../../utils/touch';
|
2019-04-08 12:35:28 +00:00
|
|
|
import {
|
2019-05-20 20:43:50 +00:00
|
|
|
replyBroadcast as replyBroadcastAction
|
2019-04-08 12:35:28 +00:00
|
|
|
} from '../../actions/messages';
|
2019-12-04 16:39:53 +00:00
|
|
|
import List from './List';
|
2019-09-16 20:26:32 +00:00
|
|
|
import database from '../../lib/database';
|
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-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-11-25 20:01:17 +00:00
|
|
|
import RoomHeaderView, { RightButtons, RoomHeaderLeft } 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-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2019-04-08 12:35:28 +00:00
|
|
|
import debounce from '../../utils/debounce';
|
2019-05-20 20:43:50 +00:00
|
|
|
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';
|
2019-11-25 20:01:17 +00:00
|
|
|
import { isIOS, isTablet } from '../../utils/deviceInfo';
|
2019-09-18 17:32:12 +00:00
|
|
|
import { showErrorAlert } from '../../utils/info';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { withTheme } from '../../theme';
|
|
|
|
import { themedHeader } from '../../utils/navigation';
|
2019-11-25 20:01:17 +00:00
|
|
|
import {
|
|
|
|
KEY_COMMAND,
|
|
|
|
handleCommandScroll,
|
|
|
|
handleCommandRoomActions,
|
|
|
|
handleCommandSearchMessages,
|
|
|
|
handleCommandReplyLatest
|
|
|
|
} from '../../commands';
|
|
|
|
import ModalNavigation from '../../lib/ModalNavigation';
|
2020-02-03 18:28:18 +00:00
|
|
|
import { Review } from '../../utils/review';
|
2020-02-05 13:34:53 +00:00
|
|
|
import RoomClass from '../../lib/methods/subscriptions/room';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-02-11 14:01:35 +00:00
|
|
|
import { CONTAINER_TYPES } from '../../lib/methods/actions';
|
2020-03-30 20:19:01 +00:00
|
|
|
import Banner from './Banner';
|
2020-03-06 13:13:24 +00:00
|
|
|
import Navigation from '../../lib/Navigation';
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
const stateAttrsUpdate = [
|
|
|
|
'joined',
|
|
|
|
'lastOpen',
|
|
|
|
'reactionsModalVisible',
|
|
|
|
'canAutoTranslate',
|
|
|
|
'showActions',
|
|
|
|
'showErrorActions',
|
|
|
|
'loading',
|
|
|
|
'editing',
|
|
|
|
'replying',
|
2020-02-20 19:44:33 +00:00
|
|
|
'reacting',
|
2020-03-30 20:19:01 +00:00
|
|
|
'member'
|
2019-09-16 20:26:32 +00:00
|
|
|
];
|
2020-03-30 20:19:01 +00:00
|
|
|
const roomAttrsUpdate = ['f', 'ro', 'blocked', 'blocker', 'archived', 'muted', 'jitsiTimeout', 'announcement', 'sysMes', 'topic', 'name', 'fname'];
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class RoomView extends React.Component {
|
2019-11-25 20:01:17 +00:00
|
|
|
static navigationOptions = ({ navigation, screenProps }) => {
|
|
|
|
const rid = navigation.getParam('rid', null);
|
2019-04-08 12:35:28 +00:00
|
|
|
const prid = navigation.getParam('prid');
|
|
|
|
const title = navigation.getParam('name');
|
2020-03-30 20:19:01 +00:00
|
|
|
const subtitle = navigation.getParam('subtitle');
|
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-11-25 20:01:17 +00:00
|
|
|
const baseUrl = navigation.getParam('baseUrl');
|
|
|
|
const userId = navigation.getParam('userId');
|
|
|
|
const token = navigation.getParam('token');
|
|
|
|
const avatar = navigation.getParam('avatar');
|
2019-05-15 19:33:30 +00:00
|
|
|
const toggleFollowThread = navigation.getParam('toggleFollowThread', () => {});
|
2019-11-25 20:01:17 +00:00
|
|
|
const goRoomActionsView = navigation.getParam('goRoomActionsView', () => {});
|
2019-08-22 19:15:30 +00:00
|
|
|
const unreadsCount = navigation.getParam('unreadsCount', null);
|
2020-04-01 12:28:54 +00:00
|
|
|
const roomUserId = navigation.getParam('roomUserId');
|
2019-11-25 20:01:17 +00:00
|
|
|
if (!rid) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return {
|
|
|
|
...themedHeader(screenProps.theme)
|
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
return {
|
2019-12-04 16:39:53 +00:00
|
|
|
...themedHeader(screenProps.theme),
|
2019-04-17 17:01:03 +00:00
|
|
|
headerTitle: (
|
2019-04-30 19:31:51 +00:00
|
|
|
<RoomHeaderView
|
|
|
|
rid={rid}
|
|
|
|
prid={prid}
|
|
|
|
tmid={tmid}
|
|
|
|
title={title}
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle={subtitle}
|
2019-04-30 19:31:51 +00:00
|
|
|
type={t}
|
|
|
|
widthOffset={tmid ? 95 : 130}
|
2020-04-01 12:28:54 +00:00
|
|
|
roomUserId={roomUserId}
|
2019-11-25 20:01:17 +00:00
|
|
|
goRoomActionsView={goRoomActionsView}
|
2019-04-30 19:31:51 +00:00
|
|
|
/>
|
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}
|
|
|
|
/>
|
2019-08-22 19:15:30 +00:00
|
|
|
),
|
|
|
|
headerLeft: (
|
2019-11-25 20:01:17 +00:00
|
|
|
<RoomHeaderLeft
|
|
|
|
tmid={tmid}
|
|
|
|
unreadsCount={unreadsCount}
|
|
|
|
navigation={navigation}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={userId}
|
|
|
|
token={token}
|
|
|
|
title={avatar}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={screenProps.theme}
|
2019-11-25 20:01:17 +00:00
|
|
|
t={t}
|
|
|
|
goRoomActionsView={goRoomActionsView}
|
|
|
|
split={screenProps.split}
|
2019-08-22 19:15:30 +00:00
|
|
|
/>
|
2019-05-15 19:33:30 +00:00
|
|
|
)
|
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
|
|
|
|
}),
|
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,
|
2020-02-20 20:43:56 +00:00
|
|
|
Hide_System_Messages: PropTypes.array,
|
2019-05-20 20:43:50 +00:00
|
|
|
baseUrl: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
customEmojis: PropTypes.object,
|
2019-11-25 20:01:17 +00:00
|
|
|
screenProps: PropTypes.object,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
replyBroadcast: 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-09-16 20:26:32 +00:00
|
|
|
this.tmid = props.navigation.getParam('tmid', null);
|
|
|
|
const room = props.navigation.getParam('room');
|
|
|
|
const selectedMessage = props.navigation.getParam('message');
|
2019-11-25 20:01:17 +00:00
|
|
|
const name = props.navigation.getParam('name');
|
|
|
|
const fname = props.navigation.getParam('fname');
|
2020-04-01 19:39:30 +00:00
|
|
|
const prid = props.navigation.getParam('prid');
|
2017-08-07 18:42:02 +00:00
|
|
|
this.state = {
|
2019-09-16 20:26:32 +00:00
|
|
|
joined: true,
|
2019-11-25 20:01:17 +00:00
|
|
|
room: room || {
|
2020-04-01 19:39:30 +00:00
|
|
|
rid: this.rid, t: this.t, name, fname, prid
|
2019-11-25 20:01:17 +00:00
|
|
|
},
|
2019-09-16 20:26:32 +00:00
|
|
|
roomUpdate: {},
|
2020-03-30 20:19:01 +00:00
|
|
|
member: {},
|
2019-05-20 20:43:50 +00:00
|
|
|
lastOpen: null,
|
|
|
|
reactionsModalVisible: false,
|
2019-09-16 20:26:32 +00:00
|
|
|
selectedMessage: selectedMessage || {},
|
|
|
|
canAutoTranslate: false,
|
|
|
|
loading: true,
|
|
|
|
showActions: false,
|
|
|
|
showErrorActions: false,
|
|
|
|
editing: false,
|
|
|
|
replying: !!selectedMessage,
|
|
|
|
replyWithMention: false,
|
2020-02-20 19:44:33 +00:00
|
|
|
reacting: false,
|
|
|
|
announcement: null
|
2017-08-07 18:42:02 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
if (room && room.observe) {
|
|
|
|
this.observeRoom(room);
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (this.rid) {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.findAndObserveRoom(this.rid);
|
|
|
|
}
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
this.messagebox = React.createRef();
|
2019-11-07 19:53:39 +00:00
|
|
|
this.list = React.createRef();
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = false;
|
2020-02-05 13:34:53 +00:00
|
|
|
this.sub = new RoomClass(this.rid);
|
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-09-16 20:26:32 +00:00
|
|
|
this.mounted = true;
|
2019-11-25 20:01:17 +00:00
|
|
|
this.offset = 0;
|
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-11-25 20:01:17 +00:00
|
|
|
const {
|
|
|
|
navigation, isAuthenticated, user, baseUrl
|
|
|
|
} = this.props;
|
|
|
|
if ((room.id || room.rid) && !this.tmid) {
|
|
|
|
navigation.setParams({
|
|
|
|
name: this.getRoomTitle(room),
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle: room.topic,
|
2019-11-25 20:01:17 +00:00
|
|
|
avatar: room.name,
|
|
|
|
t: room.t,
|
|
|
|
token: user.token,
|
|
|
|
userId: user.id,
|
|
|
|
goRoomActionsView: this.goRoomActionsView,
|
|
|
|
baseUrl
|
|
|
|
});
|
2019-04-08 12:35:28 +00:00
|
|
|
}
|
2019-05-15 19:33:30 +00:00
|
|
|
if (this.tmid) {
|
2019-11-25 20:01:17 +00:00
|
|
|
navigation.setParams({ toggleFollowThread: this.toggleFollowThread, goRoomActionsView: this.goRoomActionsView });
|
2019-05-15 19:33:30 +00:00
|
|
|
}
|
2020-04-03 18:03:53 +00:00
|
|
|
if (this.rid) {
|
|
|
|
this.sub.subscribe();
|
|
|
|
if (isAuthenticated) {
|
|
|
|
this.init();
|
|
|
|
} else {
|
|
|
|
EventEmitter.addEventListener('connected', this.handleConnected);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isIOS && this.rid) {
|
2019-09-16 21:19:14 +00:00
|
|
|
this.updateUnreadCount();
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2020-03-06 13:13:24 +00:00
|
|
|
EventEmitter.addEventListener('ROOM_REMOVED', this.handleRoomRemoved);
|
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) {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { state } = this;
|
2020-03-30 20:19:01 +00:00
|
|
|
const { roomUpdate, member } = state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { appState, theme } = this.props;
|
|
|
|
if (theme !== nextProps.theme) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
if (appState !== nextProps.appState) {
|
2018-12-05 20:52:08 +00:00
|
|
|
return true;
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2020-03-30 20:19:01 +00:00
|
|
|
if (member.statusText !== nextState.member.statusText) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
const stateUpdated = stateAttrsUpdate.some(key => nextState[key] !== state[key]);
|
|
|
|
if (stateUpdated) {
|
2019-02-07 15:48:10 +00:00
|
|
|
return true;
|
2018-09-26 13:56:36 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
return roomAttrsUpdate.some(key => !isEqual(nextState.roomUpdate[key], roomUpdate[key]));
|
2017-09-21 17:08:00 +00:00
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2020-03-30 20:19:01 +00:00
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
const { roomUpdate, room } = this.state;
|
|
|
|
const { appState, navigation } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (appState === 'foreground' && appState !== prevProps.appState && this.rid) {
|
2019-04-08 12:35:28 +00:00
|
|
|
this.onForegroundInteraction = InteractionManager.runAfterInteractions(() => {
|
2019-11-21 19:10:55 +00:00
|
|
|
// Fire List.init() just to keep observables working
|
|
|
|
if (this.list && this.list.current) {
|
|
|
|
this.list.current.init();
|
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
});
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2020-03-30 20:19:01 +00:00
|
|
|
// If it's not direct message
|
|
|
|
if (this.t !== 'd') {
|
|
|
|
if (roomUpdate.topic !== prevState.roomUpdate.topic) {
|
|
|
|
navigation.setParams({ subtitle: roomUpdate.topic });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (((roomUpdate.fname !== prevState.roomUpdate.fname) || (roomUpdate.name !== prevState.roomUpdate.name)) && !this.tmid) {
|
|
|
|
navigation.setParams({ name: this.getRoomTitle(room) });
|
|
|
|
}
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
async componentWillUnmount() {
|
|
|
|
const { editing, room } = this.state;
|
|
|
|
const db = database.active;
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = false;
|
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) {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const threadsCollection = db.collections.get('threads');
|
|
|
|
obj = await threadsCollection.find(this.tmid);
|
|
|
|
} catch (e) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2019-04-24 18:36:29 +00:00
|
|
|
} else {
|
2019-09-16 20:26:32 +00:00
|
|
|
obj = room;
|
2019-04-24 18:36:29 +00:00
|
|
|
}
|
|
|
|
if (obj) {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
await db.action(async() => {
|
|
|
|
await obj.update((r) => {
|
|
|
|
r.draftMessage = text;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2019-04-08 12:35:28 +00:00
|
|
|
}
|
2020-02-05 13:34:53 +00:00
|
|
|
this.unsubscribe();
|
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();
|
|
|
|
}
|
2019-05-03 14:54:57 +00:00
|
|
|
if (this.willBlurListener && this.willBlurListener.remove) {
|
|
|
|
this.willBlurListener.remove();
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
if (this.subSubscription && this.subSubscription.unsubscribe) {
|
|
|
|
this.subSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
if (this.queryUnreads && this.queryUnreads.unsubscribe) {
|
|
|
|
this.queryUnreads.unsubscribe();
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
2019-11-25 20:01:17 +00:00
|
|
|
if (isTablet) {
|
|
|
|
EventEmitter.removeListener(KEY_COMMAND, this.handleCommands);
|
|
|
|
}
|
2020-03-06 13:13:24 +00:00
|
|
|
EventEmitter.removeListener('ROOM_REMOVED', this.handleRoomRemoved);
|
2019-04-08 12:35:28 +00:00
|
|
|
console.countReset(`${ this.constructor.name }.render calls`);
|
2017-08-04 00:34:37 +00:00
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
goRoomActionsView = () => {
|
2020-03-30 20:19:01 +00:00
|
|
|
const { room, member } = this.state;
|
2019-11-25 20:01:17 +00:00
|
|
|
const { navigation } = this.props;
|
2020-03-30 20:19:01 +00:00
|
|
|
navigation.navigate('RoomActionsView', {
|
|
|
|
rid: this.rid, t: this.t, room, member
|
|
|
|
});
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
|
2019-12-13 16:23:20 +00:00
|
|
|
init = async() => {
|
2019-04-17 17:01:03 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ loading: true });
|
2019-12-13 16:23:20 +00:00
|
|
|
const { room, joined } = this.state;
|
|
|
|
if (this.tmid) {
|
|
|
|
await this.getThreadMessages();
|
|
|
|
} else {
|
|
|
|
const newLastOpen = new Date();
|
|
|
|
await this.getMessages(room);
|
|
|
|
|
|
|
|
// if room is joined
|
|
|
|
if (joined) {
|
|
|
|
if (room.alert || room.unread || room.userMentions) {
|
|
|
|
this.setLastOpen(room.ls);
|
|
|
|
} else {
|
|
|
|
this.setLastOpen(null);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2020-03-30 20:10:19 +00:00
|
|
|
RocketChat.readMessages(room.rid, newLastOpen, true).catch(e => console.log(e));
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2019-12-13 16:23:20 +00:00
|
|
|
}
|
2019-06-28 17:02:30 +00:00
|
|
|
|
2019-12-13 16:23:20 +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 = await RocketChat.canAutoTranslate();
|
2020-03-30 20:19:01 +00:00
|
|
|
|
|
|
|
const member = await this.getRoomMember();
|
|
|
|
|
|
|
|
this.setState({ canAutoTranslate, member, loading: false });
|
2019-04-17 17:01:03 +00:00
|
|
|
} catch (e) {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ loading: false });
|
2019-12-13 16:23:20 +00:00
|
|
|
this.retryInit = this.retryInit + 1 || 1;
|
|
|
|
if (this.retryInit <= 1) {
|
|
|
|
this.retryInitTimeout = setTimeout(() => {
|
|
|
|
this.init();
|
|
|
|
}, 300);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 20:19:01 +00:00
|
|
|
getRoomMember = async() => {
|
|
|
|
const { room } = this.state;
|
2020-04-01 12:28:54 +00:00
|
|
|
const { t } = room;
|
2020-03-30 20:19:01 +00:00
|
|
|
|
2020-04-01 12:28:54 +00:00
|
|
|
if (t === 'd' && !RocketChat.isGroupChat(room)) {
|
2020-04-09 05:20:57 +00:00
|
|
|
const { navigation } = this.props;
|
2020-03-30 20:19:01 +00:00
|
|
|
|
|
|
|
try {
|
2020-04-09 05:20:57 +00:00
|
|
|
const roomUserId = RocketChat.getUidDirectMessage(room);
|
2020-04-01 12:28:54 +00:00
|
|
|
|
|
|
|
navigation.setParams({ roomUserId });
|
|
|
|
|
2020-03-30 20:19:01 +00:00
|
|
|
const result = await RocketChat.getUserInfo(roomUserId);
|
|
|
|
if (result.success) {
|
|
|
|
return result.user;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
findAndObserveRoom = async(rid) => {
|
|
|
|
try {
|
|
|
|
const db = database.active;
|
|
|
|
const { navigation } = this.props;
|
|
|
|
const subCollection = await db.collections.get('subscriptions');
|
|
|
|
const room = await subCollection.find(rid);
|
|
|
|
this.setState({ room });
|
2020-02-28 17:39:17 +00:00
|
|
|
if (!this.tmid) {
|
|
|
|
navigation.setParams({
|
|
|
|
name: this.getRoomTitle(room),
|
2020-03-30 20:19:01 +00:00
|
|
|
subtitle: room.topic,
|
2020-02-28 17:39:17 +00:00
|
|
|
avatar: room.name,
|
|
|
|
t: room.t
|
|
|
|
});
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
this.observeRoom(room);
|
|
|
|
} catch (error) {
|
|
|
|
if (this.t !== 'd') {
|
|
|
|
console.log('Room not found');
|
|
|
|
this.internalSetState({ joined: false });
|
2020-02-21 15:59:13 +00:00
|
|
|
}
|
|
|
|
if (this.rid) {
|
|
|
|
// We navigate to RoomView before the Room is inserted to the local db
|
2019-09-16 20:26:32 +00:00
|
|
|
// So we retry just to make sure we have the right content
|
|
|
|
this.retryFindCount = this.retryFindCount + 1 || 1;
|
|
|
|
if (this.retryFindCount <= 3) {
|
|
|
|
this.retryFindTimeout = setTimeout(() => {
|
|
|
|
this.findAndObserveRoom(rid);
|
|
|
|
this.init();
|
|
|
|
}, 300);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:23:20 +00:00
|
|
|
unsubscribe = async() => {
|
2020-02-05 13:34:53 +00:00
|
|
|
if (this.sub && this.sub.unsubscribe) {
|
|
|
|
await this.sub.unsubscribe();
|
2019-09-27 20:29:25 +00:00
|
|
|
}
|
2020-02-05 13:34:53 +00:00
|
|
|
delete this.sub;
|
2019-09-27 20:29:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
observeRoom = (room) => {
|
|
|
|
const observable = room.observe();
|
|
|
|
this.subSubscription = observable
|
|
|
|
.subscribe((changes) => {
|
|
|
|
const roomUpdate = roomAttrsUpdate.reduce((ret, attr) => {
|
|
|
|
ret[attr] = changes[attr];
|
|
|
|
return ret;
|
|
|
|
}, {});
|
|
|
|
if (this.mounted) {
|
|
|
|
this.internalSetState({ room: changes, roomUpdate });
|
|
|
|
} else {
|
|
|
|
this.state.room = changes;
|
|
|
|
this.state.roomUpdate = roomUpdate;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
errorActionsShow = (message) => {
|
|
|
|
this.setState({ selectedMessage: message, showErrorActions: true });
|
|
|
|
}
|
|
|
|
|
|
|
|
onActionsHide = () => {
|
|
|
|
const { editing, replying, reacting } = this.state;
|
|
|
|
if (editing || replying || reacting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({ selectedMessage: {}, showActions: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onErrorActionsHide = () => {
|
|
|
|
this.setState({ selectedMessage: {}, showErrorActions: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditInit = (message) => {
|
|
|
|
this.setState({ selectedMessage: message, editing: true, showActions: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditCancel = () => {
|
|
|
|
this.setState({ selectedMessage: {}, editing: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onEditRequest = async(message) => {
|
|
|
|
this.setState({ selectedMessage: {}, editing: false });
|
|
|
|
try {
|
|
|
|
await RocketChat.editMessage(message);
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onReplyInit = (message, mention) => {
|
|
|
|
this.setState({
|
|
|
|
selectedMessage: message, replying: true, showActions: false, replyWithMention: mention
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onReplyCancel = () => {
|
|
|
|
this.setState({ selectedMessage: {}, replying: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onReactionInit = (message) => {
|
|
|
|
this.setState({ selectedMessage: message, reacting: true, showActions: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
onReactionClose = () => {
|
|
|
|
this.setState({ selectedMessage: {}, reacting: false });
|
|
|
|
}
|
|
|
|
|
2018-02-19 21:19:39 +00:00
|
|
|
onMessageLongPress = (message) => {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ selectedMessage: message, showActions: true });
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 21:13:11 +00:00
|
|
|
showAttachment = (attachment) => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('AttachmentView', { attachment });
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
onReactionPress = async(shortname, messageId) => {
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
await RocketChat.setReaction(shortname, messageId);
|
|
|
|
this.onReactionClose();
|
2020-02-03 18:28:18 +00:00
|
|
|
Review.pushPositiveEvent();
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(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-08-22 19:15:30 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2019-09-16 20:26:32 +00:00
|
|
|
updateUnreadCount = async() => {
|
|
|
|
const db = database.active;
|
|
|
|
const observable = await db.collections
|
|
|
|
.get('subscriptions')
|
|
|
|
.query(
|
|
|
|
Q.where('archived', false),
|
|
|
|
Q.where('open', true),
|
|
|
|
Q.where('rid', Q.notEq(this.rid))
|
|
|
|
)
|
|
|
|
.observeWithColumns(['unread']);
|
|
|
|
|
|
|
|
this.queryUnreads = observable.subscribe((data) => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
const unreadsCount = data.filter(s => s.unread > 0).reduce((a, b) => a + (b.unread || 0), 0);
|
|
|
|
if (unreadsCount !== navigation.getParam('unreadsCount')) {
|
|
|
|
navigation.setParams({
|
|
|
|
unreadsCount
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-08-22 19:15:30 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
onThreadPress = debounce(async(item) => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
if (item.tmid) {
|
2019-09-16 20:26:32 +00:00
|
|
|
if (!item.tmsg) {
|
|
|
|
await this.fetchThreadName(item.tmid, item.id);
|
|
|
|
}
|
2019-05-20 20:43:50 +00:00
|
|
|
navigation.push('RoomView', {
|
2019-09-16 20:26:32 +00:00
|
|
|
rid: item.subscription.id, tmid: item.tmid, name: item.tmsg, t: 'thread'
|
2019-05-20 20:43:50 +00:00
|
|
|
});
|
|
|
|
} else if (item.tlm) {
|
|
|
|
navigation.push('RoomView', {
|
2019-09-16 20:26:32 +00:00
|
|
|
rid: item.subscription.id, tmid: item.id, name: item.msg, t: 'thread'
|
2019-05-20 20:43:50 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 1000, true)
|
|
|
|
|
|
|
|
replyBroadcast = (message) => {
|
|
|
|
const { replyBroadcast } = this.props;
|
|
|
|
replyBroadcast(message);
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
handleConnected = () => {
|
|
|
|
this.init();
|
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
|
|
|
}
|
|
|
|
|
2020-03-06 13:13:24 +00:00
|
|
|
handleRoomRemoved = ({ rid }) => {
|
2020-03-04 11:49:54 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
if (rid === this.rid) {
|
2020-03-06 13:13:24 +00:00
|
|
|
Navigation.navigate('RoomsListView');
|
2020-03-04 11:49:54 +00:00
|
|
|
showErrorAlert(I18n.t('You_were_removed_from_channel', { channel: this.getRoomTitle(room) }), I18n.t('Oops'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
internalSetState = (...args) => {
|
2019-05-03 14:54:57 +00:00
|
|
|
if (!this.mounted) {
|
|
|
|
return;
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
this.setState(...args);
|
|
|
|
}
|
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
sendMessage = (message, tmid) => {
|
2019-07-29 16:33:28 +00:00
|
|
|
const { user } = this.props;
|
|
|
|
RocketChat.sendMessage(this.rid, message, this.tmid || tmid, user).then(() => {
|
2019-11-07 19:53:39 +00:00
|
|
|
if (this.list && this.list.current) {
|
|
|
|
this.list.current.update();
|
|
|
|
}
|
2019-03-27 20:06:57 +00:00
|
|
|
this.setLastOpen(null);
|
2020-02-03 18:28:18 +00:00
|
|
|
Review.pushPositiveEvent();
|
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-12-13 16:23:20 +00:00
|
|
|
getMessages = () => {
|
2019-04-17 17:01:03 +00:00
|
|
|
const { room } = this.state;
|
2019-12-13 16:23:20 +00:00
|
|
|
if (room.lastOpen) {
|
|
|
|
return RocketChat.loadMissedMessages(room);
|
|
|
|
} else {
|
|
|
|
return RocketChat.loadMessagesForRoom(room);
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-13 16:23:20 +00:00
|
|
|
getThreadMessages = () => RocketChat.loadThreadMessages({ tmid: this.tmid, rid: this.rid })
|
2019-04-24 18:36:29 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
getCustomEmoji = (name) => {
|
|
|
|
const { customEmojis } = this.props;
|
|
|
|
const emoji = customEmojis[name];
|
|
|
|
if (emoji) {
|
|
|
|
return emoji;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
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-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +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
|
2019-09-16 20:26:32 +00:00
|
|
|
fetchThreadName = async(tmid, messageId) => {
|
2019-04-17 17:01:03 +00:00
|
|
|
try {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
|
|
|
const threadCollection = db.collections.get('threads');
|
|
|
|
const messageCollection = db.collections.get('messages');
|
|
|
|
const messageRecord = await messageCollection.find(messageId);
|
|
|
|
let threadRecord;
|
|
|
|
try {
|
|
|
|
threadRecord = await threadCollection.find(tmid);
|
|
|
|
} catch (error) {
|
|
|
|
console.log('Thread not found. We have to search for it.');
|
|
|
|
}
|
|
|
|
if (threadRecord) {
|
|
|
|
await db.action(async() => {
|
|
|
|
await messageRecord.update((m) => {
|
|
|
|
m.tmsg = threadRecord.msg || (threadRecord.attachments && threadRecord.attachments.length && threadRecord.attachments[0].title);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const thread = await RocketChat.getSingleMessage(tmid);
|
|
|
|
await db.action(async() => {
|
|
|
|
await db.batch(
|
|
|
|
threadCollection.prepareCreate((t) => {
|
|
|
|
t._raw = sanitizedRaw({ id: thread._id }, threadCollection.schema);
|
2020-04-06 19:07:23 +00:00
|
|
|
t.subscription.id = this.rid;
|
2019-09-16 20:26:32 +00:00
|
|
|
Object.assign(t, thread);
|
|
|
|
}),
|
|
|
|
messageRecord.prepareUpdate((m) => {
|
|
|
|
m.tmsg = thread.msg || (thread.attachments && thread.attachments.length && thread.attachments[0].title);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2019-08-23 13:18:47 +00:00
|
|
|
} catch (e) {
|
2020-04-06 19:07:23 +00:00
|
|
|
// log(e);
|
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);
|
2020-01-28 13:25:28 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: isFollowingThread ? I18n.t('Unfollowed_thread') : I18n.t('Following_thread') });
|
2019-05-15 19:33:30 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-05-15 19:33:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-22 18:08:07 +00:00
|
|
|
navToRoomInfo = (navParam) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { navigation, user, screenProps } = this.props;
|
2019-08-22 18:08:07 +00:00
|
|
|
if (navParam.rid === user.id) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-25 20:01:17 +00:00
|
|
|
if (screenProps && screenProps.split) {
|
|
|
|
navigation.navigate('RoomActionsView', { rid: this.rid, t: this.t, room });
|
|
|
|
ModalNavigation.navigate('RoomInfoView', navParam);
|
|
|
|
} else {
|
|
|
|
navigation.navigate('RoomInfoView', navParam);
|
|
|
|
}
|
2019-08-22 18:08:07 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 17:32:12 +00:00
|
|
|
callJitsi = () => {
|
|
|
|
const { room } = this.state;
|
|
|
|
const { jitsiTimeout } = room;
|
|
|
|
if (jitsiTimeout < Date.now()) {
|
|
|
|
showErrorAlert(I18n.t('Call_already_ended'));
|
|
|
|
} else {
|
2019-09-25 22:13:39 +00:00
|
|
|
RocketChat.callJitsi(this.rid);
|
2019-09-18 17:32:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommands = ({ event }) => {
|
|
|
|
if (this.rid) {
|
|
|
|
const { room } = this.state;
|
|
|
|
const { navigation } = this.props;
|
|
|
|
const { input } = event;
|
|
|
|
if (handleCommandScroll(event)) {
|
|
|
|
const offset = input === 'UIKeyInputUpArrow' ? 100 : -100;
|
|
|
|
this.offset += offset;
|
|
|
|
this.flatList.scrollToOffset({ offset: this.offset });
|
|
|
|
} else if (handleCommandRoomActions(event)) {
|
|
|
|
navigation.navigate('RoomActionsView', { rid: this.rid, t: this.t, room });
|
|
|
|
} else if (handleCommandSearchMessages(event)) {
|
|
|
|
navigation.navigate('RoomActionsView', { rid: this.rid, t: this.t, room });
|
|
|
|
ModalNavigation.navigate('SearchMessagesView', { rid: this.rid });
|
|
|
|
} else if (handleCommandReplyLatest(event)) {
|
|
|
|
if (this.list && this.list.current) {
|
|
|
|
const message = this.list.current.getLastMessage();
|
|
|
|
this.onReplyInit(message, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
get isReadOnly() {
|
|
|
|
const { room } = this.state;
|
|
|
|
const { user } = this.props;
|
|
|
|
return isReadOnly(room, user);
|
|
|
|
}
|
|
|
|
|
2020-02-11 14:01:35 +00:00
|
|
|
blockAction = ({
|
|
|
|
actionId, appId, value, blockId, rid, mid
|
|
|
|
}) => RocketChat.triggerBlockAction({
|
|
|
|
blockId,
|
|
|
|
actionId,
|
|
|
|
value,
|
|
|
|
mid,
|
|
|
|
rid,
|
|
|
|
appId,
|
|
|
|
container: {
|
|
|
|
type: CONTAINER_TYPES.MESSAGE,
|
|
|
|
id: mid
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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 {
|
2020-02-27 18:34:20 +00:00
|
|
|
user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, Message_Read_Receipt_Enabled, theme
|
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
|
2020-02-28 19:31:19 +00:00
|
|
|
&& moment(item.ts).isSameOrAfter(lastOpen)
|
2019-03-27 20:06:57 +00:00
|
|
|
&& 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
|
|
|
|
item={item}
|
|
|
|
user={user}
|
2020-02-11 14:01:35 +00:00
|
|
|
rid={room.rid}
|
2018-09-25 19:28:42 +00:00
|
|
|
archived={room.archived}
|
|
|
|
broadcast={room.broadcast}
|
2019-04-17 17:01:03 +00:00
|
|
|
status={item.status}
|
2019-09-16 20:26:32 +00:00
|
|
|
isThreadRoom={!!this.tmid}
|
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}
|
2019-12-18 21:13:11 +00:00
|
|
|
showAttachment={this.showAttachment}
|
2019-09-16 20:26:32 +00:00
|
|
|
reactionInit={this.onReactionInit}
|
2019-05-20 20:43:50 +00:00
|
|
|
replyBroadcast={this.replyBroadcast}
|
|
|
|
errorActionsShow={this.errorActionsShow}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
Message_GroupingPeriod={Message_GroupingPeriod}
|
|
|
|
timeFormat={Message_TimeFormat}
|
|
|
|
useRealName={useRealName}
|
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}
|
2019-08-22 18:08:07 +00:00
|
|
|
navToRoomInfo={this.navToRoomInfo}
|
2019-09-16 20:26:32 +00:00
|
|
|
getCustomEmoji={this.getCustomEmoji}
|
2019-09-18 17:32:12 +00:00
|
|
|
callJitsi={this.callJitsi}
|
2020-02-11 14:01:35 +00:00
|
|
|
blockAction={this.blockAction}
|
2018-09-25 19:28:42 +00:00
|
|
|
/>
|
|
|
|
);
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
if (showUnreadSeparator || dateSeparator) {
|
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2019-04-17 17:01:03 +00:00
|
|
|
{message}
|
|
|
|
<Separator
|
|
|
|
ts={dateSeparator}
|
|
|
|
unread={showUnreadSeparator}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-04-17 17:01:03 +00:00
|
|
|
/>
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-04-17 17:01:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-16 20:26:32 +00:00
|
|
|
const {
|
|
|
|
joined, room, selectedMessage, editing, replying, replyWithMention
|
|
|
|
} = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { navigation, theme } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (!this.rid) {
|
|
|
|
return null;
|
|
|
|
}
|
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'>
|
2020-03-03 20:27:38 +00:00
|
|
|
<Text accessibilityLabel={I18n.t('You_are_in_preview_mode')} style={[styles.previewMode, { color: themes[theme].titleText }]}>{I18n.t('You_are_in_preview_mode')}</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Touch
|
2018-09-19 14:18:32 +00:00
|
|
|
onPress={this.joinRoom}
|
2019-12-04 16:39:53 +00:00
|
|
|
style={[styles.joinRoomButton, { backgroundColor: themes[theme].actionTintColor }]}
|
|
|
|
theme={theme}
|
2018-09-19 14:18:32 +00:00
|
|
|
>
|
2019-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.joinRoomText, { color: themes[theme].buttonText }]} testID='room-view-join-button'>{I18n.t('Join')}</Text>
|
|
|
|
</Touch>
|
2018-09-19 14:18:32 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2020-01-28 13:39:42 +00:00
|
|
|
if (this.isReadOnly || room.archived) {
|
2018-01-17 16:42:30 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.readOnly}>
|
2020-03-03 20:27:38 +00:00
|
|
|
<Text style={[styles.previewMode, { color: themes[theme].titleText }]} accessibilityLabel={I18n.t('This_room_is_read_only')}>{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-12-04 16:39:53 +00:00
|
|
|
<Text style={[styles.previewMode, { color: themes[theme].titleText }]}>{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}
|
2019-10-28 20:51:46 +00:00
|
|
|
isFocused={navigation.isFocused}
|
2020-01-07 13:58:47 +00:00
|
|
|
theme={theme}
|
2019-09-16 20:26:32 +00:00
|
|
|
message={selectedMessage}
|
|
|
|
editing={editing}
|
|
|
|
editRequest={this.onEditRequest}
|
|
|
|
editCancel={this.onEditCancel}
|
|
|
|
replying={replying}
|
|
|
|
replyWithMention={replyWithMention}
|
|
|
|
replyCancel={this.onReplyCancel}
|
|
|
|
getCustomEmoji={this.getCustomEmoji}
|
2020-02-28 17:52:50 +00:00
|
|
|
navigation={navigation}
|
2019-04-24 18:36:29 +00:00
|
|
|
/>
|
|
|
|
);
|
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 = () => {
|
|
|
|
const {
|
2019-09-16 20:26:32 +00:00
|
|
|
room, selectedMessage, showActions, showErrorActions, joined
|
|
|
|
} = this.state;
|
|
|
|
const {
|
|
|
|
user, navigation
|
2019-04-17 17:01:03 +00:00
|
|
|
} = this.props;
|
|
|
|
if (!navigation.isFocused()) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-07-18 20:34:59 +00:00
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
|
|
|
{joined && showActions
|
|
|
|
? (
|
|
|
|
<MessageActions
|
|
|
|
tmid={this.tmid}
|
|
|
|
room={room}
|
|
|
|
user={user}
|
|
|
|
message={selectedMessage}
|
|
|
|
actionsHide={this.onActionsHide}
|
|
|
|
editInit={this.onEditInit}
|
|
|
|
replyInit={this.onReplyInit}
|
|
|
|
reactionInit={this.onReactionInit}
|
|
|
|
isReadOnly={this.isReadOnly}
|
|
|
|
/>
|
|
|
|
)
|
2019-04-17 17:01:03 +00:00
|
|
|
: null
|
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
{showErrorActions ? (
|
|
|
|
<MessageErrorActions
|
2019-10-08 12:36:15 +00:00
|
|
|
tmid={this.tmid}
|
2019-09-16 20:26:32 +00:00
|
|
|
message={selectedMessage}
|
|
|
|
actionsHide={this.onErrorActionsHide}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
</>
|
2018-07-18 20:34:59 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
setListRef = ref => this.flatList = ref;
|
|
|
|
|
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 {
|
2019-12-18 21:13:11 +00:00
|
|
|
room, reactionsModalVisible, selectedMessage, loading, reacting
|
2019-05-20 20:43:50 +00:00
|
|
|
} = this.state;
|
2020-02-17 19:06:18 +00:00
|
|
|
const {
|
2020-02-20 20:43:56 +00:00
|
|
|
user, baseUrl, theme, navigation, Hide_System_Messages
|
2020-02-17 19:06:18 +00:00
|
|
|
} = this.props;
|
2020-03-06 14:19:03 +00:00
|
|
|
const { rid, t, sysMes } = room;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
return (
|
2019-12-04 16:39:53 +00:00
|
|
|
<SafeAreaView
|
|
|
|
style={[
|
|
|
|
styles.container,
|
|
|
|
{ backgroundColor: themes[theme].backgroundColor }
|
|
|
|
]}
|
|
|
|
testID='room-view'
|
|
|
|
forceInset={{ vertical: 'never' }}
|
|
|
|
>
|
|
|
|
<StatusBar theme={theme} />
|
2020-03-30 20:19:01 +00:00
|
|
|
<Banner
|
|
|
|
rid={rid}
|
|
|
|
title={I18n.t('Announcement')}
|
|
|
|
text={room.announcement}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2019-09-16 20:26:32 +00:00
|
|
|
<List
|
2019-11-07 19:53:39 +00:00
|
|
|
ref={this.list}
|
2019-11-25 20:01:17 +00:00
|
|
|
listRef={this.setListRef}
|
2019-09-16 20:26:32 +00:00
|
|
|
rid={rid}
|
|
|
|
t={t}
|
|
|
|
tmid={this.tmid}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2019-09-16 20:26:32 +00:00
|
|
|
room={room}
|
|
|
|
renderRow={this.renderItem}
|
|
|
|
loading={loading}
|
2020-02-17 19:06:18 +00:00
|
|
|
navigation={navigation}
|
2020-03-06 14:19:03 +00:00
|
|
|
hideSystemMessages={sysMes || Hide_System_Messages}
|
2019-09-16 20:26:32 +00:00
|
|
|
/>
|
2019-04-17 17:01:03 +00:00
|
|
|
{this.renderFooter()}
|
|
|
|
{this.renderActions()}
|
2019-09-16 20:26:32 +00:00
|
|
|
<ReactionPicker
|
|
|
|
show={reacting}
|
|
|
|
message={selectedMessage}
|
|
|
|
onEmojiSelected={this.onReactionPress}
|
|
|
|
reactionClose={this.onReactionClose}
|
|
|
|
/>
|
2019-07-29 16:33:28 +00:00
|
|
|
<UploadProgress rid={this.rid} user={user} baseUrl={baseUrl} />
|
2019-05-20 20:43:50 +00:00
|
|
|
<ReactionsModal
|
|
|
|
message={selectedMessage}
|
|
|
|
isVisible={reactionsModalVisible}
|
|
|
|
user={user}
|
|
|
|
baseUrl={baseUrl}
|
2019-09-16 20:26:32 +00:00
|
|
|
onClose={this.onCloseReactionsModal}
|
|
|
|
getCustomEmoji={this.getCustomEmoji}
|
2019-05-20 20:43:50 +00:00
|
|
|
/>
|
2018-08-01 19:35:06 +00:00
|
|
|
</SafeAreaView>
|
2017-08-04 00:34:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
user: getUserSelector(state),
|
2019-08-07 13:51:34 +00:00
|
|
|
appState: state.app.ready && state.app.foreground ? 'foreground' : 'background',
|
|
|
|
useRealName: state.settings.UI_Use_Real_Name,
|
|
|
|
isAuthenticated: state.login.isAuthenticated,
|
|
|
|
Message_GroupingPeriod: state.settings.Message_GroupingPeriod,
|
|
|
|
Message_TimeFormat: state.settings.Message_TimeFormat,
|
2019-09-16 20:26:32 +00:00
|
|
|
customEmojis: state.customEmojis,
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl: state.server.server,
|
2020-02-20 20:43:56 +00:00
|
|
|
Message_Read_Receipt_Enabled: state.settings.Message_Read_Receipt_Enabled,
|
|
|
|
Hide_System_Messages: state.settings.Hide_System_Messages
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
replyBroadcast: message => dispatch(replyBroadcastAction(message))
|
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomView));
|