forked from Ivasoft/mattermost-mobile
* channels update on teamMate display name change
* code clean up
* fixes DM and GM display name
* code clean up
* ts fix
* removed extra await
* implemented some guard conditions
* code clean up
* config & license ws events - wip
* tested config change on local server
* adding license to the ws event
* fix display name
* fix display name
* replace map + filter with a reduce
* rename function name
* adding missing await
* update following review
* moved differsFromLocalNameFormat to /queries/preference
* fix gm/dm
* Revert "fix gm/dm"
This reverts commit 92905c707d.
* added guard clause on DM channel type
* refactor function signature
50 lines
1.8 KiB
TypeScript
50 lines
1.8 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {updateDmGmDisplayName} from '@actions/local/channel';
|
|
import {SYSTEM_IDENTIFIERS} from '@constants/database';
|
|
import DatabaseManager from '@database/manager';
|
|
import {getConfig, getLicense} from '@queries/servers/system';
|
|
|
|
export async function handleLicenseChangedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
|
|
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
|
if (!operator) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const license = msg.data.license;
|
|
const systems: IdValue[] = [{id: SYSTEM_IDENTIFIERS.LICENSE, value: JSON.stringify(license)}];
|
|
|
|
const prevLicense = await getLicense(operator.database);
|
|
await operator.handleSystem({systems, prepareRecordsOnly: false});
|
|
|
|
if (license?.LockTeammateNameDisplay && (prevLicense?.LockTeammateNameDisplay !== license.LockTeammateNameDisplay)) {
|
|
updateDmGmDisplayName(serverUrl);
|
|
}
|
|
} catch {
|
|
// do nothing
|
|
}
|
|
}
|
|
|
|
export async function handleConfigChangedEvent(serverUrl: string, msg: WebSocketMessage): Promise<void> {
|
|
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
|
if (!operator) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const config = msg.data.config;
|
|
const systems: IdValue[] = [{id: SYSTEM_IDENTIFIERS.CONFIG, value: JSON.stringify(config)}];
|
|
|
|
const prevConfig = await getConfig(operator.database);
|
|
await operator.handleSystem({systems, prepareRecordsOnly: false});
|
|
if (config?.LockTeammateNameDisplay && (prevConfig?.LockTeammateNameDisplay !== config.LockTeammateNameDisplay)) {
|
|
updateDmGmDisplayName(serverUrl);
|
|
}
|
|
} catch {
|
|
// do nothing
|
|
}
|
|
}
|
|
|