[CHORE] Remove some migrations (#2792)
* Remove force rooms refresh * Remove MMKV migration
This commit is contained in:
parent
4d13689503
commit
645754674d
|
@ -14,7 +14,6 @@ import com.facebook.react.ReactFragmentActivity;
|
|||
|
||||
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
|
||||
import com.zoontek.rnbootsplash.RNBootSplash;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
class ThemePreferences {
|
||||
|
@ -36,61 +35,6 @@ public class MainActivity extends ReactFragmentActivity {
|
|||
// https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
|
||||
super.onCreate(null);
|
||||
RNBootSplash.init(R.drawable.launch_screen, MainActivity.this);
|
||||
|
||||
MMKV.initialize(MainActivity.this);
|
||||
|
||||
// Start the MMKV container
|
||||
MMKV defaultMMKV = MMKV.defaultMMKV();
|
||||
boolean alreadyMigrated = defaultMMKV.decodeBool("alreadyMigrated");
|
||||
|
||||
if (!alreadyMigrated) {
|
||||
// MMKV Instance that will be used by JS
|
||||
MMKV mmkv = MMKV.mmkvWithID("default");
|
||||
|
||||
// SharedPreferences -> MMKV (Migration)
|
||||
SharedPreferences sharedPreferences = getSharedPreferences("react-native", Context.MODE_PRIVATE);
|
||||
mmkv.importFromSharedPreferences(sharedPreferences);
|
||||
|
||||
// SharedPreferences only save strings, so we saved this value as a String and now we'll need to cast into a MMKV object
|
||||
|
||||
// Theme preferences object
|
||||
String THEME_PREFERENCES_KEY = "RC_THEME_PREFERENCES_KEY";
|
||||
String themeJson = sharedPreferences.getString(THEME_PREFERENCES_KEY, "");
|
||||
if (!themeJson.isEmpty()) {
|
||||
ThemePreferences themePreferences = new Gson().fromJson(themeJson, ThemePreferences.class);
|
||||
WritableMap themeMap = new Arguments().createMap();
|
||||
themeMap.putString("currentTheme", themePreferences.currentTheme);
|
||||
themeMap.putString("darkLevel", themePreferences.darkLevel);
|
||||
Bundle bundle = Arguments.toBundle(themeMap);
|
||||
mmkv.encode(THEME_PREFERENCES_KEY, bundle);
|
||||
}
|
||||
|
||||
// Sort preferences object
|
||||
String SORT_PREFS_KEY = "RC_SORT_PREFS_KEY";
|
||||
String sortJson = sharedPreferences.getString(SORT_PREFS_KEY, "");
|
||||
if (!sortJson.isEmpty()) {
|
||||
SortPreferences sortPreferences = new Gson().fromJson(sortJson, SortPreferences.class);
|
||||
WritableMap sortMap = new Arguments().createMap();
|
||||
sortMap.putString("sortBy", sortPreferences.sortBy);
|
||||
if (sortPreferences.groupByType != null) {
|
||||
sortMap.putBoolean("groupByType", sortPreferences.groupByType);
|
||||
}
|
||||
if (sortPreferences.showFavorites != null) {
|
||||
sortMap.putBoolean("showFavorites", sortPreferences.showFavorites);
|
||||
}
|
||||
if (sortPreferences.showUnread != null) {
|
||||
sortMap.putBoolean("showUnread", sortPreferences.showUnread);
|
||||
}
|
||||
Bundle bundle = Arguments.toBundle(sortMap);
|
||||
mmkv.encode(SORT_PREFS_KEY, bundle);
|
||||
}
|
||||
|
||||
// Remove all our keys of SharedPreferences
|
||||
sharedPreferences.edit().clear().commit();
|
||||
|
||||
// Mark migration complete
|
||||
defaultMMKV.encode("alreadyMigrated", true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,7 +2,6 @@ export const E2E_MESSAGE_TYPE = 'e2e';
|
|||
export const E2E_PUBLIC_KEY = 'RC_E2E_PUBLIC_KEY';
|
||||
export const E2E_PRIVATE_KEY = 'RC_E2E_PRIVATE_KEY';
|
||||
export const E2E_RANDOM_PASSWORD_KEY = 'RC_E2E_RANDOM_PASSWORD_KEY';
|
||||
export const E2E_REFRESH_MESSAGES_KEY = 'E2E_REFRESH_MESSAGES_KEY';
|
||||
export const E2E_STATUS = {
|
||||
PENDING: 'pending',
|
||||
DONE: 'done'
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import MMKVStorage from 'react-native-mmkv-storage';
|
||||
|
||||
import log from '../utils/log';
|
||||
|
||||
const MMKV = new MMKVStorage.Loader()
|
||||
// MODES.MULTI_PROCESS = ACCESSIBLE BY APP GROUP (iOS)
|
||||
.setProcessingMode(MMKVStorage.MODES.MULTI_PROCESS)
|
||||
|
@ -11,25 +9,6 @@ const MMKV = new MMKVStorage.Loader()
|
|||
class UserPreferences {
|
||||
constructor() {
|
||||
this.mmkv = MMKV;
|
||||
|
||||
this.encryptMigratedData();
|
||||
}
|
||||
|
||||
// It should run only once
|
||||
async encryptMigratedData() {
|
||||
try {
|
||||
const encryptMigration = await this.getBoolAsync('encryptMigration');
|
||||
|
||||
if (!encryptMigration) {
|
||||
// Encrypt the migrated data
|
||||
await this.mmkv.encryption.encrypt();
|
||||
|
||||
// Mark as completed
|
||||
await this.setBoolAsync('encryptMigration', true);
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
}
|
||||
|
||||
async getStringAsync(key) {
|
||||
|
|
|
@ -31,7 +31,6 @@ import UserPreferences from '../lib/userPreferences';
|
|||
|
||||
import { inquiryRequest, inquiryReset } from '../ee/omnichannel/actions/inquiry';
|
||||
import { isOmnichannelStatusAvailable } from '../ee/omnichannel/lib';
|
||||
import { E2E_REFRESH_MESSAGES_KEY } from '../lib/encryption/constants';
|
||||
import Navigation from '../lib/Navigation';
|
||||
|
||||
const getServer = state => state.server.server;
|
||||
|
@ -120,32 +119,7 @@ const fetchEnterpriseModules = function* fetchEnterpriseModules({ user }) {
|
|||
}
|
||||
};
|
||||
|
||||
const fetchRooms = function* fetchRooms({ server }) {
|
||||
try {
|
||||
// Read the flag to check if refresh was already done
|
||||
const refreshed = yield UserPreferences.getBoolAsync(E2E_REFRESH_MESSAGES_KEY);
|
||||
if (!refreshed) {
|
||||
const serversDB = database.servers;
|
||||
const serversCollection = serversDB.collections.get('servers');
|
||||
|
||||
const serverRecord = yield serversCollection.find(server);
|
||||
|
||||
// We need to reset roomsUpdatedAt to request all rooms again
|
||||
// and save their respective E2EKeys to decrypt all pending messages and lastMessage
|
||||
// that are already inserted on local database by other app version
|
||||
yield serversDB.action(async() => {
|
||||
await serverRecord.update((s) => {
|
||||
s.roomsUpdatedAt = null;
|
||||
});
|
||||
});
|
||||
|
||||
// Set the flag to indicate that already refreshed
|
||||
yield UserPreferences.setBoolAsync(E2E_REFRESH_MESSAGES_KEY, true);
|
||||
}
|
||||
} catch (e) {
|
||||
log(e);
|
||||
}
|
||||
|
||||
const fetchRooms = function* fetchRooms() {
|
||||
yield put(roomsRequest());
|
||||
};
|
||||
|
||||
|
@ -157,7 +131,7 @@ const handleLoginSuccess = function* handleLoginSuccess({ user }) {
|
|||
RocketChat.getUserPresence(user.id);
|
||||
|
||||
const server = yield select(getServer);
|
||||
yield fork(fetchRooms, { server });
|
||||
yield fork(fetchRooms);
|
||||
yield fork(fetchPermissions);
|
||||
yield fork(fetchCustomEmojis);
|
||||
yield fork(fetchRoles);
|
||||
|
|
|
@ -69,27 +69,6 @@ static void InitializeFlipper(UIApplication *application) {
|
|||
// AppGroup MMKV
|
||||
NSString *groupDir = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroup"]].path;
|
||||
[MMKV initializeMMKV:nil groupDir:groupDir logLevel:MMKVLogNone];
|
||||
|
||||
// Start the MMKV container
|
||||
MMKV *defaultMMKV = [MMKV mmkvWithID:@"migration" mode:MMKVMultiProcess];
|
||||
BOOL alreadyMigrated = [defaultMMKV getBoolForKey:@"alreadyMigrated"];
|
||||
|
||||
if (!alreadyMigrated) {
|
||||
// MMKV Instance that will be used by JS
|
||||
MMKV *mmkv = [MMKV mmkvWithID:@"default" mode:MMKVMultiProcess];
|
||||
|
||||
// NSUserDefaults -> MMKV (Migration)
|
||||
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"AppGroup"]];
|
||||
[mmkv migrateFromUserDefaults:userDefaults];
|
||||
|
||||
// Remove our own keys of NSUserDefaults
|
||||
for (NSString *key in [userDefaults dictionaryRepresentation].keyEnumerator) {
|
||||
[userDefaults removeObjectForKey:key];
|
||||
}
|
||||
|
||||
// Mark migration complete
|
||||
[defaultMMKV setBool:YES forKey:@"alreadyMigrated"];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue