Skip to content

Commit

Permalink
feat: enforce self deleting message group settings in conversations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tlebon committed Jun 2, 2023
1 parent 7ce6f75 commit 998c472
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
Expand Up @@ -139,9 +139,19 @@ const ConversationDetails = forwardRef<HTMLDivElement, ConversationDetailsProps>

const teamId = activeConversation.team_id;

const {isTeam, classifiedDomains, team} = useKoSubscribableChildren(teamState, [
const {
isTeam,
classifiedDomains,
team,
isSelfDeletingMessagesEnabled,
isSelfDeletingMessagesEnforced,
getEnforcedSelfDeletingMessagesTimeout,
} = useKoSubscribableChildren(teamState, [
'isTeam',
'classifiedDomains',
'isSelfDeletingMessagesEnabled',
'isSelfDeletingMessagesEnforced',
'getEnforcedSelfDeletingMessagesTimeout',
'team',
]);

Expand All @@ -153,7 +163,8 @@ const ConversationDetails = forwardRef<HTMLDivElement, ConversationDetailsProps>
const showOptionGuests = isActiveGroupParticipant && !!teamId && roleRepository.canToggleGuests(activeConversation);
const hasAdvancedNotifications = isMutable && isTeam;
const showOptionNotificationsGroup = hasAdvancedNotifications && isGroup;
const showOptionTimedMessages = isActiveGroupParticipant && roleRepository.canToggleTimeout(activeConversation);
const showOptionTimedMessages =
isActiveGroupParticipant && roleRepository.canToggleTimeout(activeConversation) && isSelfDeletingMessagesEnabled;
const showOptionServices =
isActiveGroupParticipant && !!teamId && roleRepository.canToggleGuests(activeConversation);
const showOptionReadReceipts = !!teamId && roleRepository.canToggleReadReceipts(activeConversation);
Expand All @@ -175,8 +186,11 @@ const ConversationDetails = forwardRef<HTMLDivElement, ConversationDetailsProps>
const servicesOptionsText = isServicesRoom ? t('conversationDetailsOn') : t('conversationDetailsOff');

const notificationStatusText = getNotificationText(notificationState);
const timedMessagesText =
hasTimer && globalMessageTimer ? formatDuration(globalMessageTimer).text : t('ephemeralUnitsNone');
const timedMessagesText = isSelfDeletingMessagesEnforced
? formatDuration(getEnforcedSelfDeletingMessagesTimeout).text
: hasTimer && globalMessageTimer
? formatDuration(globalMessageTimer).text
: t('ephemeralUnitsNone');

const showActionMute = isMutable && !isTeam;
const isVerified = verificationState === ConversationVerificationState.VERIFIED;
Expand Down
1 change: 1 addition & 0 deletions src/script/page/RightSidebar/RightSidebar.tsx
Expand Up @@ -248,6 +248,7 @@ const RightSidebar: FC<RightSidebarProps> = ({

{currentState === PanelState.TIMED_MESSAGES && (
<TimedMessages
teamState={teamState}
activeConversation={activeConversation}
repositories={repositories}
onClose={closePanel}
Expand Down
20 changes: 17 additions & 3 deletions src/script/page/RightSidebar/TimedMessages/TimedMessages.tsx
Expand Up @@ -29,6 +29,7 @@ import {formatDuration} from 'Util/TimeUtil';

import {Conversation} from '../../../entity/Conversation';
import {EphemeralTimings} from '../../../ephemeral/EphemeralTimings';
import {TeamState} from '../../../team/TeamState';
import {ViewModelRepositories} from '../../../view_model/MainViewModel';
import {PanelHeader} from '../PanelHeader';

Expand All @@ -37,6 +38,7 @@ interface TimedMessagesPanelProps {
onClose: () => void;
onGoBack: () => void;
repositories: ViewModelRepositories;
teamState: TeamState;
}

interface MessageTime {
Expand All @@ -45,14 +47,26 @@ interface MessageTime {
value: number;
}

const TimedMessages: FC<TimedMessagesPanelProps> = ({activeConversation, onClose, onGoBack, repositories}) => {
const TimedMessages: FC<TimedMessagesPanelProps> = ({
activeConversation,
onClose,
onGoBack,
repositories,
teamState,
}) => {
const [currentMessageTimer, setCurrentMessageTimer] = useState(0);
const [messageTimes, setMessageTimes] = useState<MessageTime[]>([]);

const {globalMessageTimer} = useKoSubscribableChildren(activeConversation, ['globalMessageTimer']);
const {isSelfDeletingMessagesEnforced, getEnforcedSelfDeletingMessagesTimeout} = useKoSubscribableChildren(
teamState,
['isSelfDeletingMessagesEnforced', 'getEnforcedSelfDeletingMessagesTimeout'],
);

useEffect(() => {
const messageTimer = globalMessageTimer ?? 0;
const messageTimer = isSelfDeletingMessagesEnforced
? getEnforcedSelfDeletingMessagesTimeout
: globalMessageTimer ?? 0;
setCurrentMessageTimer(messageTimer);

const mappedTimes = EphemeralTimings.VALUES.map(time => ({
Expand Down Expand Up @@ -104,7 +118,7 @@ const TimedMessages: FC<TimedMessagesPanelProps> = ({activeConversation, onClose
options={messageTimes.map(({text, isCustom, value}) => ({
label: text,
value: value,
isDisabled: isCustom,
isDisabled: isCustom || isSelfDeletingMessagesEnforced,
optionUeiName: 'item-timed-messages-option',
}))}
/>
Expand Down

0 comments on commit 998c472

Please sign in to comment.