2018-02-19 21:19:39 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-09-25 19:28:42 +00:00
|
|
|
import {
|
2019-05-29 21:19:12 +00:00
|
|
|
View, SectionList, Text, Alert, Share
|
2018-09-25 19:28:42 +00:00
|
|
|
} from 'react-native';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2020-03-30 20:19:01 +00:00
|
|
|
import _ from 'lodash';
|
2018-02-19 21:19:39 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import Touch from '../../utils/touch';
|
2020-04-01 12:28:54 +00:00
|
|
|
import { setLoading as setLoadingAction } from '../../actions/selectedUsers';
|
2020-05-08 17:36:10 +00:00
|
|
|
import { leaveRoom as leaveRoomAction, closeRoom as closeRoomAction } from '../../actions/room';
|
2018-02-19 21:19:39 +00:00
|
|
|
import styles from './styles';
|
2018-03-29 17:55:37 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2018-02-19 21:19:39 +00:00
|
|
|
import Avatar from '../../containers/Avatar';
|
2019-03-01 16:49:11 +00:00
|
|
|
import Status from '../../containers/Status';
|
2018-03-02 15:11:34 +00:00
|
|
|
import RocketChat from '../../lib/rocketchat';
|
2020-08-05 13:15:56 +00:00
|
|
|
import log, { logEvent, events } from '../../utils/log';
|
2018-05-18 16:41:47 +00:00
|
|
|
import RoomTypeIcon from '../../containers/RoomTypeIcon';
|
2018-06-01 17:38:13 +00:00
|
|
|
import I18n from '../../i18n';
|
2018-08-10 17:26:36 +00:00
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
|
|
|
import DisclosureIndicator from '../../containers/DisclosureIndicator';
|
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';
|
|
|
|
import { withTheme } from '../../theme';
|
2019-11-25 20:01:17 +00:00
|
|
|
import { CloseModalButton } from '../../containers/HeaderButton';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-03-30 20:19:01 +00:00
|
|
|
import Markdown from '../../containers/markdown';
|
2020-05-08 17:36:10 +00:00
|
|
|
import { showConfirmationAlert, showErrorAlert } from '../../utils/info';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class RoomActionsView extends React.Component {
|
2020-06-15 14:00:46 +00:00
|
|
|
static navigationOptions = ({ navigation, isMasterDetail }) => {
|
2019-11-25 20:01:17 +00:00
|
|
|
const options = {
|
|
|
|
title: I18n.t('Actions')
|
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
if (isMasterDetail) {
|
|
|
|
options.headerLeft = () => <CloseModalButton navigation={navigation} testID='room-actions-view-close' />;
|
2019-11-25 20:01:17 +00:00
|
|
|
}
|
|
|
|
return options;
|
2018-10-23 21:39:48 +00:00
|
|
|
}
|
|
|
|
|
2018-02-19 21:19:39 +00:00
|
|
|
static propTypes = {
|
2018-09-11 16:32:52 +00:00
|
|
|
baseUrl: PropTypes.string,
|
2019-03-12 16:23:06 +00:00
|
|
|
navigation: PropTypes.object,
|
2020-06-15 14:00:46 +00:00
|
|
|
route: PropTypes.object,
|
2019-02-07 19:58:20 +00:00
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
token: PropTypes.string
|
|
|
|
}),
|
2019-09-18 17:32:12 +00:00
|
|
|
leaveRoom: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
jitsiEnabled: PropTypes.bool,
|
2020-04-01 12:28:54 +00:00
|
|
|
setLoadingInvite: PropTypes.func,
|
2020-05-08 17:36:10 +00:00
|
|
|
closeRoom: PropTypes.func,
|
2019-12-04 16:39:53 +00:00
|
|
|
theme: PropTypes.string
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2019-09-16 20:26:32 +00:00
|
|
|
this.mounted = false;
|
2020-06-15 14:00:46 +00:00
|
|
|
const room = props.route.params?.room;
|
|
|
|
const member = props.route.params?.member;
|
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.t = props.route.params?.t;
|
2018-02-19 21:19:39 +00:00
|
|
|
this.state = {
|
2019-09-16 20:26:32 +00:00
|
|
|
room: room || { rid: this.rid, t: this.t },
|
2018-12-05 20:52:08 +00:00
|
|
|
membersCount: 0,
|
2020-03-30 20:19:01 +00:00
|
|
|
member: member || {},
|
2019-09-16 20:26:32 +00:00
|
|
|
joined: !!room,
|
2019-06-28 17:02:30 +00:00
|
|
|
canViewMembers: false,
|
2019-09-16 20:26:32 +00:00
|
|
|
canAutoTranslate: false,
|
2020-01-28 13:22:35 +00:00
|
|
|
canAddUser: false,
|
2020-05-08 17:36:10 +00:00
|
|
|
canInviteUser: false,
|
|
|
|
canForwardGuest: false,
|
|
|
|
canReturnQueue: false
|
2018-02-19 21:19:39 +00:00
|
|
|
};
|
2019-12-18 21:13:11 +00:00
|
|
|
if (room && room.observe && room.rid) {
|
2019-09-17 14:43:49 +00:00
|
|
|
this.roomObservable = room.observe();
|
|
|
|
this.subscription = this.roomObservable
|
|
|
|
.subscribe((changes) => {
|
|
|
|
if (this.mounted) {
|
|
|
|
this.setState({ room: changes });
|
|
|
|
} else {
|
|
|
|
this.state.room = changes;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
async componentDidMount() {
|
2019-09-16 20:26:32 +00:00
|
|
|
this.mounted = true;
|
2020-03-30 20:19:01 +00:00
|
|
|
const { room, member } = this.state;
|
2020-04-30 18:11:34 +00:00
|
|
|
if (room.rid) {
|
2020-07-31 18:22:30 +00:00
|
|
|
if (!room.id && !this.isOmnichannelPreview) {
|
2020-04-30 18:11:34 +00:00
|
|
|
try {
|
|
|
|
const result = await RocketChat.getChannelInfo(room.rid);
|
|
|
|
if (result.success) {
|
|
|
|
this.setState({ room: { ...result.channel, rid: result.channel._id } });
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-04-08 12:35:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:11:34 +00:00
|
|
|
if (room && room.t !== 'd' && this.canViewMembers()) {
|
|
|
|
try {
|
|
|
|
const counters = await RocketChat.getRoomCounters(room.rid, room.t);
|
|
|
|
if (counters.success) {
|
|
|
|
this.setState({ membersCount: counters.members, joined: counters.joined });
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2018-12-05 20:52:08 +00:00
|
|
|
}
|
2020-04-30 18:11:34 +00:00
|
|
|
} else if (room.t === 'd' && _.isEmpty(member)) {
|
|
|
|
this.updateRoomMember();
|
2018-12-05 20:52:08 +00:00
|
|
|
}
|
2019-06-28 17:02:30 +00:00
|
|
|
|
2020-04-30 18:11:34 +00:00
|
|
|
const canAutoTranslate = await RocketChat.canAutoTranslate();
|
|
|
|
this.setState({ canAutoTranslate });
|
2019-06-28 17:02:30 +00:00
|
|
|
|
2020-04-30 18:11:34 +00:00
|
|
|
this.canAddUser();
|
|
|
|
this.canInviteUser();
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
// livechat permissions
|
|
|
|
if (room.t === 'l') {
|
|
|
|
this.canForwardGuest();
|
|
|
|
this.canReturnQueue();
|
|
|
|
}
|
2020-04-30 18:11:34 +00:00
|
|
|
}
|
2018-12-21 10:55:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
componentWillUnmount() {
|
2019-09-16 20:26:32 +00:00
|
|
|
if (this.subscription && this.subscription.unsubscribe) {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
2018-03-23 16:49:51 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
get isOmnichannelPreview() {
|
|
|
|
const { room } = this.state;
|
|
|
|
return room.t === 'l' && room.status === 'queued';
|
|
|
|
}
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
onPressTouchable = (item) => {
|
2020-08-05 13:15:56 +00:00
|
|
|
const { route, event, params } = item;
|
|
|
|
if (route) {
|
|
|
|
logEvent(events[`RA_GO_${ route.replace('View', '').toUpperCase() }${ params.name ? params.name.toUpperCase() : '' }`]);
|
2019-03-12 16:23:06 +00:00
|
|
|
const { navigation } = this.props;
|
2020-08-05 13:15:56 +00:00
|
|
|
navigation.navigate(route, params);
|
2018-03-23 16:49:51 +00:00
|
|
|
}
|
2020-08-05 13:15:56 +00:00
|
|
|
if (event) {
|
|
|
|
return event();
|
2018-03-23 16:49:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
// eslint-disable-next-line react/sort-comp
|
|
|
|
canAddUser = async() => {
|
2018-12-05 20:52:08 +00:00
|
|
|
const { room, joined } = this.state;
|
2018-10-16 20:30:04 +00:00
|
|
|
const { rid, t } = room;
|
2019-09-16 20:26:32 +00:00
|
|
|
let canAdd = false;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-12-05 20:52:08 +00:00
|
|
|
const userInRoom = joined;
|
2019-09-16 20:26:32 +00:00
|
|
|
const permissions = await RocketChat.hasPermission(['add-user-to-joined-room', 'add-user-to-any-c-room', 'add-user-to-any-p-room'], rid);
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
if (permissions) {
|
|
|
|
if (userInRoom && permissions['add-user-to-joined-room']) {
|
|
|
|
canAdd = true;
|
|
|
|
}
|
|
|
|
if (t === 'c' && permissions['add-user-to-any-c-room']) {
|
|
|
|
canAdd = true;
|
|
|
|
}
|
|
|
|
if (t === 'p' && permissions['add-user-to-any-p-room']) {
|
|
|
|
canAdd = true;
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
2019-09-16 20:26:32 +00:00
|
|
|
this.setState({ canAddUser: canAdd });
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2020-01-28 13:22:35 +00:00
|
|
|
canInviteUser = async() => {
|
|
|
|
const { room } = this.state;
|
|
|
|
const { rid } = room;
|
|
|
|
const permissions = await RocketChat.hasPermission(['create-invite-links'], rid);
|
|
|
|
|
|
|
|
const canInviteUser = permissions && permissions['create-invite-links'];
|
|
|
|
this.setState({ canInviteUser });
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
canViewMembers = async() => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { rid, t, broadcast } = room;
|
2018-05-24 20:17:45 +00:00
|
|
|
if (broadcast) {
|
|
|
|
const viewBroadcastMemberListPermission = 'view-broadcast-member-list';
|
2019-09-16 20:26:32 +00:00
|
|
|
const permissions = await RocketChat.hasPermission([viewBroadcastMemberListPermission], rid);
|
2018-05-24 20:17:45 +00:00
|
|
|
if (!permissions[viewBroadcastMemberListPermission]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-12-05 20:52:08 +00:00
|
|
|
|
|
|
|
// This method is executed only in componentDidMount and returns a value
|
|
|
|
// We save the state to read in render
|
|
|
|
const result = (t === 'c' || t === 'p');
|
|
|
|
this.setState({ canViewMembers: result });
|
|
|
|
return result;
|
2018-05-24 20:17:45 +00:00
|
|
|
}
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
canForwardGuest = async() => {
|
|
|
|
const { room } = this.state;
|
|
|
|
const { rid } = room;
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
const transferLivechatGuest = 'transfer-livechat-guest';
|
|
|
|
const permissions = await RocketChat.hasPermission([transferLivechatGuest], rid);
|
|
|
|
if (!permissions[transferLivechatGuest]) {
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ canForwardGuest: result });
|
|
|
|
}
|
|
|
|
|
|
|
|
canReturnQueue = async() => {
|
|
|
|
try {
|
|
|
|
const { returnQueue } = await RocketChat.getRoutingConfig();
|
|
|
|
this.setState({ canReturnQueue: returnQueue });
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
get sections() {
|
2018-12-21 10:55:35 +00:00
|
|
|
const {
|
2020-05-08 17:36:10 +00:00
|
|
|
room, member, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canForwardGuest, canReturnQueue
|
2018-12-21 10:55:35 +00:00
|
|
|
} = this.state;
|
2019-09-18 17:32:12 +00:00
|
|
|
const { jitsiEnabled } = this.props;
|
2018-04-24 19:34:03 +00:00
|
|
|
const {
|
2019-08-23 16:24:15 +00:00
|
|
|
rid, t, blocker
|
2018-10-16 20:30:04 +00:00
|
|
|
} = room;
|
2020-04-01 12:28:54 +00:00
|
|
|
const isGroupChat = RocketChat.isGroupChat(room);
|
2018-02-19 21:19:39 +00:00
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
const notificationsAction = {
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'notification',
|
2019-08-23 16:24:15 +00:00
|
|
|
name: I18n.t('Notifications'),
|
|
|
|
route: 'NotificationPrefView',
|
2019-09-16 20:26:32 +00:00
|
|
|
params: { rid, room },
|
2018-12-21 10:55:35 +00:00
|
|
|
testID: 'room-actions-notifications'
|
|
|
|
};
|
|
|
|
|
2019-09-18 17:32:12 +00:00
|
|
|
const jitsiActions = jitsiEnabled ? [
|
|
|
|
{
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'phone',
|
2019-09-18 17:32:12 +00:00
|
|
|
name: I18n.t('Voice_call'),
|
2019-09-25 22:13:39 +00:00
|
|
|
event: () => RocketChat.callJitsi(rid, true),
|
2019-09-18 17:32:12 +00:00
|
|
|
testID: 'room-actions-voice'
|
|
|
|
},
|
|
|
|
{
|
2020-07-30 19:48:06 +00:00
|
|
|
icon: 'camera',
|
2019-09-18 17:32:12 +00:00
|
|
|
name: I18n.t('Video_call'),
|
|
|
|
event: () => RocketChat.callJitsi(rid),
|
|
|
|
testID: 'room-actions-video'
|
|
|
|
}
|
|
|
|
] : [];
|
|
|
|
|
2018-02-19 21:19:39 +00:00
|
|
|
const sections = [{
|
2018-03-29 17:55:37 +00:00
|
|
|
data: [{
|
2019-03-01 16:49:11 +00:00
|
|
|
icon: 'star',
|
2018-07-10 13:40:32 +00:00
|
|
|
name: I18n.t('Room_Info'),
|
|
|
|
route: 'RoomInfoView',
|
2019-04-08 12:35:28 +00:00
|
|
|
// forward room only if room isn't joined
|
2020-03-30 20:19:01 +00:00
|
|
|
params: {
|
|
|
|
rid, t, room, member
|
|
|
|
},
|
2020-04-01 12:28:54 +00:00
|
|
|
disabled: isGroupChat,
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-info'
|
2018-03-29 17:55:37 +00:00
|
|
|
}],
|
2018-02-19 21:19:39 +00:00
|
|
|
renderItem: this.renderRoomInfo
|
|
|
|
}, {
|
2019-09-18 17:32:12 +00:00
|
|
|
data: jitsiActions,
|
2018-02-19 21:19:39 +00:00
|
|
|
renderItem: this.renderItem
|
|
|
|
}, {
|
|
|
|
data: [
|
2018-03-23 16:49:51 +00:00
|
|
|
{
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'attach',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Files'),
|
2019-05-10 17:09:07 +00:00
|
|
|
route: 'MessagesView',
|
|
|
|
params: { rid, t, name: 'Files' },
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-files'
|
2018-03-23 16:49:51 +00:00
|
|
|
},
|
2018-03-02 15:11:34 +00:00
|
|
|
{
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'mention',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Mentions'),
|
2019-05-10 17:09:07 +00:00
|
|
|
route: 'MessagesView',
|
|
|
|
params: { rid, t, name: 'Mentions' },
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-mentioned'
|
2018-03-02 15:11:34 +00:00
|
|
|
},
|
2018-02-19 21:19:39 +00:00
|
|
|
{
|
2019-03-01 16:49:11 +00:00
|
|
|
icon: 'star',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Starred'),
|
2019-05-10 17:09:07 +00:00
|
|
|
route: 'MessagesView',
|
|
|
|
params: { rid, t, name: 'Starred' },
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-starred'
|
2018-02-19 21:19:39 +00:00
|
|
|
},
|
2018-04-24 19:34:03 +00:00
|
|
|
{
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'search',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Search'),
|
2018-07-10 13:40:32 +00:00
|
|
|
route: 'SearchMessagesView',
|
2018-05-23 13:39:18 +00:00
|
|
|
params: { rid },
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-search'
|
2018-05-23 13:39:18 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-01 16:49:11 +00:00
|
|
|
icon: 'share',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Share'),
|
2019-05-29 21:19:12 +00:00
|
|
|
event: this.handleShare,
|
2018-05-23 13:39:18 +00:00
|
|
|
testID: 'room-actions-share'
|
2018-04-24 19:34:03 +00:00
|
|
|
},
|
2018-02-19 21:19:39 +00:00
|
|
|
{
|
2019-03-01 16:49:11 +00:00
|
|
|
icon: 'pin',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Pinned'),
|
2019-05-10 17:09:07 +00:00
|
|
|
route: 'MessagesView',
|
|
|
|
params: { rid, t, name: 'Pinned' },
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-pinned'
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
2018-02-19 21:19:39 +00:00
|
|
|
],
|
|
|
|
renderItem: this.renderItem
|
|
|
|
}];
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-06-28 17:02:30 +00:00
|
|
|
if (canAutoTranslate) {
|
|
|
|
sections[2].data.push({
|
|
|
|
icon: 'language',
|
|
|
|
name: I18n.t('Auto_Translate'),
|
|
|
|
route: 'AutoTranslateView',
|
2019-09-16 20:26:32 +00:00
|
|
|
params: { rid, room },
|
2019-06-28 17:02:30 +00:00
|
|
|
testID: 'room-actions-auto-translate'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:28:54 +00:00
|
|
|
if (isGroupChat) {
|
|
|
|
sections[2].data.unshift({
|
|
|
|
icon: 'team',
|
|
|
|
name: I18n.t('Members'),
|
|
|
|
description: membersCount > 0 ? `${ membersCount } ${ I18n.t('members') }` : null,
|
|
|
|
route: 'RoomMembersView',
|
|
|
|
params: { rid, room },
|
|
|
|
testID: 'room-actions-members'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t === 'd' && !isGroupChat) {
|
2018-02-19 21:19:39 +00:00
|
|
|
sections.push({
|
|
|
|
data: [
|
2018-03-23 16:49:51 +00:00
|
|
|
{
|
2019-03-01 16:49:11 +00:00
|
|
|
icon: 'ban',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t(`${ blocker ? 'Unblock' : 'Block' }_user`),
|
2018-03-23 16:49:51 +00:00
|
|
|
type: 'danger',
|
2019-03-12 16:23:06 +00:00
|
|
|
event: this.toggleBlockUser,
|
2018-05-23 13:39:18 +00:00
|
|
|
testID: 'room-actions-block-user'
|
2018-03-23 16:49:51 +00:00
|
|
|
}
|
2018-02-19 21:19:39 +00:00
|
|
|
],
|
|
|
|
renderItem: this.renderItem
|
|
|
|
});
|
2018-12-21 10:55:35 +00:00
|
|
|
sections[2].data.push(notificationsAction);
|
2018-02-19 21:19:39 +00:00
|
|
|
} else if (t === 'c' || t === 'p') {
|
2018-05-24 20:17:45 +00:00
|
|
|
const actions = [];
|
|
|
|
|
2018-12-05 20:52:08 +00:00
|
|
|
if (canViewMembers) {
|
2018-05-24 20:17:45 +00:00
|
|
|
actions.push({
|
2019-03-01 16:49:11 +00:00
|
|
|
icon: 'team',
|
2018-06-01 17:38:13 +00:00
|
|
|
name: I18n.t('Members'),
|
2018-12-21 10:55:35 +00:00
|
|
|
description: membersCount > 0 ? `${ membersCount } ${ I18n.t('members') }` : null,
|
2018-07-10 13:40:32 +00:00
|
|
|
route: 'RoomMembersView',
|
2019-09-16 20:26:32 +00:00
|
|
|
params: { rid, room },
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-members'
|
2018-05-24 20:17:45 +00:00
|
|
|
});
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
|
2019-09-16 20:26:32 +00:00
|
|
|
if (canAddUser) {
|
2018-04-24 19:34:03 +00:00
|
|
|
actions.push({
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'add',
|
2020-01-28 13:22:35 +00:00
|
|
|
name: I18n.t('Add_users'),
|
2018-07-10 13:40:32 +00:00
|
|
|
route: 'SelectedUsersView',
|
2018-04-24 19:34:03 +00:00
|
|
|
params: {
|
2019-03-12 16:23:06 +00:00
|
|
|
rid,
|
2020-04-01 12:28:54 +00:00
|
|
|
title: I18n.t('Add_users'),
|
|
|
|
nextAction: this.addUser
|
2018-12-21 10:55:35 +00:00
|
|
|
},
|
2019-01-31 16:08:38 +00:00
|
|
|
testID: 'room-actions-add-user'
|
2018-03-23 16:49:51 +00:00
|
|
|
});
|
|
|
|
}
|
2020-01-28 13:22:35 +00:00
|
|
|
if (canInviteUser) {
|
|
|
|
actions.push({
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'user-add',
|
2020-01-28 13:22:35 +00:00
|
|
|
name: I18n.t('Invite_users'),
|
|
|
|
route: 'InviteUsersView',
|
|
|
|
params: {
|
|
|
|
rid
|
|
|
|
},
|
|
|
|
testID: 'room-actions-invite-user'
|
|
|
|
});
|
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
sections[2].data = [...actions, ...sections[2].data];
|
2018-12-21 10:55:35 +00:00
|
|
|
|
|
|
|
if (joined) {
|
|
|
|
sections[2].data.push(notificationsAction);
|
|
|
|
sections.push({
|
|
|
|
data: [
|
|
|
|
{
|
2020-07-27 19:53:33 +00:00
|
|
|
icon: 'logout',
|
2018-12-21 10:55:35 +00:00
|
|
|
name: I18n.t('Leave_channel'),
|
|
|
|
type: 'danger',
|
2019-03-12 16:23:06 +00:00
|
|
|
event: this.leaveChannel,
|
2018-12-21 10:55:35 +00:00
|
|
|
testID: 'room-actions-leave-channel'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
renderItem: this.renderItem
|
|
|
|
});
|
|
|
|
}
|
2020-02-07 13:24:16 +00:00
|
|
|
} else if (t === 'l') {
|
2020-05-08 17:36:10 +00:00
|
|
|
sections[2].data = [];
|
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
if (!this.isOmnichannelPreview) {
|
2020-05-08 17:36:10 +00:00
|
|
|
sections[2].data.push({
|
2020-07-31 18:22:30 +00:00
|
|
|
icon: 'close',
|
|
|
|
name: I18n.t('Close'),
|
|
|
|
event: this.closeLivechat
|
2020-05-08 17:36:10 +00:00
|
|
|
});
|
|
|
|
|
2020-07-31 18:22:30 +00:00
|
|
|
if (canForwardGuest) {
|
|
|
|
sections[2].data.push({
|
|
|
|
icon: 'user-forward',
|
|
|
|
name: I18n.t('Forward'),
|
|
|
|
route: 'ForwardLivechatView',
|
|
|
|
params: { rid }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (canReturnQueue) {
|
|
|
|
sections[2].data.push({
|
|
|
|
icon: 'undo',
|
|
|
|
name: I18n.t('Return'),
|
|
|
|
event: this.returnLivechat
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
sections[2].data.push({
|
2020-07-31 18:22:30 +00:00
|
|
|
icon: 'history',
|
|
|
|
name: I18n.t('Navigation_history'),
|
|
|
|
route: 'VisitorNavigationView',
|
|
|
|
params: { rid }
|
2020-05-08 17:36:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
sections.push({
|
|
|
|
data: [notificationsAction],
|
|
|
|
renderItem: this.renderItem
|
|
|
|
});
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
2020-02-07 13:24:16 +00:00
|
|
|
|
2018-04-24 19:34:03 +00:00
|
|
|
return sections;
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderSeparator = () => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return <View style={[styles.separator, { backgroundColor: themes[theme].separatorColor }]} />;
|
|
|
|
}
|
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
closeLivechat = () => {
|
|
|
|
const { room: { rid } } = this.state;
|
|
|
|
const { closeRoom } = this.props;
|
|
|
|
|
|
|
|
closeRoom(rid);
|
|
|
|
}
|
|
|
|
|
|
|
|
returnLivechat = () => {
|
|
|
|
const { room: { rid } } = this.state;
|
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('Would_you_like_to_return_the_inquiry'),
|
|
|
|
callToAction: I18n.t('Yes'),
|
|
|
|
onPress: async() => {
|
|
|
|
try {
|
|
|
|
await RocketChat.returnLivechat(rid);
|
|
|
|
} catch (e) {
|
|
|
|
showErrorAlert(e.reason, I18n.t('Oops'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:15:10 +00:00
|
|
|
updateRoomMember = async() => {
|
|
|
|
const { room } = this.state;
|
|
|
|
|
|
|
|
try {
|
2020-04-01 12:28:54 +00:00
|
|
|
if (!RocketChat.isGroupChat(room)) {
|
2020-04-09 05:20:57 +00:00
|
|
|
const roomUserId = RocketChat.getUidDirectMessage(room);
|
2020-04-01 12:28:54 +00:00
|
|
|
const result = await RocketChat.getUserInfo(roomUserId);
|
|
|
|
if (result.success) {
|
|
|
|
this.setState({ member: result.user });
|
|
|
|
}
|
2019-04-29 16:03:52 +00:00
|
|
|
}
|
2018-12-12 15:15:10 +00:00
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-12-21 10:55:35 +00:00
|
|
|
this.setState({ member: {} });
|
2018-12-12 15:15:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 12:28:54 +00:00
|
|
|
addUser = async() => {
|
|
|
|
const { room } = this.state;
|
|
|
|
const { setLoadingInvite, navigation } = this.props;
|
|
|
|
const { rid } = room;
|
|
|
|
try {
|
|
|
|
setLoadingInvite(true);
|
|
|
|
await RocketChat.addUsersToRoom(rid);
|
|
|
|
navigation.pop();
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
} finally {
|
|
|
|
setLoadingInvite(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-23 21:39:48 +00:00
|
|
|
toggleBlockUser = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RA_TOGGLE_BLOCK_USER);
|
2018-09-25 19:28:42 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const { rid, blocker } = room;
|
2018-03-29 17:55:37 +00:00
|
|
|
const { member } = this.state;
|
2018-05-18 17:55:08 +00:00
|
|
|
try {
|
2018-05-24 20:17:45 +00:00
|
|
|
RocketChat.toggleBlockUser(rid, member._id, !blocker);
|
2018-05-18 17:55:08 +00:00
|
|
|
} catch (e) {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RA_TOGGLE_BLOCK_USER_F);
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-05-18 17:55:08 +00:00
|
|
|
}
|
2018-03-23 16:49:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-29 21:19:12 +00:00
|
|
|
handleShare = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RA_SHARE);
|
2019-05-29 21:19:12 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
const permalink = RocketChat.getPermalinkChannel(room);
|
2020-02-05 16:40:44 +00:00
|
|
|
if (!permalink) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-29 21:19:12 +00:00
|
|
|
Share.share({
|
|
|
|
message: permalink
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
leaveChannel = () => {
|
|
|
|
const { room } = this.state;
|
2018-09-25 19:28:42 +00:00
|
|
|
const { leaveRoom } = this.props;
|
|
|
|
|
2018-03-23 16:49:51 +00:00
|
|
|
Alert.alert(
|
2018-06-01 17:38:13 +00:00
|
|
|
I18n.t('Are_you_sure_question_mark'),
|
2020-04-30 16:24:49 +00:00
|
|
|
I18n.t('Are_you_sure_you_want_to_leave_the_room', { room: RocketChat.getRoomTitle(room) }),
|
2018-03-23 16:49:51 +00:00
|
|
|
[
|
|
|
|
{
|
2018-06-01 17:38:13 +00:00
|
|
|
text: I18n.t('Cancel'),
|
2018-03-23 16:49:51 +00:00
|
|
|
style: 'cancel'
|
|
|
|
},
|
|
|
|
{
|
2018-06-01 17:38:13 +00:00
|
|
|
text: I18n.t('Yes_action_it', { action: I18n.t('leave') }),
|
2018-03-23 16:49:51 +00:00
|
|
|
style: 'destructive',
|
2018-12-05 20:52:08 +00:00
|
|
|
onPress: () => leaveRoom(room.rid, room.t)
|
2018-03-23 16:49:51 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-03-02 15:11:34 +00:00
|
|
|
renderRoomInfo = ({ item }) => {
|
2018-03-29 17:55:37 +00:00
|
|
|
const { room, member } = this.state;
|
2018-03-23 16:49:51 +00:00
|
|
|
const { name, t, topic } = room;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { baseUrl, user, theme } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2020-04-01 12:28:54 +00:00
|
|
|
const avatar = RocketChat.getRoomAvatar(room);
|
|
|
|
|
2018-03-02 15:11:34 +00:00
|
|
|
return (
|
2020-04-01 12:28:54 +00:00
|
|
|
this.renderTouchableItem((
|
|
|
|
<>
|
|
|
|
<Avatar
|
|
|
|
text={avatar}
|
|
|
|
size={50}
|
|
|
|
style={styles.avatar}
|
|
|
|
type={t}
|
|
|
|
baseUrl={baseUrl}
|
|
|
|
userId={user.id}
|
|
|
|
token={user.token}
|
|
|
|
>
|
|
|
|
{t === 'd' && member._id ? <Status style={sharedStyles.status} id={member._id} /> : null }
|
|
|
|
</Avatar>
|
2020-05-08 17:09:36 +00:00
|
|
|
<View style={[styles.roomTitleContainer, item.disabled && styles.roomTitlePadding]}>
|
2020-04-01 12:28:54 +00:00
|
|
|
{room.t === 'd'
|
|
|
|
? <Text style={[styles.roomTitle, { color: themes[theme].titleText }]} numberOfLines={1}>{room.fname}</Text>
|
|
|
|
: (
|
|
|
|
<View style={styles.roomTitleRow}>
|
2020-05-08 17:36:10 +00:00
|
|
|
<RoomTypeIcon type={room.prid ? 'discussion' : room.t} status={room.visitor?.status} theme={theme} />
|
2020-04-30 16:24:49 +00:00
|
|
|
<Text style={[styles.roomTitle, { color: themes[theme].titleText }]} numberOfLines={1}>{RocketChat.getRoomTitle(room)}</Text>
|
2020-04-01 12:28:54 +00:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
<Markdown
|
|
|
|
preview
|
|
|
|
msg={t === 'd' ? `@${ name }` : topic}
|
|
|
|
style={[styles.roomDescription, { color: themes[theme].auxiliaryText }]}
|
|
|
|
numberOfLines={1}
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2020-05-08 17:09:36 +00:00
|
|
|
{room.t === 'd' && <Markdown msg={member.statusText} style={[styles.roomDescription, { color: themes[theme].auxiliaryText }]} preview theme={theme} numberOfLines={1} />}
|
2020-04-01 12:28:54 +00:00
|
|
|
</View>
|
|
|
|
{!item.disabled && <DisclosureIndicator theme={theme} />}
|
|
|
|
</>
|
|
|
|
), item)
|
2018-03-02 15:11:34 +00:00
|
|
|
);
|
|
|
|
}
|
2018-02-19 21:19:39 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
renderTouchableItem = (subview, item) => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<Touch
|
|
|
|
onPress={() => this.onPressTouchable(item)}
|
|
|
|
style={{ backgroundColor: themes[theme].backgroundColor }}
|
|
|
|
accessibilityLabel={item.name}
|
|
|
|
accessibilityTraits='button'
|
2020-04-01 12:28:54 +00:00
|
|
|
enabled={!item.disabled}
|
2019-12-04 16:39:53 +00:00
|
|
|
testID={item.testID}
|
|
|
|
theme={theme}
|
|
|
|
>
|
2020-04-01 12:28:54 +00:00
|
|
|
<View style={styles.sectionItem}>
|
2019-12-04 16:39:53 +00:00
|
|
|
{subview}
|
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
);
|
|
|
|
}
|
2018-02-19 21:19:39 +00:00
|
|
|
|
|
|
|
renderItem = ({ item }) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
|
|
|
const colorDanger = { color: themes[theme].dangerColor };
|
2020-04-01 12:28:54 +00:00
|
|
|
const subview = item.type === 'danger' ? (
|
|
|
|
<>
|
|
|
|
<CustomIcon name={item.icon} size={24} style={[styles.sectionItemIcon, colorDanger]} />
|
|
|
|
<Text style={[styles.sectionItemName, colorDanger]}>{ item.name }</Text>
|
|
|
|
</>
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<CustomIcon name={item.icon} size={24} style={[styles.sectionItemIcon, { color: themes[theme].bodyText }]} />
|
|
|
|
<Text style={[styles.sectionItemName, { color: themes[theme].bodyText }]}>{ item.name }</Text>
|
|
|
|
{item.description ? <Text style={[styles.sectionItemDescription, { color: themes[theme].auxiliaryText }]}>{ item.description }</Text> : null}
|
|
|
|
<DisclosureIndicator theme={theme} />
|
|
|
|
</>
|
|
|
|
);
|
2018-02-19 21:19:39 +00:00
|
|
|
return this.renderTouchableItem(subview, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSectionSeparator = (data) => {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2018-04-24 19:34:03 +00:00
|
|
|
if (data.trailingItem) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <View style={[styles.sectionSeparator, data.leadingSection && styles.sectionSeparatorBorder, { backgroundColor: themes[theme].auxiliaryBackground, borderColor: themes[theme].separatorColor }]} />;
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
2018-04-24 19:34:03 +00:00
|
|
|
if (!data.trailingSection) {
|
2019-12-04 16:39:53 +00:00
|
|
|
return <View style={[styles.sectionSeparatorBorder, { backgroundColor: themes[theme].auxiliaryBackground, borderColor: themes[theme].separatorColor }]} />;
|
2018-04-24 19:34:03 +00:00
|
|
|
}
|
|
|
|
return null;
|
2018-02-19 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2018-02-19 21:19:39 +00:00
|
|
|
return (
|
2020-06-15 14:00:46 +00:00
|
|
|
<SafeAreaView testID='room-actions-view' theme={theme}>
|
2019-12-04 16:39:53 +00:00
|
|
|
<StatusBar theme={theme} />
|
2018-05-23 13:39:18 +00:00
|
|
|
<SectionList
|
2019-12-04 16:39:53 +00:00
|
|
|
contentContainerStyle={[styles.contentContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
|
|
|
style={[styles.container, { backgroundColor: themes[theme].auxiliaryBackground }]}
|
2018-05-23 13:39:18 +00:00
|
|
|
stickySectionHeadersEnabled={false}
|
|
|
|
sections={this.sections}
|
|
|
|
SectionSeparatorComponent={this.renderSectionSeparator}
|
2019-12-04 16:39:53 +00:00
|
|
|
ItemSeparatorComponent={this.renderSeparator}
|
2018-05-23 13:39:18 +00:00
|
|
|
keyExtractor={item => item.name}
|
|
|
|
testID='room-actions-list'
|
2018-08-10 17:26:36 +00:00
|
|
|
{...scrollPersistTaps}
|
2018-05-23 13:39:18 +00:00
|
|
|
/>
|
2018-08-01 19:35:06 +00:00
|
|
|
</SafeAreaView>
|
2018-02-19 21:19:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
user: getUserSelector(state),
|
|
|
|
baseUrl: state.server.server,
|
2019-09-18 17:32:12 +00:00
|
|
|
jitsiEnabled: state.settings.Jitsi_Enabled || false
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
2020-04-01 12:28:54 +00:00
|
|
|
leaveRoom: (rid, t) => dispatch(leaveRoomAction(rid, t)),
|
2020-05-08 17:36:10 +00:00
|
|
|
closeRoom: rid => dispatch(closeRoomAction(rid)),
|
2020-04-01 12:28:54 +00:00
|
|
|
setLoadingInvite: loading => dispatch(setLoadingAction(loading))
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(RoomActionsView));
|