2022-11-24 11:37:08 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
import Touchable from 'react-native-platform-touchable';
|
|
|
|
|
|
|
|
import i18n from '../../../../i18n';
|
|
|
|
import { getSubscriptionByRoomId } from '../../../../lib/database/services/Subscription';
|
|
|
|
import { useAppSelector } from '../../../../lib/hooks';
|
|
|
|
import { getRoomAvatar, getUidDirectMessage } from '../../../../lib/methods/helpers';
|
2023-06-05 19:37:50 +00:00
|
|
|
import { Services } from '../../../../lib/services';
|
2022-11-24 11:37:08 +00:00
|
|
|
import { useTheme } from '../../../../theme';
|
|
|
|
import { useActionSheet } from '../../../ActionSheet';
|
|
|
|
import AvatarContainer from '../../../Avatar';
|
|
|
|
import Button from '../../../Button';
|
|
|
|
import { CustomIcon } from '../../../CustomIcon';
|
|
|
|
import StatusContainer from '../../../Status';
|
2023-06-05 19:37:50 +00:00
|
|
|
import { BUTTON_HIT_SLOP } from '../../../message/utils';
|
2022-11-24 11:37:08 +00:00
|
|
|
import useStyle from './styles';
|
|
|
|
|
2023-06-05 19:37:50 +00:00
|
|
|
const useUserData = (rid: string) => {
|
|
|
|
const [user, setUser] = useState({ username: '', avatar: '', uid: '', type: '' });
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const room = await getSubscriptionByRoomId(rid);
|
|
|
|
if (room) {
|
|
|
|
const uid = (await getUidDirectMessage(room)) as string;
|
|
|
|
const avt = getRoomAvatar(room);
|
|
|
|
setUser({ uid, username: room?.name || '', avatar: avt, type: room?.t || '' });
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const result = await Services.getUserInfo(rid);
|
|
|
|
if (result.success) {
|
|
|
|
setUser({
|
|
|
|
username: result.user.name || result.user.username,
|
|
|
|
avatar: result.user.username,
|
|
|
|
uid: result.user._id,
|
|
|
|
type: 'd'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return user;
|
|
|
|
};
|
|
|
|
|
2023-03-01 18:26:56 +00:00
|
|
|
export default function StartACallActionSheet({ rid, initCall }: { rid: string; initCall: Function }): React.ReactElement {
|
2022-11-24 11:37:08 +00:00
|
|
|
const style = useStyle();
|
|
|
|
const { colors } = useTheme();
|
2023-03-01 18:26:56 +00:00
|
|
|
const [mic, setMic] = useState(true);
|
|
|
|
const [cam, setCam] = useState(false);
|
2022-11-24 11:37:08 +00:00
|
|
|
const username = useAppSelector(state => state.login.user.username);
|
|
|
|
|
|
|
|
const { hideActionSheet } = useActionSheet();
|
2023-06-05 19:37:50 +00:00
|
|
|
const user = useUserData(rid);
|
2022-11-24 11:37:08 +00:00
|
|
|
|
|
|
|
const handleColor = (enabled: boolean) => (enabled ? colors.conferenceCallEnabledIcon : colors.conferenceCallDisabledIcon);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={style.actionSheetContainer}>
|
|
|
|
<View style={style.actionSheetHeader}>
|
|
|
|
<Text style={style.actionSheetHeaderTitle}>{i18n.t('Start_a_call')}</Text>
|
|
|
|
<View style={style.actionSheetHeaderButtons}>
|
|
|
|
<Touchable
|
2023-03-01 18:26:56 +00:00
|
|
|
onPress={() => setCam(!cam)}
|
|
|
|
style={[style.iconCallContainer, cam && style.enabledBackground, { marginRight: 6 }]}
|
2022-11-24 11:37:08 +00:00
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
>
|
2023-03-01 18:26:56 +00:00
|
|
|
<CustomIcon name={cam ? 'camera' : 'camera-disabled'} size={20} color={handleColor(cam)} />
|
2022-11-24 11:37:08 +00:00
|
|
|
</Touchable>
|
|
|
|
<Touchable
|
2023-03-01 18:26:56 +00:00
|
|
|
onPress={() => setMic(!mic)}
|
|
|
|
style={[style.iconCallContainer, mic && style.enabledBackground]}
|
2022-11-24 11:37:08 +00:00
|
|
|
hitSlop={BUTTON_HIT_SLOP}
|
|
|
|
>
|
2023-03-01 18:26:56 +00:00
|
|
|
<CustomIcon name={mic ? 'microphone' : 'microphone-disabled'} size={20} color={handleColor(mic)} />
|
2022-11-24 11:37:08 +00:00
|
|
|
</Touchable>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
<View style={style.actionSheetUsernameContainer}>
|
2023-06-05 19:37:50 +00:00
|
|
|
<AvatarContainer text={user.avatar} size={36} rid={rid} type={user.type} />
|
2022-11-24 11:37:08 +00:00
|
|
|
<StatusContainer size={16} id={user.uid} style={{ marginLeft: 8, marginRight: 6 }} />
|
2023-03-01 18:26:56 +00:00
|
|
|
<Text style={style.actionSheetUsername} numberOfLines={1}>
|
|
|
|
{user.username}
|
|
|
|
</Text>
|
2022-11-24 11:37:08 +00:00
|
|
|
</View>
|
|
|
|
<View style={style.actionSheetPhotoContainer}>
|
|
|
|
<AvatarContainer size={62} text={username} />
|
|
|
|
</View>
|
|
|
|
<Button
|
|
|
|
onPress={() => {
|
|
|
|
hideActionSheet();
|
|
|
|
setTimeout(() => {
|
2023-03-01 18:26:56 +00:00
|
|
|
initCall({ cam, mic });
|
2022-11-24 11:37:08 +00:00
|
|
|
}, 100);
|
|
|
|
}}
|
|
|
|
title={i18n.t('Call')}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|