MM-24202 Add ability to invalidate specific versions (#4158)

This commit is contained in:
Elias Nahum 2020-04-16 08:53:20 -04:00 committed by GitHub
parent f610a1dd55
commit a02e536e35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 22 deletions

View file

@ -275,7 +275,13 @@ class GlobalEventHandler {
this.store.dispatch(batchActions([
{
type: General.OFFLINE_STORE_RESET,
data: initialState,
data: {
...initialState,
app: {
build: DeviceInfo.getBuildNumber(),
version: DeviceInfo.getVersion(),
},
},
},
{
type: General.STORE_REHYDRATION_COMPLETE,

View file

@ -52,8 +52,9 @@ const launchApp = (credentials) => {
]);
if (credentials) {
waitForHydration(store, async () => {
if (validatePreviousVersion(store, EphemeralStore.prevAppVersion)) {
waitForHydration(store, () => {
const valid = validatePreviousVersion(store);
if (valid) {
store.dispatch(loadMe());
resetToChannel({skipMetrics: true});
}

View file

@ -2,11 +2,11 @@
// See LICENSE.txt for license information.
import DeviceInfo from 'react-native-device-info';
import semver from 'semver/preload';
import {ViewTypes} from 'app/constants';
import initialState from 'app/initial_state';
import EphemeralStore from 'app/store/ephemeral_store';
import EphemeralStore from './ephemeral_store';
import {
captureException,
@ -20,20 +20,21 @@ export function messageRetention(store) {
const {entities, views} = action.payload;
if (!entities || !views) {
const version = DeviceInfo.getVersion();
EphemeralStore.prevAppVersion = version;
action.payload = {
...action.payload,
app: {
build: DeviceInfo.getBuildNumber(),
version,
},
};
return next(action);
}
if (!EphemeralStore.prevAppVersion) {
const version = DeviceInfo.getVersion();
const major = semver.major(version);
const minor = semver.minor(version);
const patch = semver.patch(version);
const prevAppVersion = `${major}.${parseInt(minor, 10) - 1}.${patch}`;
EphemeralStore.prevAppVersion = app?.version || prevAppVersion;
}
// When a new version of the app has been detected
if (!app || !app.version || app.version !== DeviceInfo.getVersion() || app.build !== DeviceInfo.getBuildNumber()) {
EphemeralStore.prevAppVersion = app?.version;
if (app?.version !== DeviceInfo.getVersion() || app?.build !== DeviceInfo.getBuildNumber()) {
// When a new version of the app has been detected
return next(resetStateForNewVersion(action));
}
@ -177,9 +178,6 @@ function resetStateForNewVersion(action) {
thread: {
drafts: threadDrafts,
},
root: {
hydrationComplete: true,
},
selectServer,
recentEmojis,
},

View file

@ -258,7 +258,6 @@ export default function configureAppStore(initialState) {
log: false,
},
blacklist: ['device', 'navigation', 'offline', 'requests'],
debounce: 500,
transforms: [
setTransformer,
viewsBlackListFilter,

View file

@ -2,6 +2,7 @@
// See LICENSE.txt for license information.
import merge from 'deepmerge';
import DeviceInfo from 'react-native-device-info';
function transformFromSet(incoming) {
const state = {...incoming};
@ -77,6 +78,10 @@ export function getStateForReset(initialState, currentState) {
});
const resetState = merge(initialState, {
app: {
build: DeviceInfo.getBuildNumber(),
version: DeviceInfo.getVersion(),
},
entities: {
users: {
currentUserId,

View file

@ -7,6 +7,7 @@ import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import {Posts} from 'mattermost-redux/constants';
import {logout} from 'app/actions/views/user';
import EphemeralStore from 'app/store/ephemeral_store';
const INVALID_VERSIONS = ['1.29.0'];
@ -87,8 +88,11 @@ export function isPendingPost(postId, userId) {
return postId.startsWith(userId);
}
export function validatePreviousVersion(store, version) {
if (INVALID_VERSIONS.includes(version)) {
export function validatePreviousVersion(store) {
const version = EphemeralStore.prevAppVersion;
if (!version || INVALID_VERSIONS.includes(version)) {
console.log('Previous version is no longer valid'); //eslint-disable-line no-console
store.dispatch(logout());
return false;
}