fix: use storage put instead of data methods so that we can track in redux

added a fix in OverlayDisappearingMessages so when v2 turns on an and the app is running a migration occurs
pull/2660/head
William Grant 2 years ago
parent ec3f62d12f
commit 42924b0c54

@ -13,11 +13,15 @@ import {
getSelectedConversationExpirationSettings, getSelectedConversationExpirationSettings,
getSelectedConversationKey, getSelectedConversationKey,
} from '../../../../../state/selectors/conversations'; } from '../../../../../state/selectors/conversations';
import { DEFAULT_TIMER_OPTION } from '../../../../../util/expiringMessages'; import {
DEFAULT_TIMER_OPTION,
DisappearingMessageConversationType,
} from '../../../../../util/expiringMessages';
import { useTimerOptionsByMode } from '../../../../../hooks/useParamSelector'; import { useTimerOptionsByMode } from '../../../../../hooks/useParamSelector';
import { Header } from './Header'; import { Header } from './Header';
import { DisappearingModes } from './DisappearingModes'; import { DisappearingModes } from './DisappearingModes';
import { TimeOptions } from './TimeOptions'; import { TimeOptions } from './TimeOptions';
import { getConversationController } from '../../../../../session/conversations';
const StyledScrollContainer = styled.div` const StyledScrollContainer = styled.div`
width: 100%; width: 100%;
@ -113,6 +117,21 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
} }
}, [convoProps.expirationType, convoProps.expireTimer]); }, [convoProps.expirationType, convoProps.expireTimer]);
// 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.isMediumGroup()) {
defaultExpirationType = 'deleteAfterSend';
}
convo.set('expirationType', defaultExpirationType);
setModeSelected(defaultExpirationType);
}
}
}, [unlockNewModes, selectedConversationKey, modeSelected]);
return ( return (
<StyledScrollContainer> <StyledScrollContainer>
<StyledContainer container={true} flexDirection={'column'} alignItems={'center'}> <StyledContainer container={true} flexDirection={'column'} alignItems={'center'}>

@ -1,4 +1,4 @@
import { Data } from '../data/data'; import { Storage } from './storage';
// TODO update to agreed value between platforms // TODO update to agreed value between platforms
const featureReleaseTimestamp = 1706778000000; // unix 01/02/2024 09:00 const featureReleaseTimestamp = 1706778000000; // unix 01/02/2024 09:00
@ -15,10 +15,10 @@ export function resetFeatureReleasedCachedValue() {
export async function getIsFeatureReleased(): Promise<boolean> { export async function getIsFeatureReleased(): Promise<boolean> {
if (isFeatureReleased === undefined) { if (isFeatureReleased === undefined) {
// read values from db and cache them as it looks like we did not // read values from db and cache them as it looks like we did not
const oldIsFeatureReleased = (await Data.getItemById('featureReleased'))?.value; const oldIsFeatureReleased = Boolean(Storage.get('featureReleased'));
// values do not exist in the db yet. Let's store false for now in the db and update our cached value. // values do not exist in the db yet. Let's store false for now in the db and update our cached value.
if (oldIsFeatureReleased === undefined) { if (oldIsFeatureReleased === undefined) {
await Data.createOrUpdateItem({ id: 'featureReleased', value: false }); await Storage.put('featureReleased', false);
isFeatureReleased = false; isFeatureReleased = false;
} else { } else {
isFeatureReleased = oldIsFeatureReleased; isFeatureReleased = oldIsFeatureReleased;
@ -37,20 +37,14 @@ export async function checkIsFeatureReleased(featureName: string): Promise<boole
// Feature is already released and we don't need to update the db // Feature is already released and we don't need to update the db
} else { } else {
window.log.info(`[releaseFeature]: It is time to release ${featureName}. Releasing it now`); window.log.info(`[releaseFeature]: It is time to release ${featureName}. Releasing it now`);
await Data.createOrUpdateItem({ await Storage.put('featureReleased', true);
id: 'featureReleased',
value: true,
});
} }
isFeatureReleased = true; isFeatureReleased = true;
} else { } else {
// Reset featureReleased to false if we have already released a feature since we have updated the featureReleaseTimestamp to a later date. // Reset featureReleased to false if we have already released a feature since we have updated the featureReleaseTimestamp to a later date.
// The alternative solution would be to do a db migration everytime we want to use this system. // The alternative solution would be to do a db migration everytime we want to use this system.
if (featureAlreadyReleased) { if (featureAlreadyReleased) {
await Data.createOrUpdateItem({ await Storage.put('featureReleased', false);
id: 'featureReleased',
value: false,
});
isFeatureReleased = false; isFeatureReleased = false;
} }
} }

Loading…
Cancel
Save