feat: remove unlockNewModes from OverlayDisappearingMessages

use isDisappearMessageV2FeatureReleasedCached to set the mode to legacy strictly in the UI, created resolveLegacyDisappearingMode to change the legacy mode into the default mode for a conversation
pull/2971/head
William Grant 2 years ago
parent cc63887273
commit 60b75a8ddf

@ -3,12 +3,10 @@ import { useDispatch, useSelector } from 'react-redux';
import styled from 'styled-components'; import styled from 'styled-components';
import { useTimerOptionsByMode } from '../../../../../hooks/useParamSelector'; import { useTimerOptionsByMode } from '../../../../../hooks/useParamSelector';
import { setDisappearingMessagesByConvoId } from '../../../../../interactions/conversationInteractions'; import { setDisappearingMessagesByConvoId } from '../../../../../interactions/conversationInteractions';
import { getConversationController } from '../../../../../session/conversations';
import { closeRightPanel } from '../../../../../state/ducks/conversations'; import { closeRightPanel } from '../../../../../state/ducks/conversations';
import { resetRightOverlayMode } from '../../../../../state/ducks/section'; import { resetRightOverlayMode } from '../../../../../state/ducks/section';
import { import {
getSelectedConversationExpirationModes, getSelectedConversationExpirationModes,
getSelectedConversationExpirationModesWithLegacy,
useSelectedConversationKey, useSelectedConversationKey,
useSelectedExpirationType, useSelectedExpirationType,
useSelectedExpireTimer, useSelectedExpireTimer,
@ -25,6 +23,7 @@ import { SpacerLG, SpacerXL } from '../../../../basic/Text';
import { DisappearingModes } from './DisappearingModes'; import { DisappearingModes } from './DisappearingModes';
import { Header } from './Header'; import { Header } from './Header';
import { TimeOptions } from './TimeOptions'; import { TimeOptions } from './TimeOptions';
import { ReleasedFeatures } from '../../../../../util/releaseFeature';
const StyledScrollContainer = styled.div` const StyledScrollContainer = styled.div`
width: 100%; width: 100%;
@ -70,14 +69,10 @@ export type PropsForExpirationSettings = {
weAreAdmin: boolean | undefined; weAreAdmin: boolean | undefined;
}; };
export const OverlayDisappearingMessages = ({ unlockNewModes }: { unlockNewModes: boolean }) => { export const OverlayDisappearingMessages = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const selectedConversationKey = useSelectedConversationKey(); const selectedConversationKey = useSelectedConversationKey();
const disappearingModeOptions = useSelector( const disappearingModeOptions = useSelector(getSelectedConversationExpirationModes);
unlockNewModes
? getSelectedConversationExpirationModes
: getSelectedConversationExpirationModesWithLegacy
);
// NOTE if there is only 'off' and one disappearing message mode then we trigger single mode // NOTE if there is only 'off' and one disappearing message mode then we trigger single mode
const singleMode = const singleMode =
@ -96,7 +91,8 @@ export const OverlayDisappearingMessages = ({ unlockNewModes }: { unlockNewModes
const [modeSelected, setModeSelected] = useState<DisappearingMessageConversationType | undefined>( const [modeSelected, setModeSelected] = useState<DisappearingMessageConversationType | undefined>(
expirationType expirationType
); );
const [timeSelected, setTimeSelected] = useState<number>(0);
const [timeSelected, setTimeSelected] = useState(expireTimer || 0);
const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode); const timerOptions = useTimerOptionsByMode(modeSelected, hasOnlyOneMode);
const handleSetMode = async () => { const handleSetMode = async () => {
@ -123,30 +119,22 @@ export const OverlayDisappearingMessages = ({ unlockNewModes }: { unlockNewModes
setTimeSelected(value); setTimeSelected(value);
}; };
useEffect(() => {
if (!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()) {
setModeSelected(
expirationType === 'deleteAfterRead' || expirationType === 'deleteAfterSend'
? 'legacy'
: expirationType
);
}
}, [expirationType]);
useEffect(() => { useEffect(() => {
// NOTE loads a time value from the conversation model or the default // NOTE loads a time value from the conversation model or the default
handleSetTime( handleSetTime(
modeSelected === expirationType && expireTimer && expireTimer > -1 expireTimer && expireTimer > -1 ? expireTimer : loadDefaultTimeValue(modeSelected)
? expireTimer
: loadDefaultTimeValue(modeSelected)
); );
}, [expirationType, expireTimer, modeSelected]); }, [expireTimer, modeSelected]);
// TODO legacy messages support will be removed in a future
useEffect(() => {
if (unlockNewModes && modeSelected === 'legacy' && selectedConversationKey) {
const convo = getConversationController().get(selectedConversationKey);
if (convo) {
let defaultExpirationType: DisappearingMessageConversationType = 'deleteAfterRead';
if (convo.isMe() || convo.isClosedGroup()) {
defaultExpirationType = 'deleteAfterSend';
}
convo.set('expirationType', defaultExpirationType);
// TODO do we need to add libsession stuff here probably not?
setModeSelected(defaultExpirationType);
}
}
}, [unlockNewModes, selectedConversationKey, modeSelected]);
if (!disappearingModeOptions) { if (!disappearingModeOptions) {
return null; return null;
@ -155,6 +143,7 @@ export const OverlayDisappearingMessages = ({ unlockNewModes }: { unlockNewModes
if (!selectedConversationKey) { if (!selectedConversationKey) {
return null; return null;
} }
return ( return (
<StyledScrollContainer> <StyledScrollContainer>
<StyledContainer container={true} flexDirection={'column'} alignItems={'center'}> <StyledContainer container={true} flexDirection={'column'} alignItems={'center'}>

@ -120,6 +120,7 @@ import {
import { import {
DisappearingMessageConversationType, DisappearingMessageConversationType,
isLegacyDisappearingModeEnabled, isLegacyDisappearingModeEnabled,
resolveLegacyDisappearingMode,
} from '../util/expiringMessages'; } from '../util/expiringMessages';
import { markAttributesAsReadIfNeeded } from './messageFactory'; import { markAttributesAsReadIfNeeded } from './messageFactory';
@ -853,6 +854,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const isOutgoing = Boolean(!receivedAt); const isOutgoing = Boolean(!receivedAt);
source = source || UserUtils.getOurPubKeyStrFromCache(); source = source || UserUtils.getOurPubKeyStrFromCache();
// Note the legacy type should only be in the UI, it should change the the conversation type default before we send
if (expirationType === 'legacy') {
expirationType = resolveLegacyDisappearingMode(this);
}
// When we add a disappearing messages notification to the conversation, we want it // When we add a disappearing messages notification to the conversation, we want it
// to be above the message that initiated that change, hence the subtraction. // to be above the message that initiated that change, hence the subtraction.
const timestamp = (receivedAt || Date.now()) - 1; const timestamp = (receivedAt || Date.now()) - 1;

@ -95,6 +95,7 @@ import {
DisappearingMessageUpdate, DisappearingMessageUpdate,
ExpirationTimerOptions, ExpirationTimerOptions,
isLegacyDisappearingModeEnabled, isLegacyDisappearingModeEnabled,
resolveLegacyDisappearingMode,
setExpirationStartTimestamp, setExpirationStartTimestamp,
} from '../util/expiringMessages'; } from '../util/expiringMessages';
import { LinkPreviews } from '../util/linkPreviews'; import { LinkPreviews } from '../util/linkPreviews';
@ -1017,11 +1018,7 @@ export class MessageModel extends Backbone.Model<MessageAttributes> {
let expirationType: DisappearingMessageType = DisappearingMessageMode[content.expirationType]; let expirationType: DisappearingMessageType = DisappearingMessageMode[content.expirationType];
if (isLegacyDisappearingDataMessage) { if (isLegacyDisappearingDataMessage) {
if (conversation.isMe() || conversation.isClosedGroup()) { expirationType = resolveLegacyDisappearingMode(conversation);
expirationType = 'deleteAfterSend';
} else {
expirationType = 'deleteAfterRead';
}
} }
const expirationTimer = isLegacyDisappearingDataMessage const expirationTimer = isLegacyDisappearingDataMessage

@ -13,12 +13,11 @@ import { MessageModel } from '../models/message';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime'; import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
import { ReleasedFeatures } from './releaseFeature'; import { ReleasedFeatures } from './releaseFeature';
// TODO do we need to add legacy here now that it's explicitly in the protobuf?
export const DisappearingMessageMode = ['deleteAfterRead', 'deleteAfterSend']; export const DisappearingMessageMode = ['deleteAfterRead', 'deleteAfterSend'];
export type DisappearingMessageType = typeof DisappearingMessageMode[number] | null; export type DisappearingMessageType = typeof DisappearingMessageMode[number];
// NOTE these cannot be imported in the nodejs side yet. We need to move the types to the own file with no window imports // NOTE these cannot be imported in the nodejs side yet. We need to move the types to the own file with no window imports
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// TODO NOTE do we need to remove 'legacy' from here? // TODO NOTE legacy is strictly used in the UI and is not a valid disappearing message mode
export const DisappearingMessageConversationSetting = ['off', ...DisappearingMessageMode, 'legacy']; export const DisappearingMessageConversationSetting = ['off', ...DisappearingMessageMode, 'legacy'];
export type DisappearingMessageConversationType = typeof DisappearingMessageConversationSetting[number]; // TODO we should make this type a bit more hardcoded than being just resolved as a string export type DisappearingMessageConversationType = typeof DisappearingMessageConversationSetting[number]; // TODO we should make this type a bit more hardcoded than being just resolved as a string
@ -276,6 +275,30 @@ export function setExpirationStartTimestamp(
return expirationStartTimestamp; return expirationStartTimestamp;
} }
// TODO legacy messages support will be removed in a future release
export function isLegacyDisappearingModeEnabled(
expirationType: DisappearingMessageConversationType | DisappearingMessageType | undefined
): boolean {
return Boolean(
expirationType &&
expirationType !== 'off' &&
!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()
);
}
// TODO legacy messages support will be removed in a future release
/**
* This function is used to set the mode for legacy disappearing messages depending on the default for the conversation type
* @param convo Conversation we want to set
* @returns Disappearing mode we should use
*/
export function resolveLegacyDisappearingMode(convo: ConversationModel): DisappearingMessageType {
if (convo.isMe() || convo.isClosedGroup()) {
return 'deleteAfterSend';
}
return 'deleteAfterRead';
}
// TODO legacy messages support will be removed in a future release // TODO legacy messages support will be removed in a future release
// NOTE We need this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage // NOTE We need this to check for legacy disappearing messages where the expirationType and expireTimer should be undefined on the ContentMessage
function checkIsLegacyContentMessage(contentMessage: SignalService.Content): boolean { function checkIsLegacyContentMessage(contentMessage: SignalService.Content): boolean {
@ -437,13 +460,3 @@ export async function checkHasOutdatedClient(
await convoToUpdate.commit(); await convoToUpdate.commit();
} }
} }
export function isLegacyDisappearingModeEnabled(
expirationType: DisappearingMessageConversationType | DisappearingMessageType | undefined
): boolean {
return Boolean(
expirationType &&
expirationType !== 'off' &&
!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()
);
}

Loading…
Cancel
Save