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,
getSelectedConversationKey,
} 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 { Header } from './Header';
import { DisappearingModes } from './DisappearingModes';
import { TimeOptions } from './TimeOptions';
import { getConversationController } from '../../../../../session/conversations';
const StyledScrollContainer = styled.div`
width: 100%;
@ -113,6 +117,21 @@ export const OverlayDisappearingMessages = (props: OverlayDisappearingMessagesPr
}
}, [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 (
<StyledScrollContainer>
<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
const featureReleaseTimestamp = 1706778000000; // unix 01/02/2024 09:00
@ -15,10 +15,10 @@ export function resetFeatureReleasedCachedValue() {
export async function getIsFeatureReleased(): Promise<boolean> {
if (isFeatureReleased === undefined) {
// 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.
if (oldIsFeatureReleased === undefined) {
await Data.createOrUpdateItem({ id: 'featureReleased', value: false });
await Storage.put('featureReleased', false);
isFeatureReleased = false;
} else {
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
} else {
window.log.info(`[releaseFeature]: It is time to release ${featureName}. Releasing it now`);
await Data.createOrUpdateItem({
id: 'featureReleased',
value: true,
});
await Storage.put('featureReleased', true);
}
isFeatureReleased = true;
} else {
// 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.
if (featureAlreadyReleased) {
await Data.createOrUpdateItem({
id: 'featureReleased',
value: false,
});
await Storage.put('featureReleased', false);
isFeatureReleased = false;
}
}

Loading…
Cancel
Save