diff --git a/app/constants/database.ts b/app/constants/database.ts index 000c7d8384..bbb0f9bca6 100644 --- a/app/constants/database.ts +++ b/app/constants/database.ts @@ -52,7 +52,6 @@ export const MIGRATION_EVENTS = keyMirror({ }); export const SYSTEM_IDENTIFIERS = { - CONFIG: 'config', CURRENT_CHANNEL_ID: 'currentChannelId', LAST_UNREAD_CHANNEL_ID: 'lastUnreadChannelId', CURRENT_TEAM_ID: 'currentTeamId', diff --git a/app/database/manager/index.ts b/app/database/manager/index.ts index 37851837ff..93eed0b393 100644 --- a/app/database/manager/index.ts +++ b/app/database/manager/index.ts @@ -8,7 +8,7 @@ import {DeviceEventEmitter, Platform} from 'react-native'; import DeviceInfo from 'react-native-device-info'; import FileSystem from 'react-native-fs'; -import {DatabaseType, MIGRATION_EVENTS, MM_TABLES, SYSTEM_IDENTIFIERS} from '@constants/database'; +import {DatabaseType, MIGRATION_EVENTS, MM_TABLES} from '@constants/database'; import AppDatabaseMigrations from '@database/migration/app'; import ServerDatabaseMigrations from '@database/migration/server'; import {InfoModel, GlobalModel, ServersModel} from '@database/models/app'; @@ -24,12 +24,10 @@ import {schema as appSchema} from '@database/schema/app'; import {serverSchema} from '@database/schema/server'; import {beforeUpgrade} from '@helpers/database/upgrade'; import {getActiveServer, getServer, getServerByIdentifier} from '@queries/app/servers'; -import {querySystemValue} from '@queries/servers/system'; -import {deleteLegacyFileCache} from '@utils/file'; import {emptyFunction} from '@utils/general'; import {logDebug, logError} from '@utils/log'; import {deleteIOSDatabase, getIOSAppGroupDetails, renameIOSDatabase} from '@utils/mattermost_managed'; -import {hashCode_DEPRECATED, urlSafeBase64Encode} from '@utils/security'; +import {urlSafeBase64Encode} from '@utils/security'; import {removeProtocol} from '@utils/url'; import type {AppDatabase, CreateServerDatabaseArgs, RegisterServerDatabaseArgs, Models, ServerDatabase, ServerDatabases} from '@typings/database/database'; @@ -133,12 +131,6 @@ class DatabaseManager { if (serverUrl) { try { const databaseName = urlSafeBase64Encode(serverUrl); - const oldDatabaseName = hashCode_DEPRECATED(serverUrl); - - // Remove any legacy database we may already have. - await this.renameDatabase(oldDatabaseName, databaseName); - deleteLegacyFileCache(serverUrl); - const databaseFilePath = this.getDatabaseFilePath(databaseName); const migrations = ServerDatabaseMigrations; const modelClasses = this.serverModels; @@ -181,38 +173,13 @@ class DatabaseManager { * @returns {Promise} */ private initServerDatabase = async (serverUrl: string): Promise => { - const serverDatabase = await this.createServerDatabase({ + await this.createServerDatabase({ config: { dbName: serverUrl, dbType: DatabaseType.SERVER, serverUrl, }, }); - - // Migration for config - if (serverDatabase) { - const {database, operator} = serverDatabase; - const oldConfigList = await querySystemValue(database, SYSTEM_IDENTIFIERS.CONFIG).fetch(); - if (oldConfigList.length) { - const oldConfigModel = oldConfigList[0]; - const oldConfig = oldConfigModel.value as ClientConfig; - - const configs = []; - let k: keyof ClientConfig; - for (k in oldConfig) { - // Check to silence eslint (guard-for-in) - if (Object.prototype.hasOwnProperty.call(oldConfig, k)) { - configs.push({ - id: k, - value: oldConfig[k], - }); - } - } - const models = await operator.handleConfigs({configs, configsToDelete: [], prepareRecordsOnly: true}); - - operator.batchRecords([...models, oldConfigModel.prepareDestroyPermanently()]); - } - } }; /** diff --git a/app/utils/file/index.ts b/app/utils/file/index.ts index fdab1e8bfd..348a156181 100644 --- a/app/utils/file/index.ts +++ b/app/utils/file/index.ts @@ -18,7 +18,7 @@ import {generateId} from '@utils/general'; import keyMirror from '@utils/key_mirror'; import {logError} from '@utils/log'; import {deleteEntititesFile, getIOSAppGroupDetails} from '@utils/mattermost_managed'; -import {hashCode_DEPRECATED, urlSafeBase64Encode} from '@utils/security'; +import {urlSafeBase64Encode} from '@utils/security'; import type FileModel from '@typings/database/models/servers/file'; @@ -169,11 +169,6 @@ export async function deleteFileCache(serverUrl: string) { return deleteFileCacheByDir(serverDir); } -export async function deleteLegacyFileCache(serverUrl: string) { - const serverDir = hashCode_DEPRECATED(serverUrl); - return deleteFileCacheByDir(serverDir); -} - export async function deleteFileCacheByDir(dir: string) { if (Platform.OS === 'ios') { const appGroupCacheDir = `${getIOSAppGroupDetails().appGroupSharedDirectory}/Library/Caches/${dir}`; diff --git a/app/utils/security.ts b/app/utils/security.ts index 03a32bb1a4..981579c50e 100644 --- a/app/utils/security.ts +++ b/app/utils/security.ts @@ -9,23 +9,6 @@ export async function getCSRFFromCookie(url: string) { return cookies.MMCSRF?.value; } -// This has been deprecated and is only used for migrations -export const hashCode_DEPRECATED = (str: string): string => { - let hash = 0; - let i; - let chr; - if (!str || str.length === 0) { - return hash.toString(); - } - - for (i = 0; i < str.length; i++) { - chr = str.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; - hash |= 0; // Convert to 32bit integer - } - return hash.toString(); -}; - export const urlSafeBase64Encode = (str: string): string => { return base64.encode(str).replace(/\+/g, '-').replace(/\//g, '_'); };