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

@ -120,6 +120,7 @@ import {
import {
DisappearingMessageConversationType,
isLegacyDisappearingModeEnabled,
resolveLegacyDisappearingMode,
} from '../util/expiringMessages';
import { markAttributesAsReadIfNeeded } from './messageFactory';
@ -853,6 +854,11 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
const isOutgoing = Boolean(!receivedAt);
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
// to be above the message that initiated that change, hence the subtraction.
const timestamp = (receivedAt || Date.now()) - 1;

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

@ -13,12 +13,11 @@ import { MessageModel } from '../models/message';
import { GetNetworkTime } from '../session/apis/snode_api/getNetworkTime';
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 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
// 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 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;
}
// 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
// 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 {
@ -437,13 +460,3 @@ export async function checkHasOutdatedClient(
await convoToUpdate.commit();
}
}
export function isLegacyDisappearingModeEnabled(
expirationType: DisappearingMessageConversationType | DisappearingMessageType | undefined
): boolean {
return Boolean(
expirationType &&
expirationType !== 'off' &&
!ReleasedFeatures.isDisappearMessageV2FeatureReleasedCached()
);
}

Loading…
Cancel
Save