mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-11 05:30:12 +00:00
* implements auto cache cleanup when zero persistence mode is enabled (0 value)
* uses memory flag with sqlite instead of loki when running in zero persistence mode
* renames ephemeral mode manager and improves readability
* zero persistence refactors and restore values during transitions
* fixes ephemeral mode tests
* use initializeClient instead of just initialize to wait for doReconnect to finish
that way teams loading is awaited while WS reconnects during ZPM transitions
* adds inital sync as a mount hook to prevent undesired load error states
during app cold start in ZPM mode, we need a way to load team and channels
without showing loading error during the transition. The nre is initial sync
hook allows for it
* reset started sync subject on wipe
* removes extra log lines
* resets tracked server during ephemeral mode transitions
* improvements to apply persistence mode changes when something fails
* address coderabbit PR suggestions
* add batching time logging
* throws ephemeral mode change error as is
* make deleteServerDatabaseFiles private
* inline derive persistence flag function
* return current user id when refetching current user
* support zero persistence mode server for push notifications
* adds support for zero persistence mode when sharing to mattermost
* adds clarifying comment
* catch and log error deleting files
* reorder translations to correct position
* adds some new tests to improve coverage
* ios push notification native fix
* logout when fetchMe fails with 401 status code during reconnection
* properly surface errors
* return proper false value when checking for zero persistence flag
* change comments and properly await on some operations
* prevent not set persistence mode to report as an error
* include servers with no persistence flag set in share list
* disable button for accessibility
* improves when to store and remove signing key from global area
* review push notification reception running in zero persistence mode
* add server to ephemeral mode manager right after login
---------
(cherry picked from commit a5ff8a0d95)
Co-authored-by: Carlos Garcia <carlos.garcia@mattermost.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
178 lines
5.9 KiB
TypeScript
178 lines
5.9 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {updateDmGmDisplayName} from '@actions/local/channel';
|
|
import {reconcilePersistenceFlag} from '@actions/local/ephemeral_mode/wipe';
|
|
import {storeConfig} from '@actions/local/systems';
|
|
import {SYSTEM_IDENTIFIERS} from '@constants/database';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getConfig, getLicense} from '@queries/servers/system';
|
|
|
|
import {handleLicenseChangedEvent, handleConfigChangedEvent} from './system';
|
|
|
|
import type ServerDataOperator from '@database/operator/server_data_operator';
|
|
|
|
jest.mock('@actions/local/channel');
|
|
jest.mock('@actions/local/ephemeral_mode/wipe');
|
|
jest.mock('@actions/local/systems');
|
|
jest.mock('@database/manager');
|
|
jest.mock('@queries/servers/system');
|
|
|
|
describe('WebSocket System Actions', () => {
|
|
const serverUrl = 'baseHandler.test.com';
|
|
|
|
let operator: ServerDataOperator;
|
|
let handleSystem: jest.SpyInstance;
|
|
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks();
|
|
|
|
await DatabaseManager.init([serverUrl]);
|
|
operator = DatabaseManager.serverDatabases[serverUrl]!.operator;
|
|
handleSystem = jest.spyOn(operator, 'handleSystem');
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await DatabaseManager.destroyServerDatabase(serverUrl);
|
|
jest.restoreAllMocks();
|
|
});
|
|
|
|
describe('handleLicenseChangedEvent', () => {
|
|
it('should handle missing operator', async () => {
|
|
DatabaseManager.serverDatabases = {};
|
|
const msg = {
|
|
data: {
|
|
license: {
|
|
LockTeammateNameDisplay: true,
|
|
},
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleLicenseChangedEvent(serverUrl, msg);
|
|
expect(handleSystem).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle license update with no display name change', async () => {
|
|
const mockLicense = {
|
|
LockTeammateNameDisplay: false,
|
|
};
|
|
|
|
jest.mocked(getLicense).mockResolvedValue({
|
|
LockTeammateNameDisplay: 'false',
|
|
} as ClientLicense);
|
|
|
|
const msg = {
|
|
data: {
|
|
license: mockLicense,
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleLicenseChangedEvent(serverUrl, msg);
|
|
|
|
expect(handleSystem).toHaveBeenCalledWith({
|
|
systems: [{
|
|
id: SYSTEM_IDENTIFIERS.LICENSE,
|
|
value: JSON.stringify(mockLicense),
|
|
}],
|
|
prepareRecordsOnly: false,
|
|
});
|
|
expect(updateDmGmDisplayName).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle license update with display name change', async () => {
|
|
const mockLicense = {
|
|
LockTeammateNameDisplay: true,
|
|
};
|
|
|
|
jest.mocked(getLicense).mockResolvedValue({
|
|
LockTeammateNameDisplay: 'false',
|
|
} as ClientLicense);
|
|
|
|
const msg = {
|
|
data: {
|
|
license: mockLicense,
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleLicenseChangedEvent(serverUrl, msg);
|
|
|
|
expect(handleSystem).toHaveBeenCalled();
|
|
expect(updateDmGmDisplayName).toHaveBeenCalledWith(serverUrl);
|
|
});
|
|
});
|
|
|
|
describe('handleConfigChangedEvent', () => {
|
|
it('should handle missing operator', async () => {
|
|
DatabaseManager.serverDatabases = {};
|
|
const msg = {
|
|
data: {
|
|
config: {
|
|
LockTeammateNameDisplay: true,
|
|
},
|
|
},
|
|
} as WebSocketMessage;
|
|
await handleConfigChangedEvent(serverUrl, msg);
|
|
expect(storeConfig).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle config update with no display name change', async () => {
|
|
const mockConfig = {
|
|
LockTeammateNameDisplay: false,
|
|
};
|
|
|
|
jest.mocked(getConfig).mockResolvedValue({
|
|
LockTeammateNameDisplay: 'false',
|
|
} as ClientConfig);
|
|
|
|
const msg = {
|
|
data: {
|
|
config: mockConfig,
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleConfigChangedEvent(serverUrl, msg);
|
|
|
|
expect(storeConfig).toHaveBeenCalledWith(serverUrl, mockConfig);
|
|
expect(updateDmGmDisplayName).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should handle config update with display name change', async () => {
|
|
const mockConfig = {
|
|
LockTeammateNameDisplay: true,
|
|
};
|
|
|
|
jest.mocked(getConfig).mockResolvedValue({
|
|
LockTeammateNameDisplay: 'false',
|
|
} as ClientConfig);
|
|
|
|
const msg = {
|
|
data: {
|
|
config: mockConfig,
|
|
},
|
|
} as WebSocketMessage;
|
|
|
|
await handleConfigChangedEvent(serverUrl, msg);
|
|
|
|
expect(storeConfig).toHaveBeenCalledWith(serverUrl, mockConfig);
|
|
expect(updateDmGmDisplayName).toHaveBeenCalledWith(serverUrl);
|
|
});
|
|
|
|
it('should reconcile the persistence flag against the new config so a live MEM-cleanup change clears zero-persistence', async () => {
|
|
const mockConfig = {
|
|
MobileEphemeralModeEnabled: 'true',
|
|
MobileEphemeralModeAutoCacheCleanupDays: '5',
|
|
};
|
|
|
|
jest.mocked(getConfig).mockResolvedValue({
|
|
MobileEphemeralModeEnabled: 'true',
|
|
MobileEphemeralModeAutoCacheCleanupDays: '0',
|
|
} as ClientConfig);
|
|
|
|
const msg = {data: {config: mockConfig}} as WebSocketMessage;
|
|
|
|
await handleConfigChangedEvent(serverUrl, msg);
|
|
|
|
expect(reconcilePersistenceFlag).toHaveBeenCalledWith(serverUrl, mockConfig);
|
|
});
|
|
});
|
|
});
|