2023-09-26 14:33:53 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Text, View } from 'react-native';
|
|
|
|
import { BorderlessButton } from 'react-native-gesture-handler';
|
|
|
|
|
|
|
|
import { CustomIcon, TIconsName } from '../../../containers/CustomIcon';
|
|
|
|
import { ISubscription, SubscriptionType } from '../../../definitions';
|
|
|
|
import i18n from '../../../i18n';
|
|
|
|
import { useVideoConf } from '../../../lib/hooks/useVideoConf';
|
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import styles from '../styles';
|
2024-01-03 21:14:31 +00:00
|
|
|
import { compareServerVersion } from '../../../lib/methods/helpers';
|
2023-09-26 14:33:53 +00:00
|
|
|
|
|
|
|
function BaseButton({
|
|
|
|
danger,
|
|
|
|
iconName,
|
|
|
|
onPress,
|
|
|
|
label,
|
|
|
|
showIcon = true,
|
|
|
|
enabled = true
|
|
|
|
}: {
|
|
|
|
danger?: boolean;
|
|
|
|
iconName: TIconsName;
|
|
|
|
onPress?: (prop: any) => void;
|
|
|
|
label: string;
|
|
|
|
showIcon?: boolean;
|
|
|
|
enabled?: boolean;
|
|
|
|
}): React.ReactElement | null {
|
|
|
|
const { colors } = useTheme();
|
|
|
|
const color = danger ? colors.dangerColor : colors.actionTintColor;
|
|
|
|
|
|
|
|
if (showIcon)
|
|
|
|
return (
|
|
|
|
<BorderlessButton enabled={enabled} testID={`room-info-view-${iconName}`} onPress={onPress} style={styles.roomButton}>
|
|
|
|
<CustomIcon name={iconName} size={30} color={color} />
|
2024-01-03 21:14:31 +00:00
|
|
|
<Text numberOfLines={1} style={[styles.roomButtonText, { color }]}>
|
|
|
|
{label}
|
|
|
|
</Text>
|
2023-09-26 14:33:53 +00:00
|
|
|
</BorderlessButton>
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function CallButton({ rid, roomFromRid }: { rid: string; isDirect: boolean; roomFromRid: boolean }): React.ReactElement | null {
|
|
|
|
const { callEnabled, disabledTooltip, showInitCallActionSheet } = useVideoConf(rid);
|
|
|
|
return (
|
|
|
|
<BaseButton
|
|
|
|
onPress={showInitCallActionSheet}
|
|
|
|
iconName='phone'
|
|
|
|
label={i18n.t('Call')}
|
|
|
|
enabled={!disabledTooltip}
|
|
|
|
showIcon={callEnabled && !roomFromRid}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IRoomInfoButtons {
|
|
|
|
rid: string;
|
|
|
|
room: ISubscription | undefined;
|
|
|
|
roomUserId?: string;
|
|
|
|
isDirect: boolean;
|
|
|
|
fromRid?: string;
|
|
|
|
handleCreateDirectMessage: () => void;
|
|
|
|
handleIgnoreUser: () => void;
|
|
|
|
handleBlockUser: () => void;
|
2024-01-03 21:14:31 +00:00
|
|
|
handleReportUser: () => void;
|
2023-09-26 14:33:53 +00:00
|
|
|
roomFromRid: ISubscription | undefined;
|
2024-01-03 21:14:31 +00:00
|
|
|
serverVersion: string | null;
|
|
|
|
itsMe?: boolean;
|
2023-09-26 14:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const RoomInfoButtons = ({
|
|
|
|
rid,
|
|
|
|
room: roomFromProps,
|
|
|
|
roomUserId,
|
|
|
|
isDirect,
|
|
|
|
fromRid,
|
|
|
|
handleCreateDirectMessage,
|
|
|
|
handleIgnoreUser,
|
|
|
|
handleBlockUser,
|
2024-01-03 21:14:31 +00:00
|
|
|
handleReportUser,
|
|
|
|
roomFromRid,
|
|
|
|
serverVersion,
|
|
|
|
itsMe
|
2023-09-26 14:33:53 +00:00
|
|
|
}: IRoomInfoButtons): React.ReactElement => {
|
|
|
|
const room = roomFromRid || roomFromProps;
|
|
|
|
// Following the web behavior, when is a DM with myself, shouldn't appear block or ignore option
|
2023-11-08 18:03:53 +00:00
|
|
|
const isDmWithMyself = room?.uids?.filter((uid: string) => uid !== roomUserId).length === 0;
|
2023-09-26 14:33:53 +00:00
|
|
|
const isFromDm = room?.t === SubscriptionType.DIRECT;
|
|
|
|
const isDirectFromSaved = isDirect && fromRid && room;
|
|
|
|
const isIgnored = room?.ignored?.includes?.(roomUserId || '');
|
|
|
|
const isBlocked = room?.blocker;
|
|
|
|
|
|
|
|
const renderIgnoreUser = isDirectFromSaved && !isFromDm && !isDmWithMyself;
|
2024-01-03 21:14:31 +00:00
|
|
|
const renderBlockUser = !itsMe && isDirectFromSaved && isFromDm && !isDmWithMyself;
|
|
|
|
const renderReportUser =
|
|
|
|
!itsMe && isDirectFromSaved && !isDmWithMyself && compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '6.4.0');
|
2023-09-26 14:33:53 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.roomButtonsContainer}>
|
|
|
|
<BaseButton onPress={handleCreateDirectMessage} label={i18n.t('Message')} iconName='message' />
|
|
|
|
<CallButton isDirect={isDirect} rid={rid} roomFromRid={!!roomFromRid} />
|
|
|
|
<BaseButton
|
|
|
|
onPress={handleIgnoreUser}
|
|
|
|
label={i18n.t(isIgnored ? 'Unignore' : 'Ignore')}
|
|
|
|
iconName='ignore'
|
|
|
|
showIcon={!!renderIgnoreUser}
|
|
|
|
/>
|
|
|
|
<BaseButton
|
|
|
|
onPress={handleBlockUser}
|
2024-01-03 21:14:31 +00:00
|
|
|
label={i18n.t(`${isBlocked ? 'Unblock' : 'Block'}`)}
|
2023-09-26 14:33:53 +00:00
|
|
|
iconName='ignore'
|
|
|
|
showIcon={!!renderBlockUser}
|
2024-01-03 21:14:31 +00:00
|
|
|
/>
|
|
|
|
<BaseButton
|
|
|
|
onPress={handleReportUser}
|
|
|
|
label={i18n.t('Report')}
|
|
|
|
iconName='warning'
|
|
|
|
showIcon={!!renderReportUser}
|
2023-09-26 14:33:53 +00:00
|
|
|
danger
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RoomInfoButtons;
|