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';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { InteractionManager, Text, View } from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-05-26 17:24:54 +00:00
|
|
|
import parse from 'url-parse';
|
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';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { withSafeAreaInsets } from 'react-native-safe-area-context';
|
2017-08-13 01:35:09 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import Touch from '../../utils/touch';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { replyBroadcast as replyBroadcastAction } from '../../actions/messages';
|
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';
|
2021-09-13 20:41:05 +00:00
|
|
|
import log, { events, logEvent } 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';
|
2021-04-07 18:31:25 +00:00
|
|
|
import RoomHeader from '../../containers/RoomHeader';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
2021-05-26 17:24:54 +00:00
|
|
|
import { MESSAGE_TYPE_ANY_LOAD, MESSAGE_TYPE_LOAD_MORE } from '../../constants/messageTypeLoad';
|
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';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { getBadgeColor, isBlocked, isTeamRoom, makeThreadName } from '../../utils/room';
|
2020-04-13 13:56:30 +00:00
|
|
|
import { isReadOnly } from '../../utils/isReadOnly';
|
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';
|
2019-11-25 20:01:17 +00:00
|
|
|
import {
|
|
|
|
KEY_COMMAND,
|
2021-09-13 20:41:05 +00:00
|
|
|
handleCommandReplyLatest,
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommandRoomActions,
|
2021-09-13 20:41:05 +00:00
|
|
|
handleCommandScroll,
|
|
|
|
handleCommandSearchMessages
|
2019-11-25 20:01:17 +00:00
|
|
|
} from '../../commands';
|
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-06 13:13:24 +00:00
|
|
|
import Navigation from '../../lib/Navigation';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2020-06-17 17:35:58 +00:00
|
|
|
import { withDimensions } from '../../dimensions';
|
2020-07-06 20:56:28 +00:00
|
|
|
import { getHeaderTitlePosition } from '../../containers/Header';
|
2020-09-11 14:31:38 +00:00
|
|
|
import { E2E_MESSAGE_TYPE, E2E_STATUS } from '../../lib/encryption/constants';
|
2020-08-28 19:41:08 +00:00
|
|
|
import { takeInquiry } from '../../ee/omnichannel/lib';
|
2021-05-26 17:24:54 +00:00
|
|
|
import Loading from '../../containers/Loading';
|
|
|
|
import { goRoom } from '../../utils/goRoom';
|
|
|
|
import getThreadName from '../../lib/methods/getThreadName';
|
|
|
|
import getRoomInfo from '../../lib/methods/getRoomInfo';
|
2021-09-13 20:41:05 +00:00
|
|
|
import RoomServices from './services';
|
|
|
|
import LoadMore from './LoadMore';
|
|
|
|
import Banner from './Banner';
|
|
|
|
import Separator from './Separator';
|
|
|
|
import RightButtons from './RightButtons';
|
|
|
|
import LeftButtons from './LeftButtons';
|
|
|
|
import styles from './styles';
|
|
|
|
import JoinCode from './JoinCode';
|
|
|
|
import UploadProgress from './UploadProgress';
|
|
|
|
import ReactionPicker from './ReactionPicker';
|
|
|
|
import List from './List';
|
2020-08-28 19:41:08 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
const stateAttrsUpdate = [
|
|
|
|
'joined',
|
|
|
|
'lastOpen',
|
|
|
|
'reactionsModalVisible',
|
|
|
|
'canAutoTranslate',
|
2020-06-15 19:35:45 +00:00
|
|
|
'selectedMessage',
|
2019-09-16 20:26:32 +00:00
|
|
|
'loading',
|
|
|
|
'editing',
|
|
|
|
'replying',
|
2020-02-20 19:44:33 +00:00
|
|
|
'reacting',
|
2020-04-13 12:51:16 +00:00
|
|
|
'readOnly',
|
2021-05-26 17:24:54 +00:00
|
|
|
'member',
|
|
|
|
'showingBlockingLoader'
|
2019-09-16 20:26:32 +00:00
|
|
|
];
|
2021-09-13 20:41:05 +00:00
|
|
|
const roomAttrsUpdate = [
|
|
|
|
'f',
|
|
|
|
'ro',
|
|
|
|
'blocked',
|
|
|
|
'blocker',
|
|
|
|
'archived',
|
|
|
|
'tunread',
|
|
|
|
'muted',
|
|
|
|
'ignored',
|
|
|
|
'jitsiTimeout',
|
|
|
|
'announcement',
|
|
|
|
'sysMes',
|
|
|
|
'topic',
|
|
|
|
'name',
|
|
|
|
'fname',
|
|
|
|
'roles',
|
|
|
|
'bannerClosed',
|
|
|
|
'visitor',
|
|
|
|
'joinCodeRequired',
|
|
|
|
'teamMain',
|
|
|
|
'teamId'
|
|
|
|
];
|
2018-09-26 13:56:36 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class RoomView extends React.Component {
|
2017-08-05 18:16:32 +00:00
|
|
|
static propTypes = {
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2020-06-15 14:00:46 +00:00
|
|
|
route: PropTypes.object,
|
2018-07-10 13:40:32 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
username: PropTypes.string.isRequired,
|
2020-10-30 17:35:07 +00:00
|
|
|
token: PropTypes.string.isRequired,
|
|
|
|
showMessageInMainThread: PropTypes.bool
|
2018-07-10 13:40:32 +00:00
|
|
|
}),
|
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,
|
2021-10-20 16:35:28 +00:00
|
|
|
serverVersion: PropTypes.string,
|
2019-09-16 20:26:32 +00:00
|
|
|
customEmojis: PropTypes.object,
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: PropTypes.bool,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string,
|
2020-06-17 17:35:58 +00:00
|
|
|
replyBroadcast: PropTypes.func,
|
|
|
|
width: PropTypes.number,
|
2020-07-06 20:56:28 +00:00
|
|
|
height: PropTypes.number,
|
|
|
|
insets: PropTypes.object
|
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);
|
2021-09-13 20:41:05 +00:00
|
|
|
console.time(`${this.constructor.name} init`);
|
|
|
|
console.time(`${this.constructor.name} mount`);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.t = props.route.params?.t;
|
|
|
|
this.tmid = props.route.params?.tmid;
|
|
|
|
const selectedMessage = props.route.params?.message;
|
|
|
|
const name = props.route.params?.name;
|
|
|
|
const fname = props.route.params?.fname;
|
|
|
|
const prid = props.route.params?.prid;
|
2020-10-30 17:35:07 +00:00
|
|
|
const room = props.route.params?.room ?? {
|
2021-09-13 20:41:05 +00:00
|
|
|
rid: this.rid,
|
|
|
|
t: this.t,
|
|
|
|
name,
|
|
|
|
fname,
|
|
|
|
prid
|
2020-10-30 17:35:07 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
this.jumpToMessageId = props.route.params?.jumpToMessageId;
|
2021-10-26 16:11:50 +00:00
|
|
|
this.jumpToThreadId = props.route.params?.jumpToThreadId;
|
2020-10-30 17:35:07 +00:00
|
|
|
const roomUserId = props.route.params?.roomUserId ?? RocketChat.getUidDirectMessage(room);
|
2017-08-07 18:42:02 +00:00
|
|
|
this.state = {
|
2019-09-16 20:26:32 +00:00
|
|
|
joined: true,
|
2020-10-30 17:35:07 +00:00
|
|
|
room,
|
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,
|
2021-05-26 17:24:54 +00:00
|
|
|
showingBlockingLoader: false,
|
2019-09-16 20:26:32 +00:00
|
|
|
editing: false,
|
|
|
|
replying: !!selectedMessage,
|
|
|
|
replyWithMention: false,
|
2020-02-20 19:44:33 +00:00
|
|
|
reacting: false,
|
2020-06-15 14:00:46 +00:00
|
|
|
readOnly: false,
|
|
|
|
unreadsCount: null,
|
2020-10-30 17:35:07 +00:00
|
|
|
roomUserId
|
2017-08-07 18:42:02 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-13 12:51:16 +00:00
|
|
|
this.setReadOnly();
|
|
|
|
|
2019-04-08 12:35:28 +00:00
|
|
|
this.messagebox = React.createRef();
|
2019-11-07 19:53:39 +00:00
|
|
|
this.list = React.createRef();
|
2020-12-01 17:30:39 +00:00
|
|
|
this.joinCode = React.createRef();
|
2021-05-26 17:24:54 +00:00
|
|
|
this.flatList = React.createRef();
|
2019-05-03 14:54:57 +00:00
|
|
|
this.mounted = false;
|
2021-02-11 21:42:50 +00:00
|
|
|
|
|
|
|
// we don't need to subscribe to threads
|
|
|
|
if (this.rid && !this.tmid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.sub = new RoomClass(this.rid);
|
|
|
|
}
|
2021-09-13 20:41:05 +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(() => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { isAuthenticated } = this.props;
|
|
|
|
this.setHeader();
|
2020-04-03 18:03:53 +00:00
|
|
|
if (this.rid) {
|
2021-02-11 21:42:50 +00:00
|
|
|
this.sub?.subscribe?.();
|
2020-04-03 18:03:53 +00:00
|
|
|
if (isAuthenticated) {
|
|
|
|
this.init();
|
|
|
|
} else {
|
|
|
|
EventEmitter.addEventListener('connected', this.handleConnected);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
if (this.jumpToMessageId) {
|
|
|
|
this.jumpToMessage(this.jumpToMessageId);
|
|
|
|
}
|
2021-10-26 16:11:50 +00:00
|
|
|
if (this.jumpToThreadId && !this.jumpToMessageId) {
|
|
|
|
this.navToThread({ tmid: this.jumpToThreadId });
|
|
|
|
}
|
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);
|
2021-09-13 20:41:05 +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;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { appState, theme, insets, route } = this.props;
|
2019-12-04 16:39:53 +00:00
|
|
|
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
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(nextProps.insets, insets)) {
|
2020-07-06 20:56:28 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
if (!dequal(nextProps.route?.params, route?.params)) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-02-26 16:01:45 +00:00
|
|
|
return roomAttrsUpdate.some(key => !dequal(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) {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { roomUpdate } = this.state;
|
2021-05-26 17:24:54 +00:00
|
|
|
const { appState, insets, route } = this.props;
|
|
|
|
|
|
|
|
if (route?.params?.jumpToMessageId !== prevProps.route?.params?.jumpToMessageId) {
|
|
|
|
this.jumpToMessage(route?.params?.jumpToMessageId);
|
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2021-10-26 16:11:50 +00:00
|
|
|
if (route?.params?.jumpToThreadId !== prevProps.route?.params?.jumpToThreadId) {
|
|
|
|
this.navToThread({ tmid: route?.params?.jumpToThreadId });
|
|
|
|
}
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
if (appState === 'foreground' && appState !== prevProps.appState && this.rid) {
|
2020-07-20 16:44:54 +00:00
|
|
|
// Fire List.query() just to keep observables working
|
|
|
|
if (this.list && this.list.current) {
|
|
|
|
this.list.current?.query?.();
|
|
|
|
}
|
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) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2020-03-30 20:19:01 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-08 17:36:10 +00:00
|
|
|
// If it's a livechat room
|
|
|
|
if (this.t === 'l') {
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(prevState.roomUpdate.visitor, roomUpdate.visitor)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
if (roomUpdate.teamMain !== prevState.roomUpdate.teamMain || roomUpdate.teamId !== prevState.roomUpdate.teamId) {
|
[NEW] Convert/Move Channel to Team (#3164)
* Added Create Team
* Added actionTypes, actions, ENG strings for Teams and updated NewMessageView
* Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
* Remove unnecessary actionTypes, reducers and sagas, e2e tests and navigation to team view
* Minor tweaks
* Show TeamChannelsView only if joined the team
* Minor tweak
* Added AddChannelTeamView
* Added permissions, translations strings for teams, deleteTeamRoom and addTeamRooms, AddExistingChannelView, updated CreateChannelView, TeamChannelsView
* Refactor touch component and update removeRoom and deleteRoom methods
* Minor tweaks
* Minor tweaks for removing channels and addExistingChannelView
* Added missing events and fixed channels list
* Minor tweaks for refactored touch component
* Added SelectListView and logic for leaving team
* Added addTeamMember and removeTeamMember
* Minor tweak
* Added deleteTeam function
* Minor tweak
* Minor tweaks
* Remove unnecesary changes, update TeamChannelsView, AddExistingChannelView, AddChannelTeamView, createChannel, goRoom and Touchable
* Remove unnecesary prop
* Add screens to ModalStack, events, autoJoin, update createChannel, addRoomsToTeam and Touchable
* Minor tweak
* Update loadMessagesForRoom.js
* Updated schema, tag component, touch, AddChannelTeamView, AddExistingChannelView, ActionSheet Item
* Fix unnecessary changes
* Add i18n, update createChannel, AddExistingChannelTeamView, AddChannelTeamView, RightButton and TeamChannelsView
* Updated styles, added tag story
* Minor tweak
* Minor tweaks
* Auto-join tweak
* Minor tweaks
* Minor tweak on search
* Minor refactor to ListItem, add SelectListView to ModalStack, update handleLeaveTeam
* Minor tweaks
* Update SelectListView
* Update handleLeaveTeam, remove unnecessary method, add story
* Minor tweak
* Minor visual tweaks
* Update SelectListView.js
* Update index.js
* Update RoomMembersView
* Updated SelectListView, RoomActionsView, leaveTeam method and string translations
* Update SelectListVIew
* Minor tweak
* Update SelectListView
* Minor tweak
* Minor tweaks
* Fix for List.Item subtitles being pushed down by title's flex
* Minor tweaks
* Update RoomActionsView
* Use showConfirmationAlert and showErrorAlert
* Remove addTeamMember, update removeTeamMember
* Update Alert
* Minor tweaks
* Minor tweaks
* Minor tweak
* Update showActionSheet on RoomMembersView
* Remove team main from query and move code around
* Fetch roles
* Update RoomMembersView and SelectListView
* Update rocketchat.js
* Updated leaveTeam and handleRemoveFromTeam
* Fix validation
* Remove unnecessary function
* Update RoomActionsView
* Update en.json
* updated deleteTeam function and permissions
* Added showConfirmationAlert
* Added string translations for teams
* Fix permission
* Added moveChannelToTeam and convertToTeam functionality
* Fix SelectListView RadioButton
* Fix moveToTeam
* Added searchBar to SelectListVIew
* Update RoomView , SelectListVIew and string translation for error
Co-authored-by: Diego Mello <diegolmello@gmail.com>
2021-06-02 13:44:19 +00:00
|
|
|
this.setHeader();
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
if (
|
|
|
|
(roomUpdate.fname !== prevState.roomUpdate.fname ||
|
|
|
|
roomUpdate.name !== prevState.roomUpdate.name ||
|
|
|
|
roomUpdate.teamMain !== prevState.roomUpdate.teamMain ||
|
|
|
|
roomUpdate.teamId !== prevState.roomUpdate.teamId) &&
|
|
|
|
!this.tmid
|
|
|
|
) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2020-03-30 20:19:01 +00:00
|
|
|
}
|
2020-07-06 20:56:28 +00:00
|
|
|
if (insets.left !== prevProps.insets.left || insets.right !== prevProps.insets.right) {
|
|
|
|
this.setHeader();
|
|
|
|
}
|
2020-06-26 20:22:56 +00:00
|
|
|
this.setReadOnly();
|
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 {
|
2021-02-26 16:25:51 +00:00
|
|
|
const threadsCollection = db.get('threads');
|
2019-09-16 20:26:32 +00:00
|
|
|
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 {
|
2021-09-13 20:41:05 +00:00
|
|
|
await db.action(async () => {
|
|
|
|
await obj.update(r => {
|
2019-09-16 20:26:32 +00:00
|
|
|
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();
|
|
|
|
}
|
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);
|
2021-09-13 20:41:05 +00:00
|
|
|
console.countReset(`${this.constructor.name}.render calls`);
|
2017-08-04 00:34:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
get isOmnichannel() {
|
|
|
|
const { room } = this.state;
|
|
|
|
return room.t === 'l';
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
setHeader = () => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { room, unreadsCount, roomUserId, joined } = this.state;
|
|
|
|
const { navigation, isMasterDetail, theme, baseUrl, user, insets, route } = this.props;
|
2020-10-30 17:35:07 +00:00
|
|
|
const { rid, tmid } = this;
|
|
|
|
const prid = room?.prid;
|
2021-03-31 17:47:17 +00:00
|
|
|
const isGroupChat = RocketChat.isGroupChat(room);
|
2020-06-15 14:00:46 +00:00
|
|
|
let title = route.params?.name;
|
2020-10-30 17:35:07 +00:00
|
|
|
let parentTitle;
|
|
|
|
if ((room.id || room.rid) && !tmid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
title = RocketChat.getRoomTitle(room);
|
|
|
|
}
|
2020-10-30 17:35:07 +00:00
|
|
|
if (tmid) {
|
|
|
|
parentTitle = RocketChat.getRoomTitle(room);
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
const subtitle = room?.topic;
|
2020-10-30 17:35:07 +00:00
|
|
|
const t = room?.t;
|
2021-04-07 18:31:25 +00:00
|
|
|
const teamMain = room?.teamMain;
|
|
|
|
const teamId = room?.teamId;
|
2021-10-05 13:58:21 +00:00
|
|
|
const encrypted = room?.encrypted;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { id: userId, token } = user;
|
|
|
|
const avatar = room?.name;
|
|
|
|
const visitor = room?.visitor;
|
2020-10-30 17:35:07 +00:00
|
|
|
if (!room?.rid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-07 18:31:25 +00:00
|
|
|
|
|
|
|
let numIconsRight = 2;
|
|
|
|
if (tmid) {
|
|
|
|
numIconsRight = 1;
|
2021-05-12 19:01:29 +00:00
|
|
|
} else if (isTeamRoom({ teamId, joined })) {
|
2021-04-07 18:31:25 +00:00
|
|
|
numIconsRight = 3;
|
|
|
|
}
|
|
|
|
const headerTitlePosition = getHeaderTitlePosition({ insets, numIconsRight });
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.setOptions({
|
|
|
|
headerShown: true,
|
|
|
|
headerTitleAlign: 'left',
|
2020-07-06 20:56:28 +00:00
|
|
|
headerTitleContainerStyle: {
|
|
|
|
left: headerTitlePosition.left,
|
|
|
|
right: headerTitlePosition.right
|
|
|
|
},
|
|
|
|
headerLeft: () => (
|
|
|
|
<LeftButtons
|
|
|
|
tmid={tmid}
|
|
|
|
unreadsCount={unreadsCount}
|
|
|
|
navigation={navigation}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={userId}
|
|
|
|
token={token}
|
|
|
|
title={avatar}
|
|
|
|
theme={theme}
|
|
|
|
t={t}
|
|
|
|
goRoomActionsView={this.goRoomActionsView}
|
|
|
|
isMasterDetail={isMasterDetail}
|
|
|
|
/>
|
|
|
|
),
|
2020-06-15 14:00:46 +00:00
|
|
|
headerTitle: () => (
|
2021-04-07 18:31:25 +00:00
|
|
|
<RoomHeader
|
2020-06-15 14:00:46 +00:00
|
|
|
rid={rid}
|
|
|
|
prid={prid}
|
|
|
|
tmid={tmid}
|
|
|
|
title={title}
|
2021-04-07 18:31:25 +00:00
|
|
|
teamMain={teamMain}
|
2020-10-30 17:35:07 +00:00
|
|
|
parentTitle={parentTitle}
|
2020-06-15 14:00:46 +00:00
|
|
|
subtitle={subtitle}
|
|
|
|
type={t}
|
|
|
|
roomUserId={roomUserId}
|
|
|
|
visitor={visitor}
|
2021-03-31 17:47:17 +00:00
|
|
|
isGroupChat={isGroupChat}
|
2021-04-07 18:31:25 +00:00
|
|
|
onPress={this.goRoomActionsView}
|
2021-09-13 20:41:05 +00:00
|
|
|
testID={`room-view-title-${title}`}
|
2020-06-15 14:00:46 +00:00
|
|
|
/>
|
|
|
|
),
|
|
|
|
headerRight: () => (
|
|
|
|
<RightButtons
|
|
|
|
rid={rid}
|
|
|
|
tmid={tmid}
|
2021-04-07 18:31:25 +00:00
|
|
|
teamId={teamId}
|
2021-05-12 19:01:29 +00:00
|
|
|
teamMain={teamMain}
|
|
|
|
joined={joined}
|
2020-06-15 14:00:46 +00:00
|
|
|
t={t}
|
2021-10-05 13:58:21 +00:00
|
|
|
encrypted={encrypted}
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation={navigation}
|
|
|
|
toggleFollowThread={this.toggleFollowThread}
|
|
|
|
/>
|
|
|
|
)
|
2020-03-30 20:19:01 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
goRoomActionsView = screen => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.ROOM_GO_RA);
|
2021-09-28 19:33:25 +00:00
|
|
|
const { room, member, joined } = this.state;
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
if (isMasterDetail) {
|
|
|
|
navigation.navigate('ModalStackNavigator', {
|
|
|
|
screen: screen ?? 'RoomActionsView',
|
|
|
|
params: {
|
2021-09-17 20:22:02 +00:00
|
|
|
rid: this.rid,
|
|
|
|
t: this.t,
|
|
|
|
room,
|
|
|
|
member,
|
2021-09-28 19:33:25 +00:00
|
|
|
showCloseModal: !!screen,
|
|
|
|
joined
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2021-07-22 15:24:24 +00:00
|
|
|
navigation.push('RoomActionsView', {
|
2021-09-17 20:22:02 +00:00
|
|
|
rid: this.rid,
|
|
|
|
t: this.t,
|
|
|
|
room,
|
2021-09-28 19:33:25 +00:00
|
|
|
member,
|
|
|
|
joined
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
setReadOnly = async () => {
|
2020-04-13 12:51:16 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { user } = this.props;
|
|
|
|
const readOnly = await isReadOnly(room, user);
|
|
|
|
this.setState({ readOnly });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-04-13 12:51:16 +00:00
|
|
|
|
2021-09-13 20:41:05 +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) {
|
2021-05-26 17:24:54 +00:00
|
|
|
await RoomServices.getThreadMessages(this.tmid, this.rid);
|
2019-12-13 16:23:20 +00:00
|
|
|
} else {
|
|
|
|
const newLastOpen = new Date();
|
2021-05-26 17:24:54 +00:00
|
|
|
await RoomServices.getMessages(room);
|
2019-12-13 16:23:20 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
RoomServices.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
|
|
|
|
2021-02-25 16:41:44 +00:00
|
|
|
const canAutoTranslate = 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
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
getRoomMember = async () => {
|
2020-03-30 20:19:01 +00:00
|
|
|
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-03-30 20:19:01 +00:00
|
|
|
try {
|
2020-04-09 05:20:57 +00:00
|
|
|
const roomUserId = RocketChat.getUidDirectMessage(room);
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setState({ roomUserId }, () => this.setHeader());
|
2020-04-01 12:28:54 +00:00
|
|
|
|
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 {};
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-30 20:19:01 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
findAndObserveRoom = async rid => {
|
2019-09-16 20:26:32 +00:00
|
|
|
try {
|
|
|
|
const db = database.active;
|
2021-02-26 16:25:51 +00:00
|
|
|
const subCollection = await db.get('subscriptions');
|
2019-09-16 20:26:32 +00:00
|
|
|
const room = await subCollection.find(rid);
|
|
|
|
this.setState({ room });
|
2020-02-28 17:39:17 +00:00
|
|
|
if (!this.tmid) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2020-02-28 17:39:17 +00:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +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;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-27 20:29:25 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
observeRoom = room => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const observable = room.observe();
|
2021-09-13 20:41:05 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
errorActionsShow = message => {
|
2020-06-15 19:35:45 +00:00
|
|
|
this.messageErrorActions?.showMessageErrorActions(message);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onEditInit = message => {
|
2021-02-23 17:24:05 +00:00
|
|
|
const newMessage = {
|
|
|
|
id: message.id,
|
|
|
|
subscription: {
|
|
|
|
id: message.subscription.id
|
|
|
|
},
|
|
|
|
msg: message?.attachments?.[0]?.description || message.msg
|
|
|
|
};
|
|
|
|
this.setState({ selectedMessage: newMessage, editing: true });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onEditCancel = () => {
|
|
|
|
this.setState({ selectedMessage: {}, editing: false });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onEditRequest = async message => {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ selectedMessage: {}, editing: false });
|
|
|
|
try {
|
|
|
|
await RocketChat.editMessage(message);
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onReplyInit = (message, mention) => {
|
|
|
|
this.setState({
|
2021-09-13 20:41:05 +00:00
|
|
|
selectedMessage: message,
|
|
|
|
replying: true,
|
|
|
|
replyWithMention: mention
|
2019-09-16 20:26:32 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onReplyCancel = () => {
|
2020-11-04 13:39:53 +00:00
|
|
|
this.setState({ selectedMessage: {}, replying: false, replyWithMention: false });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onReactionInit = message => {
|
2020-06-15 19:35:45 +00:00
|
|
|
this.setState({ selectedMessage: message, reacting: true });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
|
|
|
onReactionClose = () => {
|
|
|
|
this.setState({ selectedMessage: {}, reacting: false });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onMessageLongPress = message => {
|
2020-06-15 19:35:45 +00:00
|
|
|
this.messageActions?.showMessageActions(message);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-02-19 21:19:39 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
showAttachment = attachment => {
|
2019-12-18 21:13:11 +00:00
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('AttachmentView', { attachment });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-09-13 20:41:05 +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
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onReactionLongPress = message => {
|
2019-05-20 20:43:50 +00:00
|
|
|
this.setState({ selectedMessage: message, reactionsModalVisible: true });
|
2019-06-28 17:07:17 +00:00
|
|
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
|
|
|
onCloseReactionsModal = () => {
|
|
|
|
this.setState({ selectedMessage: {}, reactionsModalVisible: false });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2020-09-11 14:31:38 +00:00
|
|
|
onEncryptedPress = () => {
|
|
|
|
logEvent(events.ROOM_ENCRYPTED_PRESS);
|
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
|
|
|
|
const screen = { screen: 'E2EHowItWorksView', params: { showCloseModal: true } };
|
|
|
|
|
|
|
|
if (isMasterDetail) {
|
|
|
|
return navigation.navigate('ModalStackNavigator', screen);
|
|
|
|
}
|
|
|
|
navigation.navigate('E2ESaveYourPasswordStackNavigator', screen);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-09-11 14:31:38 +00:00
|
|
|
|
2021-09-13 20:41:05 +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-04-08 12:35:28 +00:00
|
|
|
|
2019-08-22 19:15:30 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
2021-09-13 20:41:05 +00:00
|
|
|
updateUnreadCount = async () => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const db = database.active;
|
|
|
|
const observable = await db.collections
|
|
|
|
.get('subscriptions')
|
2021-09-13 20:41:05 +00:00
|
|
|
.query(Q.where('archived', false), Q.where('open', true), Q.where('rid', Q.notEq(this.rid)))
|
2019-09-16 20:26:32 +00:00
|
|
|
.observeWithColumns(['unread']);
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
this.queryUnreads = observable.subscribe(data => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { unreadsCount } = this.state;
|
|
|
|
const newUnreadsCount = data.filter(s => s.unread > 0).reduce((a, b) => a + (b.unread || 0), 0);
|
|
|
|
if (unreadsCount !== newUnreadsCount) {
|
|
|
|
this.setState({ unreadsCount: newUnreadsCount }, () => this.setHeader());
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2019-08-22 19:15:30 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onThreadPress = debounce(item => this.navToThread(item), 1000, true);
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
shouldNavigateToRoom = message => {
|
2021-05-26 17:24:54 +00:00
|
|
|
if (message.tmid && message.tmid === this.tmid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!message.tmid && message.rid === this.rid) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
jumpToMessageByUrl = async messageUrl => {
|
2021-05-26 17:24:54 +00:00
|
|
|
if (!messageUrl) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
this.setState({ showingBlockingLoader: true });
|
|
|
|
const parsedUrl = parse(messageUrl, true);
|
|
|
|
const messageId = parsedUrl.query.msg;
|
|
|
|
await this.jumpToMessage(messageId);
|
|
|
|
this.setState({ showingBlockingLoader: false });
|
|
|
|
} catch (e) {
|
|
|
|
this.setState({ showingBlockingLoader: false });
|
|
|
|
log(e);
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
jumpToMessage = async messageId => {
|
2021-05-26 17:24:54 +00:00
|
|
|
try {
|
|
|
|
this.setState({ showingBlockingLoader: true });
|
|
|
|
const message = await RoomServices.getMessageInfo(messageId);
|
|
|
|
|
|
|
|
if (!message) {
|
|
|
|
return;
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
|
|
|
|
if (this.shouldNavigateToRoom(message)) {
|
|
|
|
if (message.rid !== this.rid) {
|
|
|
|
this.navToRoom(message);
|
|
|
|
} else {
|
|
|
|
this.navToThread(message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* if it's from server, we don't have it saved locally and so we fetch surroundings
|
|
|
|
* we test if it's not from threads because we're fetching from threads currently with `getThreadMessages`
|
|
|
|
*/
|
|
|
|
if (message.fromServer && !message.tmid) {
|
|
|
|
await RocketChat.loadSurroundingMessages({ messageId, rid: this.rid });
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
await Promise.race([this.list.current.jumpToMessage(message.id), new Promise(res => setTimeout(res, 5000))]);
|
2021-05-26 17:24:54 +00:00
|
|
|
this.list.current.cancelJumpToMessage();
|
2020-09-11 14:31:38 +00:00
|
|
|
}
|
2021-05-26 17:24:54 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
} finally {
|
|
|
|
this.setState({ showingBlockingLoader: false });
|
2019-05-20 20:43:50 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
replyBroadcast = message => {
|
2019-05-20 20:43:50 +00:00
|
|
|
const { replyBroadcast } = this.props;
|
|
|
|
replyBroadcast(message);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-20 20:43:50 +00:00
|
|
|
|
2019-04-17 17:01:03 +00:00
|
|
|
handleConnected = () => {
|
|
|
|
this.init();
|
|
|
|
EventEmitter.removeListener('connected', this.handleConnected);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-04-17 17:01:03 +00:00
|
|
|
|
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');
|
2021-09-13 20:41:05 +00:00
|
|
|
!this.isOmnichannel &&
|
|
|
|
showErrorAlert(I18n.t('You_were_removed_from_channel', { channel: RocketChat.getRoomTitle(room) }), I18n.t('Oops'));
|
2020-03-04 11:49:54 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-03-04 11:49:54 +00:00
|
|
|
|
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);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2020-10-30 17:35:07 +00:00
|
|
|
sendMessage = (message, tmid, tshow) => {
|
2020-07-30 19:51:13 +00:00
|
|
|
logEvent(events.ROOM_SEND_MESSAGE);
|
2019-07-29 16:33:28 +00:00
|
|
|
const { user } = this.props;
|
2020-10-30 17:35:07 +00:00
|
|
|
RocketChat.sendMessage(this.rid, message, this.tmid || tmid, user, tshow).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
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
getCustomEmoji = name => {
|
2019-09-16 20:26:32 +00:00
|
|
|
const { customEmojis } = this.props;
|
|
|
|
const emoji = customEmojis[name];
|
|
|
|
if (emoji) {
|
|
|
|
return emoji;
|
|
|
|
}
|
|
|
|
return null;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-09-16 20:26:32 +00:00
|
|
|
|
2019-05-20 20:43:50 +00:00
|
|
|
setLastOpen = lastOpen => this.setState({ lastOpen });
|
2019-03-27 20:06:57 +00:00
|
|
|
|
2020-12-01 17:30:39 +00:00
|
|
|
onJoin = () => {
|
|
|
|
this.internalSetState({
|
|
|
|
joined: true
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-12-01 17:30:39 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
joinRoom = async () => {
|
2020-07-31 18:22:30 +00:00
|
|
|
logEvent(events.ROOM_JOIN);
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2020-07-31 18:22:30 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
|
|
|
|
if (this.isOmnichannel) {
|
2020-08-28 19:41:08 +00:00
|
|
|
await takeInquiry(room._id);
|
2021-08-23 13:43:09 +00:00
|
|
|
this.onJoin();
|
2020-07-31 18:22:30 +00:00
|
|
|
} else {
|
2020-12-01 17:30:39 +00:00
|
|
|
const { joinCodeRequired } = room;
|
|
|
|
if (joinCodeRequired) {
|
|
|
|
this.joinCode.current?.show();
|
|
|
|
} else {
|
|
|
|
await RocketChat.joinRoom(this.rid, null, this.t);
|
|
|
|
this.onJoin();
|
|
|
|
}
|
2020-07-31 18:22:30 +00:00
|
|
|
}
|
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
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-08-10 16:16:32 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
getThreadName = (tmid, messageId) => getThreadName(this.rid, tmid, messageId);
|
2019-04-17 17:01:03 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
toggleFollowThread = async (isFollowingThread, tmid) => {
|
2019-05-15 19:33:30 +00:00
|
|
|
try {
|
2020-10-30 17:35:07 +00:00
|
|
|
await RocketChat.toggleFollowMessage(tmid ?? 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
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-05-15 19:33:30 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
getBadgeColor = messageId => {
|
2020-10-30 17:35:07 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { theme } = this.props;
|
|
|
|
return getBadgeColor({ subscription: room, theme, messageId });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-10-30 17:35:07 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
navToRoomInfo = navParam => {
|
2020-06-15 14:00:46 +00:00
|
|
|
const { navigation, user, isMasterDetail } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events[`ROOM_GO_${navParam.t === 'd' ? 'USER' : 'ROOM'}_INFO`]);
|
2019-08-22 18:08:07 +00:00
|
|
|
if (navParam.rid === user.id) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
navParam.showCloseModal = true;
|
|
|
|
navigation.navigate('ModalStackNavigator', { screen: 'RoomInfoView', params: navParam });
|
2019-11-25 20:01:17 +00:00
|
|
|
} else {
|
2020-06-15 14:00:46 +00:00
|
|
|
navigation.navigate('RoomInfoView', navParam);
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-08-22 18:08:07 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
navToThread = async item => {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { roomUserId } = this.state;
|
|
|
|
const { navigation } = this.props;
|
|
|
|
|
|
|
|
if (item.tmid) {
|
|
|
|
let name = item.tmsg;
|
|
|
|
if (!name) {
|
2021-10-26 16:11:50 +00:00
|
|
|
const result = await this.getThreadName(item.tmid, item.id);
|
|
|
|
// test if there isn't a thread
|
|
|
|
if (!result) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
name = result;
|
2021-05-26 17:24:54 +00:00
|
|
|
}
|
|
|
|
if (item.t === E2E_MESSAGE_TYPE && item.e2e !== E2E_STATUS.DONE) {
|
|
|
|
name = I18n.t('Encrypted_message');
|
|
|
|
}
|
|
|
|
return navigation.push('RoomView', {
|
2021-09-13 20:41:05 +00:00
|
|
|
rid: this.rid,
|
|
|
|
tmid: item.tmid,
|
|
|
|
name,
|
|
|
|
t: 'thread',
|
|
|
|
roomUserId,
|
|
|
|
jumpToMessageId: item.id
|
2021-05-26 17:24:54 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item.tlm) {
|
|
|
|
return navigation.push('RoomView', {
|
2021-09-13 20:41:05 +00:00
|
|
|
rid: this.rid,
|
|
|
|
tmid: item.id,
|
|
|
|
name: makeThreadName(item),
|
|
|
|
t: 'thread',
|
|
|
|
roomUserId
|
2021-05-26 17:24:54 +00:00
|
|
|
});
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
navToRoom = async message => {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { navigation, isMasterDetail } = this.props;
|
|
|
|
const roomInfo = await getRoomInfo(message.rid);
|
|
|
|
return goRoom({
|
2021-09-13 20:41:05 +00:00
|
|
|
item: roomInfo,
|
|
|
|
isMasterDetail,
|
|
|
|
navigationMethod: navigation.push,
|
|
|
|
jumpToMessageId: message.id
|
2021-05-26 17:24:54 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2021-05-26 17:24:54 +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 {
|
2021-02-22 21:37:13 +00:00
|
|
|
RocketChat.callJitsi(room);
|
2019-09-18 17:32:12 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-25 20:01:17 +00:00
|
|
|
handleCommands = ({ event }) => {
|
|
|
|
if (this.rid) {
|
|
|
|
const { input } = event;
|
|
|
|
if (handleCommandScroll(event)) {
|
|
|
|
const offset = input === 'UIKeyInputUpArrow' ? 100 : -100;
|
|
|
|
this.offset += offset;
|
2020-07-08 16:36:37 +00:00
|
|
|
this.flatList?.scrollToOffset({ offset: this.offset });
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandRoomActions(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoomActionsView();
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandSearchMessages(event)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.goRoomActionsView('SearchMessagesView');
|
2019-11-25 20:01:17 +00:00
|
|
|
} else if (handleCommandReplyLatest(event)) {
|
|
|
|
if (this.list && this.list.current) {
|
|
|
|
const message = this.list.current.getLastMessage();
|
|
|
|
this.onReplyInit(message, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-11-25 20:01:17 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
blockAction = ({ actionId, appId, value, blockId, rid, mid }) =>
|
|
|
|
RocketChat.triggerBlockAction({
|
|
|
|
blockId,
|
|
|
|
actionId,
|
|
|
|
value,
|
|
|
|
mid,
|
|
|
|
rid,
|
|
|
|
appId,
|
|
|
|
container: {
|
|
|
|
type: CONTAINER_TYPES.MESSAGE,
|
|
|
|
id: mid
|
|
|
|
}
|
|
|
|
});
|
2020-02-11 14:01:35 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
closeBanner = async () => {
|
2020-05-08 12:57:04 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
try {
|
|
|
|
const db = database.active;
|
2021-09-13 20:41:05 +00:00
|
|
|
await db.action(async () => {
|
|
|
|
await room.update(r => {
|
2020-05-08 12:57:04 +00:00
|
|
|
r.bannerClosed = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
isIgnored = message => {
|
2020-11-30 20:00:31 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
return room?.ignored?.includes?.(message?.u?._id) ?? false;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-11-30 20:00:31 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
onLoadMoreMessages = loaderItem =>
|
|
|
|
RoomServices.getMoreMessages({
|
|
|
|
rid: this.rid,
|
|
|
|
tmid: this.tmid,
|
|
|
|
t: this.t,
|
|
|
|
loaderItem
|
|
|
|
});
|
2021-05-26 17:24:54 +00:00
|
|
|
|
|
|
|
renderItem = (item, previousItem, highlightedMessage) => {
|
2019-06-28 17:02:30 +00:00
|
|
|
const { room, lastOpen, canAutoTranslate } = this.state;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { user, Message_GroupingPeriod, Message_TimeFormat, useRealName, baseUrl, Message_Read_Receipt_Enabled, theme } =
|
|
|
|
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 {
|
2021-09-13 20:41:05 +00:00
|
|
|
showUnreadSeparator = lastOpen && moment(item.ts).isSameOrAfter(lastOpen) && moment(previousItem.ts).isBefore(lastOpen);
|
2019-03-27 20:06:57 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
let content = null;
|
|
|
|
if (MESSAGE_TYPE_ANY_LOAD.includes(item.t)) {
|
2021-09-13 20:41:05 +00:00
|
|
|
content = (
|
|
|
|
<LoadMore
|
|
|
|
load={() => this.onLoadMoreMessages(item)}
|
|
|
|
type={item.t}
|
|
|
|
runOnRender={item.t === MESSAGE_TYPE_LOAD_MORE && !previousItem}
|
|
|
|
/>
|
|
|
|
);
|
2021-05-26 17:24:54 +00:00
|
|
|
} else {
|
|
|
|
content = (
|
|
|
|
<Message
|
|
|
|
item={item}
|
|
|
|
user={user}
|
|
|
|
rid={room.rid}
|
|
|
|
archived={room.archived}
|
|
|
|
broadcast={room.broadcast}
|
|
|
|
status={item.status}
|
|
|
|
isThreadRoom={!!this.tmid}
|
|
|
|
isIgnored={this.isIgnored(item)}
|
|
|
|
previousItem={previousItem}
|
|
|
|
fetchThreadName={this.getThreadName}
|
|
|
|
onReactionPress={this.onReactionPress}
|
|
|
|
onReactionLongPress={this.onReactionLongPress}
|
|
|
|
onLongPress={this.onMessageLongPress}
|
|
|
|
onEncryptedPress={this.onEncryptedPress}
|
|
|
|
onDiscussionPress={this.onDiscussionPress}
|
|
|
|
onThreadPress={this.onThreadPress}
|
2021-08-27 16:29:34 +00:00
|
|
|
onAnswerButtonPress={this.sendMessage}
|
2021-05-26 17:24:54 +00:00
|
|
|
showAttachment={this.showAttachment}
|
|
|
|
reactionInit={this.onReactionInit}
|
|
|
|
replyBroadcast={this.replyBroadcast}
|
|
|
|
errorActionsShow={this.errorActionsShow}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
Message_GroupingPeriod={Message_GroupingPeriod}
|
|
|
|
timeFormat={Message_TimeFormat}
|
|
|
|
useRealName={useRealName}
|
|
|
|
isReadReceiptEnabled={Message_Read_Receipt_Enabled}
|
|
|
|
autoTranslateRoom={canAutoTranslate && room.autoTranslate}
|
|
|
|
autoTranslateLanguage={room.autoTranslateLanguage}
|
|
|
|
navToRoomInfo={this.navToRoomInfo}
|
|
|
|
getCustomEmoji={this.getCustomEmoji}
|
|
|
|
callJitsi={this.callJitsi}
|
|
|
|
blockAction={this.blockAction}
|
|
|
|
threadBadgeColor={this.getBadgeColor(item?.id)}
|
|
|
|
toggleFollowThread={this.toggleFollowThread}
|
|
|
|
jumpToMessage={this.jumpToMessageByUrl}
|
|
|
|
highlighted={highlightedMessage === item.id}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2019-04-17 17:01:03 +00:00
|
|
|
|
|
|
|
if (showUnreadSeparator || dateSeparator) {
|
|
|
|
return (
|
2019-09-24 20:26:56 +00:00
|
|
|
<>
|
2021-05-26 17:24:54 +00:00
|
|
|
{content}
|
2021-09-13 20:41:05 +00:00
|
|
|
<Separator ts={dateSeparator} unread={showUnreadSeparator} theme={theme} />
|
2019-09-24 20:26:56 +00:00
|
|
|
</>
|
2019-04-17 17:01:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-26 17:24:54 +00:00
|
|
|
return content;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2017-08-07 00:34:35 +00:00
|
|
|
|
2017-08-10 16:16:32 +00:00
|
|
|
renderFooter = () => {
|
2021-09-22 17:29:26 +00:00
|
|
|
const { joined, room, selectedMessage, editing, replying, replyWithMention, readOnly, loading } = this.state;
|
|
|
|
const { navigation, theme, route } = this.props;
|
|
|
|
|
|
|
|
const usedCannedResponse = route?.params?.usedCannedResponse;
|
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'>
|
2021-09-13 20:41:05 +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 }]}
|
2021-09-22 17:29:26 +00:00
|
|
|
enabled={!loading}
|
2021-09-13 20:41:05 +00:00
|
|
|
theme={theme}>
|
|
|
|
<Text style={[styles.joinRoomText, { color: themes[theme].buttonText }]} testID='room-view-join-button'>
|
|
|
|
{I18n.t(this.isOmnichannel ? 'Take_it' : 'Join')}
|
|
|
|
</Text>
|
2019-12-04 16:39:53 +00:00
|
|
|
</Touch>
|
2018-09-19 14:18:32 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2020-04-13 12:51:16 +00:00
|
|
|
if (readOnly) {
|
2018-01-17 16:42:30 +00:00
|
|
|
return (
|
2019-04-08 12:35:28 +00:00
|
|
|
<View style={styles.readOnly}>
|
2021-09-13 20:41:05 +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}
|
2021-09-22 17:29:26 +00:00
|
|
|
usedCannedResponse={usedCannedResponse}
|
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 = () => {
|
2020-06-15 19:35:45 +00:00
|
|
|
const { room, readOnly } = this.state;
|
2020-12-17 16:55:19 +00:00
|
|
|
const { user } = this.props;
|
2018-07-18 20:34:59 +00:00
|
|
|
return (
|
2019-09-16 20:26:32 +00:00
|
|
|
<>
|
2020-06-15 19:35:45 +00:00
|
|
|
<MessageActions
|
2021-09-13 20:41:05 +00:00
|
|
|
ref={ref => (this.messageActions = ref)}
|
2020-06-15 19:35:45 +00:00
|
|
|
tmid={this.tmid}
|
|
|
|
room={room}
|
|
|
|
user={user}
|
|
|
|
editInit={this.onEditInit}
|
|
|
|
replyInit={this.onReplyInit}
|
|
|
|
reactionInit={this.onReactionInit}
|
|
|
|
onReactionPress={this.onReactionPress}
|
|
|
|
isReadOnly={readOnly}
|
|
|
|
/>
|
2021-09-13 20:41:05 +00:00
|
|
|
<MessageErrorActions ref={ref => (this.messageErrorActions = ref)} tmid={this.tmid} />
|
2019-09-16 20:26:32 +00:00
|
|
|
</>
|
2018-07-18 20:34:59 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-07-18 20:34:59 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
render() {
|
2021-09-13 20:41:05 +00:00
|
|
|
console.count(`${this.constructor.name}.render calls`);
|
|
|
|
const { room, reactionsModalVisible, selectedMessage, loading, reacting, showingBlockingLoader } = this.state;
|
2021-10-20 16:35:28 +00:00
|
|
|
const { user, baseUrl, theme, navigation, Hide_System_Messages, width, height, serverVersion } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { rid, t, sysMes, bannerClosed, announcement } = room;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2017-08-04 00:34:37 +00:00
|
|
|
return (
|
2021-09-13 20:41:05 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }} testID='room-view'>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2020-03-30 20:19:01 +00:00
|
|
|
<Banner
|
|
|
|
rid={rid}
|
|
|
|
title={I18n.t('Announcement')}
|
2020-05-08 12:57:04 +00:00
|
|
|
text={announcement}
|
|
|
|
bannerClosed={bannerClosed}
|
|
|
|
closeBanner={this.closeBanner}
|
2020-03-30 20:19:01 +00:00
|
|
|
theme={theme}
|
|
|
|
/>
|
2019-09-16 20:26:32 +00:00
|
|
|
<List
|
2019-11-07 19:53:39 +00:00
|
|
|
ref={this.list}
|
2021-05-26 17:24:54 +00:00
|
|
|
listRef={this.flatList}
|
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}
|
2020-11-12 14:17:32 +00:00
|
|
|
tunread={room?.tunread}
|
2020-11-30 20:00:31 +00:00
|
|
|
ignored={room?.ignored}
|
2019-09-16 20:26:32 +00:00
|
|
|
renderRow={this.renderItem}
|
|
|
|
loading={loading}
|
2020-02-17 19:06:18 +00:00
|
|
|
navigation={navigation}
|
2020-06-09 20:11:52 +00:00
|
|
|
hideSystemMessages={Array.isArray(sysMes) ? sysMes : Hide_System_Messages}
|
2020-10-30 17:35:07 +00:00
|
|
|
showMessageInMainThread={user.showMessageInMainThread}
|
2021-10-20 16:35:28 +00:00
|
|
|
serverVersion={serverVersion}
|
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}
|
2020-06-17 17:35:58 +00:00
|
|
|
width={width}
|
|
|
|
height={height}
|
2021-02-19 18:05:47 +00:00
|
|
|
theme={theme}
|
2019-09-16 20:26:32 +00:00
|
|
|
/>
|
2020-06-17 17:35:58 +00:00
|
|
|
<UploadProgress rid={this.rid} user={user} baseUrl={baseUrl} width={width} />
|
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
|
|
|
/>
|
2021-09-13 20:41:05 +00:00
|
|
|
<JoinCode ref={this.joinCode} onJoin={this.onJoin} rid={rid} t={t} theme={theme} />
|
2021-05-26 17:24:54 +00:00
|
|
|
<Loading visible={showingBlockingLoader} />
|
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),
|
2020-06-15 14:00:46 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
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,
|
2021-10-20 16:35:28 +00:00
|
|
|
serverVersion: state.server.version,
|
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))
|
|
|
|
});
|
|
|
|
|
2020-07-06 20:56:28 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withDimensions(withTheme(withSafeAreaInsets(RoomView))));
|