mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-09 04:30:14 +00:00
* auto cache rolling cleanup for posts * ai threads rolling cleanup * auto rolling cleanup of playbook runs * fix to import and use renamed module * makes post cleanup atomic by moving processing to sql layer * restore previous file viewer post id and use full error logging * performs vacuum as last step and removes unused code * return early on empty channel array * address gallery items without a post id * prevent drafts to be deleted as part of auto cache cleanups * unset channel oldest visible on channel switch * clear oldest visible on empty array * revert early return to prevent flickering * restore previous playbookrun id on unmount * fixes issue creating data retention deletion batches * move active threads root cleanup protection to SQL execution * notify observers of range changes in post lists * in flight protection for auto cache cleanup runs * add space around operator Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * show warnings as snackbars related to ephemeral mode settings snackbar can now be persistent for some warnings requiring the user to acknowledge reading the message by manually dismissing it. * adds warnings when mobile ephemeral mode settings change snackbar component has been augmented to show user dismissable messages that require user interaction and to support longer messages with title and description. A header icon continuously show when ephemeral mode or zero persistence is enabled for a particular server. * fix i18n * renders snackbar properly when changing from persistent to ephemeral versions * reset visibility for tooltip when ephemeral mode config changes * show ephemeral mode warnings only for active server * renames added tests to start with should... * guards against a race casing to wipe an untracked server * enqueue ephemeral mode config changes so wipe operations don't race * auto cache cleanup warning shows only for active server * shows snackbar instead of tooltip on ephemeral mode icon tap * drops virtual set to true from jest mocks of real modules this was causing some flaky tests that failed depending on ordering while running in CI. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
102 lines
4.7 KiB
TypeScript
102 lines
4.7 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {wipeServerDatabaseWithRetry, wipeServerFiles} from '@actions/local/ephemeral_mode/wipe';
|
|
import {cancelSessionNotification, terminateSession} from '@actions/local/session';
|
|
import {SNACK_BAR_TYPE} from '@constants/snack_bar';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getServerCredentials} from '@init/credentials';
|
|
import EphemeralModeManager from '@managers/ephemeral_mode_manager';
|
|
import WebsocketManager from '@managers/websocket_manager';
|
|
import {getCurrentChannelId, getCurrentTeamId, getPushVerificationStatus, prepareCommonSystemValues} from '@queries/servers/system';
|
|
import {getFullErrorMessage} from '@utils/errors';
|
|
import {logError, logWarning} from '@utils/log';
|
|
import {showSnackBar} from '@utils/snack_bar';
|
|
|
|
import {refetchCurrentUser} from './user';
|
|
|
|
export const applyPersistenceModeChange = async (serverUrl: string): Promise<{error?: unknown}> => {
|
|
let resumeServerTracking = true;
|
|
try {
|
|
// untrack server during the transition
|
|
EphemeralModeManager.removeServer(serverUrl);
|
|
|
|
const credentials = await getServerCredentials(serverUrl);
|
|
const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
|
|
|
// Snapshot SYSTEM values that the WS reconnect won't restore on its own so the post-wipe
|
|
// UI doesn't show a regressed state (push-proxy red alert, team-select screen flash, etc).
|
|
const previousPushVerificationStatus = await getPushVerificationStatus(database);
|
|
const previousCurrentTeamId = await getCurrentTeamId(database);
|
|
const previousCurrentChannelId = await getCurrentChannelId(database);
|
|
|
|
try {
|
|
await cancelSessionNotification(serverUrl);
|
|
} catch {
|
|
logWarning('applyPersistenceModeChange: cancelSessionNotification failed (non-critical)');
|
|
}
|
|
|
|
await WebsocketManager.invalidateClient(serverUrl);
|
|
const {success} = await wipeServerDatabaseWithRetry(serverUrl);
|
|
if (!success) {
|
|
throw new Error('Failed to wipe server database after changing persistence mode');
|
|
}
|
|
|
|
wipeServerFiles(serverUrl);
|
|
|
|
const {error: refetchError} = await refetchCurrentUser(serverUrl, undefined);
|
|
if (refetchError) {
|
|
throw new Error(`applyPersistenceModeChange: failed to seed current user: ${getFullErrorMessage(refetchError)}`);
|
|
}
|
|
|
|
const {operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
|
const systemModels = await prepareCommonSystemValues(operator, {
|
|
currentPushVerificationStatus: previousPushVerificationStatus,
|
|
currentTeamId: previousCurrentTeamId,
|
|
currentChannelId: previousCurrentChannelId,
|
|
});
|
|
|
|
if (systemModels?.length) {
|
|
await operator.batchRecords(systemModels, 'applyPersistenceModeChange');
|
|
}
|
|
|
|
if (credentials?.token) {
|
|
await WebsocketManager.createClient(serverUrl, credentials.token, credentials.preauthSecret);
|
|
await WebsocketManager.initializeClient(serverUrl);
|
|
}
|
|
|
|
// Touch lastActiveAt so withServerDatabase re-reads the newly-created database instance.
|
|
// Only needed (and safe) for the active server
|
|
const activeServerUrl = await DatabaseManager.getActiveServerUrl();
|
|
if (activeServerUrl === serverUrl) {
|
|
await DatabaseManager.setActiveServerDatabase(serverUrl);
|
|
}
|
|
|
|
return {};
|
|
} catch (error) {
|
|
logError('applyPersistenceModeChange', serverUrl, getFullErrorMessage(error));
|
|
const {error: logoutError} = await terminateSession(serverUrl, false);
|
|
if (logoutError) {
|
|
logError('applyPersistenceModeChange: terminateSession failed', serverUrl, getFullErrorMessage(logoutError));
|
|
} else {
|
|
// do not resume server tracking in case of session termination
|
|
resumeServerTracking = false;
|
|
}
|
|
|
|
return {error};
|
|
} finally {
|
|
if (resumeServerTracking) {
|
|
// restart tracking; file cache was already wiped during the transition
|
|
await EphemeralModeManager.addServer(serverUrl, {cleanFileCache: false});
|
|
|
|
// Notify the user post-remount so the persistent banner survives the withServerDatabase key flip.
|
|
const activeServerUrl = await DatabaseManager.getActiveServerUrl();
|
|
const isActive = activeServerUrl === serverUrl;
|
|
const isZpm = EphemeralModeManager.isZeroPersistenceMode(serverUrl);
|
|
if (isActive && isZpm) {
|
|
showSnackBar({barType: SNACK_BAR_TYPE.EPHEMERAL_MODE_ZERO_PERSISTENCE_ACTIVE});
|
|
}
|
|
}
|
|
}
|
|
};
|