Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import com.zoontek.rnbootsplash.RNBootSplash;
import com.tencent.mmkv.MMKV;
import com.google.gson.Gson;

class ThemePreferences {
Expand All @@ -36,61 +35,6 @@ protected void onCreate(Bundle savedInstanceState) {
// 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);
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion app/lib/encryption/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
21 changes: 0 additions & 21 deletions app/lib/userPreferences.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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) {
Expand Down
30 changes: 2 additions & 28 deletions app/sagas/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
};

Expand All @@ -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);
Expand Down
21 changes: 0 additions & 21 deletions ios/RocketChatRN/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// 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;
}
Expand Down