From 645754674db5c5ebe86a0e7684c9094d11bbb893 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 14 Jan 2021 14:06:38 -0300 Subject: [PATCH] [CHORE] Remove some migrations (#2792) * Remove force rooms refresh * Remove MMKV migration --- .../chat/rocket/reactnative/MainActivity.java | 56 ------------------- app/lib/encryption/constants.js | 1 - app/lib/userPreferences.js | 21 ------- app/sagas/login.js | 30 +--------- ios/RocketChatRN/AppDelegate.m | 21 ------- 5 files changed, 2 insertions(+), 127 deletions(-) diff --git a/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java b/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java index 5eefab57..e65fc28b 100644 --- a/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java +++ b/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java @@ -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); - } } /** diff --git a/app/lib/encryption/constants.js b/app/lib/encryption/constants.js index 216746a7..d10539ed 100644 --- a/app/lib/encryption/constants.js +++ b/app/lib/encryption/constants.js @@ -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' diff --git a/app/lib/userPreferences.js b/app/lib/userPreferences.js index 633a5198..3377856d 100644 --- a/app/lib/userPreferences.js +++ b/app/lib/userPreferences.js @@ -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) { diff --git a/app/sagas/login.js b/app/sagas/login.js index 8b883a62..cf487eed 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -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); diff --git a/ios/RocketChatRN/AppDelegate.m b/ios/RocketChatRN/AppDelegate.m index a7e8be77..28fde17f 100644 --- a/ios/RocketChatRN/AppDelegate.m +++ b/ios/RocketChatRN/AppDelegate.m @@ -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; }