2023-03-01 18:26:56 +00:00
|
|
|
import { CompositeNavigationProp, RouteProp } from '@react-navigation/native';
|
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2023-08-11 20:35:24 +00:00
|
|
|
import { uniq } from 'lodash';
|
2023-03-01 18:26:56 +00:00
|
|
|
import isEmpty from 'lodash/isEmpty';
|
2018-03-29 17:55:37 +00:00
|
|
|
import React from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { ScrollView, Text, View } from 'react-native';
|
2020-02-14 00:25:42 +00:00
|
|
|
import { BorderlessButton } from 'react-native-gesture-handler';
|
2019-01-31 16:08:38 +00:00
|
|
|
import { connect } from 'react-redux';
|
2022-03-03 21:46:53 +00:00
|
|
|
import { Observable, Subscription } from 'rxjs';
|
2023-03-01 18:26:56 +00:00
|
|
|
import UAParser from 'ua-parser-js';
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2023-04-10 14:59:00 +00:00
|
|
|
import { AvatarWithEdit } from '../../containers/Avatar';
|
2023-03-01 18:26:56 +00:00
|
|
|
import { CustomIcon, TIconsName } from '../../containers/CustomIcon';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2023-03-01 18:26:56 +00:00
|
|
|
import RoomTypeIcon from '../../containers/RoomTypeIcon';
|
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
|
|
|
import Status from '../../containers/Status';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2020-07-17 17:08:15 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
2023-08-11 20:35:24 +00:00
|
|
|
import { MarkdownPreview } from '../../containers/markdown';
|
2023-03-01 18:26:56 +00:00
|
|
|
import { IApplicationState, ISubscription, IUser, SubscriptionType, TSubscriptionModel } from '../../definitions';
|
|
|
|
import { ILivechatVisitor } from '../../definitions/ILivechatVisitor';
|
|
|
|
import I18n from '../../i18n';
|
|
|
|
import { themes } from '../../lib/constants';
|
|
|
|
import { getSubscriptionByRoomId } from '../../lib/database/services/Subscription';
|
|
|
|
import { getRoomTitle, getUidDirectMessage, hasPermission } from '../../lib/methods/helpers';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
|
|
|
import { goRoom } from '../../lib/methods/helpers/goRoom';
|
2023-03-01 18:26:56 +00:00
|
|
|
import { handleIgnore } from '../../lib/methods/helpers/handleIgnore';
|
|
|
|
import log, { events, logEvent } from '../../lib/methods/helpers/log';
|
2022-04-07 13:22:19 +00:00
|
|
|
import Navigation from '../../lib/navigation/appNavigation';
|
2023-03-01 18:26:56 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2023-08-11 20:35:24 +00:00
|
|
|
import { TUsersRoles } from '../../reducers/usersRoles';
|
2023-03-01 18:26:56 +00:00
|
|
|
import { MasterDetailInsideStackParamList } from '../../stacks/MasterDetailStack/types';
|
|
|
|
import { ChatsStackParamList } from '../../stacks/types';
|
|
|
|
import { TSupportedThemes, withTheme } from '../../theme';
|
|
|
|
import sharedStyles from '../Styles';
|
2021-09-13 20:41:05 +00:00
|
|
|
import Channel from './Channel';
|
|
|
|
import Direct from './Direct';
|
2023-03-01 18:26:56 +00:00
|
|
|
import Livechat from './Livechat';
|
2023-08-11 20:35:24 +00:00
|
|
|
import { CallButton } from './components/UserInfoButton';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2022-03-03 21:46:53 +00:00
|
|
|
|
|
|
|
interface IGetRoomTitle {
|
|
|
|
room: ISubscription;
|
|
|
|
type: SubscriptionType;
|
|
|
|
name?: string;
|
|
|
|
username: string;
|
|
|
|
statusText?: string;
|
2022-04-12 16:27:05 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-03-03 21:46:53 +00:00
|
|
|
}
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
const renderRoomTitle = ({ room, type, name, username, statusText, theme }: IGetRoomTitle) =>
|
2022-03-03 21:46:53 +00:00
|
|
|
type === SubscriptionType.DIRECT ? (
|
2020-02-14 00:25:42 +00:00
|
|
|
<>
|
2023-08-18 17:48:33 +00:00
|
|
|
<Text testID='room-info-view-name' style={[styles.roomTitle, { color: themes[theme].titleText }]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
{name}
|
|
|
|
</Text>
|
|
|
|
{username && (
|
|
|
|
<Text
|
|
|
|
testID='room-info-view-username'
|
2023-08-18 17:48:33 +00:00
|
|
|
style={[styles.roomUsername, { color: themes[theme].auxiliaryText }]}
|
2022-08-08 21:02:08 +00:00
|
|
|
>{`@${username}`}</Text>
|
2021-09-13 20:41:05 +00:00
|
|
|
)}
|
|
|
|
{!!statusText && (
|
|
|
|
<View testID='room-info-view-custom-status'>
|
2023-08-18 17:48:33 +00:00
|
|
|
<MarkdownPreview msg={statusText} style={[styles.roomUsername, { color: themes[theme].auxiliaryText }]} />
|
2021-09-13 20:41:05 +00:00
|
|
|
</View>
|
|
|
|
)}
|
2020-02-14 00:25:42 +00:00
|
|
|
</>
|
2021-09-13 20:41:05 +00:00
|
|
|
) : (
|
2018-08-31 16:46:33 +00:00
|
|
|
<View style={styles.roomTitleRow}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<RoomTypeIcon
|
|
|
|
type={room.prid ? 'discussion' : room.t}
|
|
|
|
teamMain={room.teamMain}
|
|
|
|
key='room-info-type'
|
|
|
|
status={room.visitor?.status}
|
2022-04-15 02:27:36 +00:00
|
|
|
sourceType={room.source}
|
2021-09-13 20:41:05 +00:00
|
|
|
/>
|
2023-08-18 17:48:33 +00:00
|
|
|
<Text testID='room-info-view-name' style={[styles.roomTitle, { color: themes[theme].titleText }]} key='room-info-name'>
|
2022-04-28 20:37:25 +00:00
|
|
|
{getRoomTitle(room)}
|
2021-09-13 20:41:05 +00:00
|
|
|
</Text>
|
2018-08-31 16:46:33 +00:00
|
|
|
</View>
|
2021-09-13 20:41:05 +00:00
|
|
|
);
|
2018-07-10 13:40:32 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
interface IRoomInfoViewProps {
|
|
|
|
navigation: CompositeNavigationProp<
|
|
|
|
StackNavigationProp<ChatsStackParamList, 'RoomInfoView'>,
|
|
|
|
StackNavigationProp<MasterDetailInsideStackParamList>
|
|
|
|
>;
|
|
|
|
route: RouteProp<ChatsStackParamList, 'RoomInfoView'>;
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: string;
|
2023-08-18 17:48:33 +00:00
|
|
|
theme: TSupportedThemes;
|
2022-03-03 21:46:53 +00:00
|
|
|
isMasterDetail: boolean;
|
|
|
|
jitsiEnabled: boolean;
|
|
|
|
editRoomPermission?: string[];
|
|
|
|
editOmnichannelContact?: string[];
|
|
|
|
editLivechatRoomCustomfields?: string[];
|
|
|
|
roles: { [key: string]: string };
|
2023-08-11 20:35:24 +00:00
|
|
|
usersRoles: TUsersRoles;
|
2022-03-03 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 18:20:59 +00:00
|
|
|
export interface IUserParsed extends IUser {
|
2022-03-03 21:46:53 +00:00
|
|
|
parsedRoles?: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface ILivechatVisitorModified extends ILivechatVisitor {
|
|
|
|
os?: string;
|
|
|
|
browser?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IRoomInfoViewState {
|
|
|
|
room: ISubscription;
|
2022-05-11 18:20:59 +00:00
|
|
|
roomUser: IUserParsed | ILivechatVisitorModified;
|
2022-03-03 21:46:53 +00:00
|
|
|
showEdit: boolean;
|
2022-10-13 21:29:55 +00:00
|
|
|
roomFromRid?: TSubscriptionModel;
|
2022-03-03 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewState> {
|
|
|
|
private rid: string;
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
private t: SubscriptionType;
|
|
|
|
|
|
|
|
private unsubscribeFocus?: () => void;
|
|
|
|
|
|
|
|
private subscription?: Subscription;
|
|
|
|
|
|
|
|
private roomObservable?: Observable<TSubscriptionModel>;
|
|
|
|
|
2022-10-13 21:29:55 +00:00
|
|
|
private fromRid?: string;
|
|
|
|
|
|
|
|
private subscriptionRoomFromRid?: Subscription;
|
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
constructor(props: IRoomInfoViewProps) {
|
2019-05-28 13:03:08 +00:00
|
|
|
super(props);
|
2020-06-15 14:00:46 +00:00
|
|
|
const room = props.route.params?.room;
|
|
|
|
const roomUser = props.route.params?.member;
|
|
|
|
this.rid = props.route.params?.rid;
|
|
|
|
this.t = props.route.params?.t;
|
2022-10-13 21:29:55 +00:00
|
|
|
this.fromRid = props.route.params?.fromRid;
|
2018-03-29 17:55:37 +00:00
|
|
|
this.state = {
|
2022-03-03 21:46:53 +00:00
|
|
|
room: (room || { rid: this.rid, t: this.t }) as any,
|
2020-06-15 14:00:46 +00:00
|
|
|
roomUser: roomUser || {},
|
2022-10-13 21:29:55 +00:00
|
|
|
showEdit: false,
|
|
|
|
roomFromRid: undefined
|
2018-03-29 17:55:37 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
componentDidMount() {
|
|
|
|
if (this.isDirect) {
|
|
|
|
this.loadUser();
|
2022-10-13 21:29:55 +00:00
|
|
|
this.loadRoomFromRid();
|
2020-05-08 17:36:10 +00:00
|
|
|
} else {
|
|
|
|
this.loadRoom();
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setHeader();
|
2020-05-08 17:36:10 +00:00
|
|
|
|
|
|
|
const { navigation } = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
this.unsubscribeFocus = navigation.addListener('focus', () => {
|
2020-05-08 17:36:10 +00:00
|
|
|
if (this.isLivechat) {
|
|
|
|
this.loadVisitor();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.subscription && this.subscription.unsubscribe) {
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
}
|
2022-10-13 21:29:55 +00:00
|
|
|
if (this.subscriptionRoomFromRid && this.subscriptionRoomFromRid.unsubscribe) {
|
|
|
|
this.subscriptionRoomFromRid.unsubscribe();
|
|
|
|
}
|
2020-06-15 14:00:46 +00:00
|
|
|
if (this.unsubscribeFocus) {
|
|
|
|
this.unsubscribeFocus();
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
setHeader = () => {
|
|
|
|
const { roomUser, room, showEdit } = this.state;
|
|
|
|
const { navigation, route } = this.props;
|
|
|
|
const t = route.params?.t;
|
|
|
|
const rid = route.params?.rid;
|
|
|
|
const showCloseModal = route.params?.showCloseModal;
|
|
|
|
navigation.setOptions({
|
2020-10-30 16:15:58 +00:00
|
|
|
headerLeft: showCloseModal ? () => <HeaderButton.CloseModal navigation={navigation} /> : undefined,
|
2022-03-03 21:46:53 +00:00
|
|
|
title: t === SubscriptionType.DIRECT ? I18n.t('User_Info') : I18n.t('Room_Info'),
|
2020-06-15 14:00:46 +00:00
|
|
|
headerRight: showEdit
|
|
|
|
? () => (
|
2021-09-13 20:41:05 +00:00
|
|
|
<HeaderButton.Container>
|
|
|
|
<HeaderButton.Item
|
|
|
|
iconName='edit'
|
|
|
|
onPress={() => {
|
2022-03-03 21:46:53 +00:00
|
|
|
const isLivechat = t === SubscriptionType.OMNICHANNEL;
|
2021-09-13 20:41:05 +00:00
|
|
|
logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]);
|
|
|
|
navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser });
|
|
|
|
}}
|
|
|
|
testID='room-info-view-edit-button'
|
|
|
|
/>
|
|
|
|
</HeaderButton.Container>
|
|
|
|
)
|
2022-03-03 21:46:53 +00:00
|
|
|
: undefined
|
2020-06-15 14:00:46 +00:00
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-06-15 14:00:46 +00:00
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
get isDirect() {
|
|
|
|
const { room } = this.state;
|
2022-03-03 21:46:53 +00:00
|
|
|
return room.t === SubscriptionType.DIRECT;
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isLivechat() {
|
|
|
|
const { room } = this.state;
|
2022-03-03 21:46:53 +00:00
|
|
|
return room.t === SubscriptionType.OMNICHANNEL;
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
getRoleDescription = (id: string) => {
|
2021-07-01 16:51:19 +00:00
|
|
|
const { roles } = this.props;
|
|
|
|
return roles[id];
|
2020-05-08 17:36:10 +00:00
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
loadVisitor = async () => {
|
2020-05-08 17:36:10 +00:00
|
|
|
const { room } = this.state;
|
|
|
|
try {
|
2022-03-03 21:46:53 +00:00
|
|
|
if (room.visitor?._id) {
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getVisitorInfo(room.visitor._id);
|
2022-03-03 21:46:53 +00:00
|
|
|
if (result.success) {
|
|
|
|
const { visitor } = result;
|
|
|
|
const params: { os?: string; browser?: string } = {};
|
|
|
|
if (visitor.userAgent) {
|
|
|
|
const ua = new UAParser();
|
|
|
|
ua.setUA(visitor.userAgent);
|
|
|
|
params.os = `${ua.getOS().name} ${ua.getOS().version}`;
|
|
|
|
params.browser = `${ua.getBrowser().name} ${ua.getBrowser().version}`;
|
|
|
|
}
|
2022-05-11 18:20:59 +00:00
|
|
|
this.setState({ roomUser: { ...visitor, ...params } as ILivechatVisitorModified }, () => this.setHeader());
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
// Do nothing
|
2020-03-30 20:19:01 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
parseRoles = (roleArray: string[]) =>
|
2022-01-12 14:04:15 +00:00
|
|
|
Promise.all(
|
|
|
|
roleArray.map(async role => {
|
|
|
|
const description = await this.getRoleDescription(role);
|
|
|
|
return description;
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2023-08-11 20:35:24 +00:00
|
|
|
setUser = async (user: IUser) => {
|
|
|
|
const roles = (() => {
|
|
|
|
const { usersRoles } = this.props;
|
|
|
|
const userRoles = usersRoles.find(u => u?.username === user.username);
|
|
|
|
let r: string[] = [];
|
|
|
|
if (userRoles?.roles?.length) r = userRoles.roles;
|
|
|
|
if (user.roles?.length) r = [...r, ...user.roles];
|
|
|
|
return uniq(r);
|
|
|
|
})();
|
|
|
|
if (roles.length) {
|
|
|
|
const parsedRoles = await this.parseRoles(roles);
|
|
|
|
this.setState({ roomUser: { ...user, parsedRoles } });
|
|
|
|
} else {
|
|
|
|
this.setState({ roomUser: user });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
loadUser = async () => {
|
2020-07-17 17:08:15 +00:00
|
|
|
const { room, roomUser } = this.state;
|
2020-03-30 20:19:01 +00:00
|
|
|
|
2021-02-01 17:18:55 +00:00
|
|
|
if (isEmpty(roomUser)) {
|
2019-04-29 16:03:52 +00:00
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
const roomUserId = getUidDirectMessage(room);
|
|
|
|
const result = await Services.getUserInfo(roomUserId);
|
2019-04-29 16:03:52 +00:00
|
|
|
if (result.success) {
|
2020-05-08 17:36:10 +00:00
|
|
|
const { user } = result;
|
2023-08-11 20:35:24 +00:00
|
|
|
this.setUser(user as IUser);
|
2018-12-21 10:55:35 +00:00
|
|
|
}
|
2020-05-08 17:36:10 +00:00
|
|
|
} catch {
|
|
|
|
// do nothing
|
2018-12-21 10:55:35 +00:00
|
|
|
}
|
2022-01-12 14:04:15 +00:00
|
|
|
} else {
|
2023-08-11 20:35:24 +00:00
|
|
|
this.setUser(roomUser as IUser);
|
2019-08-22 18:08:07 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-04-01 12:28:54 +00:00
|
|
|
|
2022-10-13 21:29:55 +00:00
|
|
|
loadRoomFromRid = async () => {
|
|
|
|
if (this.fromRid) {
|
|
|
|
try {
|
|
|
|
const sub = await getSubscriptionByRoomId(this.fromRid);
|
|
|
|
this.subscriptionRoomFromRid = sub?.observe().subscribe(roomFromRid => {
|
|
|
|
this.setState({ roomFromRid });
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
loadRoom = async () => {
|
2020-07-31 18:22:30 +00:00
|
|
|
const { room: roomState } = this.state;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { route, editRoomPermission, editOmnichannelContact, editLivechatRoomCustomfields } = this.props;
|
2022-03-03 21:46:53 +00:00
|
|
|
let room = route.params?.room as any;
|
|
|
|
const roomModel = room as TSubscriptionModel;
|
|
|
|
if (roomModel && roomModel.observe) {
|
|
|
|
this.roomObservable = roomModel.observe();
|
2021-09-13 20:41:05 +00:00
|
|
|
this.subscription = this.roomObservable.subscribe(changes => {
|
|
|
|
this.setState({ room: changes }, () => this.setHeader());
|
|
|
|
});
|
2019-08-22 18:08:07 +00:00
|
|
|
} else {
|
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.getRoomInfo(this.rid);
|
2019-08-22 18:08:07 +00:00
|
|
|
if (result.success) {
|
2020-05-08 17:36:10 +00:00
|
|
|
({ room } = result);
|
2020-07-31 18:22:30 +00:00
|
|
|
this.setState({ room: { ...roomState, ...room } });
|
2019-08-22 18:08:07 +00:00
|
|
|
}
|
2019-08-30 12:43:23 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
2019-08-22 18:08:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-08 17:36:10 +00:00
|
|
|
|
2021-08-23 13:42:09 +00:00
|
|
|
const permissionToEdit = this.isLivechat ? [editOmnichannelContact, editLivechatRoomCustomfields] : [editRoomPermission];
|
|
|
|
|
2022-04-28 20:37:25 +00:00
|
|
|
const permissions = await hasPermission(permissionToEdit, room.rid);
|
2021-08-23 13:42:09 +00:00
|
|
|
if (permissions.some(Boolean)) {
|
2020-06-15 14:00:46 +00:00
|
|
|
this.setState({ showEdit: true }, () => this.setHeader());
|
2018-12-21 10:55:35 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-03-29 17:55:37 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
createDirect = () =>
|
2022-03-03 21:46:53 +00:00
|
|
|
new Promise<void>(async (resolve, reject) => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const { route } = this.props;
|
2020-07-17 17:08:15 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
// We don't need to create a direct
|
|
|
|
const member = route.params?.member;
|
|
|
|
if (!isEmpty(member)) {
|
|
|
|
return resolve();
|
|
|
|
}
|
2020-07-17 17:08:15 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
// TODO: Check if some direct with the user already exists on database
|
|
|
|
try {
|
|
|
|
const {
|
|
|
|
roomUser: { username }
|
|
|
|
} = this.state;
|
2022-04-28 20:37:25 +00:00
|
|
|
const result = await Services.createDirectMessage(username);
|
2021-09-13 20:41:05 +00:00
|
|
|
if (result.success) {
|
|
|
|
const {
|
|
|
|
room: { rid }
|
|
|
|
} = result;
|
|
|
|
return this.setState(({ room }) => ({ room: { ...room, rid } }), resolve);
|
|
|
|
}
|
|
|
|
} catch {
|
|
|
|
// do nothing
|
2019-09-16 20:26:32 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
reject();
|
|
|
|
});
|
2018-06-01 17:38:13 +00:00
|
|
|
|
2020-05-11 14:19:28 +00:00
|
|
|
goRoom = () => {
|
2020-08-05 13:15:56 +00:00
|
|
|
logEvent(events.RI_GO_ROOM_USER);
|
2022-06-10 20:33:48 +00:00
|
|
|
const { room } = this.state;
|
2022-11-25 13:21:56 +00:00
|
|
|
const { navigation, isMasterDetail, subscribedRoom } = this.props;
|
2020-06-15 14:00:46 +00:00
|
|
|
const params = {
|
|
|
|
rid: room.rid,
|
2022-06-10 20:33:48 +00:00
|
|
|
name: getRoomTitle(room),
|
2020-06-15 14:00:46 +00:00
|
|
|
t: room.t,
|
2022-04-28 20:37:25 +00:00
|
|
|
roomUserId: getUidDirectMessage(room)
|
2020-06-15 14:00:46 +00:00
|
|
|
};
|
2020-05-11 14:19:28 +00:00
|
|
|
|
|
|
|
if (room.rid) {
|
2022-11-25 13:21:56 +00:00
|
|
|
if (room.rid === subscribedRoom) {
|
|
|
|
if (isMasterDetail) {
|
|
|
|
return Navigation.navigate('DrawerNavigator');
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
2022-11-25 13:21:56 +00:00
|
|
|
return navigation.goBack();
|
2020-02-14 00:25:42 +00:00
|
|
|
}
|
2022-11-25 13:21:56 +00:00
|
|
|
// if it's on master detail layout, we close the modal and replace RoomView
|
|
|
|
goRoom({ item: params, isMasterDetail, popToRoot: true });
|
2020-02-14 00:25:42 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-14 00:25:42 +00:00
|
|
|
|
2022-10-13 21:29:55 +00:00
|
|
|
handleCreateDirectMessage = async (onPress: () => void) => {
|
|
|
|
try {
|
|
|
|
if (this.isDirect) {
|
|
|
|
await this.createDirect();
|
|
|
|
}
|
|
|
|
onPress();
|
|
|
|
} catch {
|
|
|
|
EventEmitter.emit(LISTENER, {
|
|
|
|
message: I18n.t('error-action-not-allowed', { action: I18n.t('Create_Direct_Messages') })
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
handleBlockUser = async (rid: string, blocked: string, block: boolean) => {
|
|
|
|
logEvent(events.RI_TOGGLE_BLOCK_USER);
|
|
|
|
try {
|
|
|
|
await Services.toggleBlockUser(rid, blocked, block);
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
2023-04-10 14:59:00 +00:00
|
|
|
|
|
|
|
handleEditAvatar = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
const { room } = this.state;
|
|
|
|
navigation.navigate('ChangeAvatarView', { titleHeader: I18n.t('Room_Info'), room, t: this.t, context: 'room' });
|
|
|
|
};
|
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
renderAvatar = (room: ISubscription, roomUser: IUserParsed) => {
|
2020-10-30 13:12:02 +00:00
|
|
|
const { theme } = this.props;
|
2023-04-10 14:59:00 +00:00
|
|
|
const { showEdit } = this.state;
|
|
|
|
const showAvatarEdit = showEdit && this.t !== SubscriptionType.OMNICHANNEL;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
return (
|
2023-04-10 14:59:00 +00:00
|
|
|
<AvatarWithEdit
|
|
|
|
text={room.name || roomUser.username}
|
|
|
|
style={styles.avatar}
|
|
|
|
type={this.t}
|
|
|
|
rid={room?.rid}
|
|
|
|
handleEdit={showAvatarEdit ? this.handleEditAvatar : undefined}
|
|
|
|
>
|
2022-03-03 21:46:53 +00:00
|
|
|
{this.t === SubscriptionType.DIRECT && roomUser._id ? (
|
2023-08-18 17:48:33 +00:00
|
|
|
<View style={[sharedStyles.status, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Status size={20} id={roomUser._id} />
|
|
|
|
</View>
|
|
|
|
) : null}
|
2023-04-10 14:59:00 +00:00
|
|
|
</AvatarWithEdit>
|
2018-09-25 19:28:42 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-05-18 17:55:08 +00:00
|
|
|
|
2022-10-13 21:29:55 +00:00
|
|
|
renderButton = (onPress: () => void, iconName: TIconsName, text: string, danger?: boolean) => {
|
2020-02-14 00:25:42 +00:00
|
|
|
const { theme } = this.props;
|
2023-08-18 17:48:33 +00:00
|
|
|
const color = danger ? themes[theme].dangerColor : themes[theme].actionTintColor;
|
2020-02-14 00:25:42 +00:00
|
|
|
return (
|
2022-10-13 21:29:55 +00:00
|
|
|
<BorderlessButton testID={`room-info-view-${iconName}`} onPress={onPress} style={styles.roomButton}>
|
|
|
|
<CustomIcon name={iconName} size={30} color={color} />
|
|
|
|
<Text style={[styles.roomButtonText, { color }]}>{text}</Text>
|
2020-02-14 00:25:42 +00:00
|
|
|
</BorderlessButton>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-14 00:25:42 +00:00
|
|
|
|
2020-07-17 17:08:15 +00:00
|
|
|
renderButtons = () => {
|
2023-03-01 18:26:56 +00:00
|
|
|
const { roomFromRid, roomUser, room } = this.state;
|
2022-10-13 21:29:55 +00:00
|
|
|
|
|
|
|
const isFromDm = roomFromRid?.rid ? new RegExp(roomUser._id).test(roomFromRid.rid) : false;
|
|
|
|
const isDirectFromSaved = this.isDirect && this.fromRid && roomFromRid;
|
|
|
|
|
|
|
|
// Following the web behavior, when is a DM with myself, shouldn't appear block or ignore option
|
|
|
|
const isDmWithMyself = roomFromRid?.uids && roomFromRid.uids?.filter(uid => uid !== roomUser._id).length === 0;
|
|
|
|
|
|
|
|
const ignored = roomFromRid?.ignored;
|
|
|
|
const isIgnored = ignored?.includes?.(roomUser._id);
|
|
|
|
|
|
|
|
const blocker = roomFromRid?.blocker;
|
|
|
|
|
2020-07-17 17:08:15 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.roomButtonsContainer}>
|
2022-10-13 21:29:55 +00:00
|
|
|
{this.renderButton(() => this.handleCreateDirectMessage(this.goRoom), 'message', I18n.t('Message'))}
|
2023-03-01 18:26:56 +00:00
|
|
|
<CallButton isDirect={this.isDirect} rid={room.rid} />
|
2022-10-13 21:29:55 +00:00
|
|
|
{isDirectFromSaved && !isFromDm && !isDmWithMyself
|
|
|
|
? this.renderButton(
|
|
|
|
() => handleIgnore(roomUser._id, !isIgnored, roomFromRid.rid),
|
|
|
|
'ignore',
|
|
|
|
I18n.t(isIgnored ? 'Unignore' : 'Ignore'),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
: null}
|
|
|
|
{isDirectFromSaved && isFromDm
|
|
|
|
? this.renderButton(
|
|
|
|
() => this.handleBlockUser(roomFromRid.rid, roomUser._id, !blocker),
|
|
|
|
'ignore',
|
|
|
|
I18n.t(`${blocker ? 'Unblock' : 'Block'}_user`),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
: null}
|
2020-07-17 17:08:15 +00:00
|
|
|
</View>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-02-14 00:25:42 +00:00
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
renderContent = () => {
|
|
|
|
const { room, roomUser } = this.state;
|
2019-08-22 18:08:07 +00:00
|
|
|
|
2020-05-08 17:36:10 +00:00
|
|
|
if (this.isDirect) {
|
2022-05-11 18:20:59 +00:00
|
|
|
return <Direct roomUser={roomUser as IUserParsed} />;
|
2022-03-03 21:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.t === SubscriptionType.OMNICHANNEL) {
|
2022-05-11 18:20:59 +00:00
|
|
|
return <Livechat room={room} roomUser={roomUser as ILivechatVisitorModified} />;
|
2020-05-08 17:36:10 +00:00
|
|
|
}
|
2022-03-03 21:46:53 +00:00
|
|
|
return <Channel room={room} />;
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2019-08-22 18:08:07 +00:00
|
|
|
|
2018-03-29 17:55:37 +00:00
|
|
|
render() {
|
|
|
|
const { room, roomUser } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { theme } = this.props;
|
2022-05-11 18:20:59 +00:00
|
|
|
const roomUserParsed = roomUser as IUserParsed;
|
2022-04-15 02:27:36 +00:00
|
|
|
|
2018-03-29 17:55:37 +00:00
|
|
|
return (
|
2023-08-18 17:48:33 +00:00
|
|
|
<ScrollView style={[styles.scroll, { backgroundColor: themes[theme].backgroundColor }]}>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
2023-08-18 17:48:33 +00:00
|
|
|
<SafeAreaView style={{ backgroundColor: themes[theme].backgroundColor }} testID='room-info-view'>
|
|
|
|
<View style={[styles.avatarContainer, { backgroundColor: themes[theme].auxiliaryBackground }]}>
|
2022-05-11 18:20:59 +00:00
|
|
|
{this.renderAvatar(room, roomUserParsed)}
|
2021-09-13 20:41:05 +00:00
|
|
|
<View style={styles.roomTitleContainer}>
|
2022-04-28 20:37:25 +00:00
|
|
|
{renderRoomTitle({
|
2022-03-03 21:46:53 +00:00
|
|
|
room,
|
|
|
|
type: this.t,
|
2022-05-11 18:20:59 +00:00
|
|
|
name: roomUserParsed?.name,
|
|
|
|
username: roomUserParsed?.username,
|
|
|
|
statusText: roomUserParsed?.statusText,
|
2023-08-18 17:48:33 +00:00
|
|
|
theme
|
2022-03-03 21:46:53 +00:00
|
|
|
})}
|
2021-09-13 20:41:05 +00:00
|
|
|
</View>
|
2021-04-01 13:54:39 +00:00
|
|
|
{this.renderButtons()}
|
2018-08-01 19:35:06 +00:00
|
|
|
</View>
|
2020-05-08 17:36:10 +00:00
|
|
|
{this.renderContent()}
|
2018-08-01 19:35:06 +00:00
|
|
|
</SafeAreaView>
|
2018-03-29 17:55:37 +00:00
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
2022-03-03 21:46:53 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2022-11-25 13:21:56 +00:00
|
|
|
subscribedRoom: state.room.subscribedRoom,
|
2020-07-17 17:08:15 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
2022-03-03 21:46:53 +00:00
|
|
|
jitsiEnabled: (state.settings.Jitsi_Enabled as boolean) || false,
|
2021-07-01 16:51:19 +00:00
|
|
|
editRoomPermission: state.permissions['edit-room'],
|
2021-08-23 13:42:09 +00:00
|
|
|
editOmnichannelContact: state.permissions['edit-omnichannel-contact'],
|
|
|
|
editLivechatRoomCustomfields: state.permissions['edit-livechat-room-customfields'],
|
2023-08-11 20:35:24 +00:00
|
|
|
roles: state.roles,
|
|
|
|
usersRoles: state.usersRoles
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2020-06-15 14:00:46 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(RoomInfoView));
|