mirror of
https://github.com/mattermost/mattermost-mobile.git
synced 2026-11-04 09:58:57 +00:00
* [MM-67923] Add channel settings for shared channels * Fix toggle and tests * Address client types * Add failure state to channel share screen * Better handle errors on save * Remove unneeded database fetch inside the component * Fix i18n * Disable interactions while saving * Fix test * Address coderabbit comments * Add e2e tests * Address feedback * Address codeRabbit comments * Update detox/e2e/test/products/channels/channel_settings/share_with_connected_workspaces.e2e.ts Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Address comments * Address coderabbit comments * Address reviews and several UI defects * Fix tests --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {toMilliseconds} from '@utils/datetime';
|
|
|
|
const SITE_URL_PENDING_PREFIX = 'pending_';
|
|
const CONNECTED_PING_THRESHOLD_MS = toMilliseconds({minutes: 5});
|
|
|
|
export type RemoteConnectionInfo = {
|
|
site_url?: string;
|
|
last_ping_at: number;
|
|
};
|
|
|
|
export function isRemoteClusterConfirmed(rc: RemoteConnectionInfo): boolean {
|
|
return Boolean(rc.site_url && !rc.site_url.startsWith(SITE_URL_PENDING_PREFIX));
|
|
}
|
|
|
|
export function isRemoteClusterConnected(rc: RemoteConnectionInfo): boolean {
|
|
if (!rc.last_ping_at) {
|
|
return false;
|
|
}
|
|
return (Date.now() - rc.last_ping_at) <= CONNECTED_PING_THRESHOLD_MS;
|
|
}
|
|
|
|
export type RemoteConnectionStatus = 'connection_pending' | 'connected' | 'offline';
|
|
|
|
export function getRemoteClusterConnectionStatus(rc: RemoteConnectionInfo): RemoteConnectionStatus {
|
|
if (!isRemoteClusterConfirmed(rc)) {
|
|
return 'connection_pending';
|
|
}
|
|
return isRemoteClusterConnected(rc) ? 'connected' : 'offline';
|
|
}
|
|
|
|
export type ConnectionStatus = 'pending_save' | 'connection_pending' | 'connected' | 'offline';
|
|
|
|
export type WorkspaceWithStatus = RemoteConnectionInfo & {
|
|
pendingSave?: boolean;
|
|
};
|
|
|
|
export function getConnectionStatus(w: WorkspaceWithStatus): ConnectionStatus {
|
|
if (w.pendingSave) {
|
|
return 'pending_save';
|
|
}
|
|
return getRemoteClusterConnectionStatus(w);
|
|
}
|