2022-01-12 17:35:47 +00:00
|
|
|
// Copyright 2019-2022 Signal Messenger, LLC
|
2020-10-30 20:34:04 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-12 23:59:08 +00:00
|
|
|
import React, { useEffect, useCallback, useMemo, useState } from 'react';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { MeasuredComponentProps } from 'react-measure';
|
|
|
|
import Measure from 'react-measure';
|
2021-10-12 23:59:08 +00:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import { clamp, isNumber, noop } from 'lodash';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { LeftPaneHelper, ToFindType } from './leftPane/LeftPaneHelper';
|
|
|
|
import { FindDirection } from './leftPane/LeftPaneHelper';
|
|
|
|
import type { LeftPaneInboxPropsType } from './leftPane/LeftPaneInboxHelper';
|
|
|
|
import { LeftPaneInboxHelper } from './leftPane/LeftPaneInboxHelper';
|
|
|
|
import type { LeftPaneSearchPropsType } from './leftPane/LeftPaneSearchHelper';
|
|
|
|
import { LeftPaneSearchHelper } from './leftPane/LeftPaneSearchHelper';
|
|
|
|
import type { LeftPaneArchivePropsType } from './leftPane/LeftPaneArchiveHelper';
|
|
|
|
import { LeftPaneArchiveHelper } from './leftPane/LeftPaneArchiveHelper';
|
|
|
|
import type { LeftPaneComposePropsType } from './leftPane/LeftPaneComposeHelper';
|
|
|
|
import { LeftPaneComposeHelper } from './leftPane/LeftPaneComposeHelper';
|
|
|
|
import type { LeftPaneChooseGroupMembersPropsType } from './leftPane/LeftPaneChooseGroupMembersHelper';
|
|
|
|
import { LeftPaneChooseGroupMembersHelper } from './leftPane/LeftPaneChooseGroupMembersHelper';
|
|
|
|
import type { LeftPaneSetGroupMetadataPropsType } from './leftPane/LeftPaneSetGroupMetadataHelper';
|
|
|
|
import { LeftPaneSetGroupMetadataHelper } from './leftPane/LeftPaneSetGroupMetadataHelper';
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
import * as OS from '../OS';
|
2021-11-02 23:01:13 +00:00
|
|
|
import type { LocalizerType, ThemeType } from '../types/Util';
|
2021-10-26 19:15:33 +00:00
|
|
|
import { ScrollBehavior } from '../types/Util';
|
2021-11-17 21:11:21 +00:00
|
|
|
import type { PreferredBadgeSelectorType } from '../state/selectors/badges';
|
2021-09-17 22:24:21 +00:00
|
|
|
import { usePrevious } from '../hooks/usePrevious';
|
2021-02-23 20:34:28 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2022-11-16 20:18:02 +00:00
|
|
|
import type { DurationInSeconds } from '../util/durations';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { WidthBreakpoint } from './_util';
|
|
|
|
import { getConversationListWidthBreakpoint } from './_util';
|
2022-03-31 05:58:28 +00:00
|
|
|
import * as KeyboardLayout from '../services/keyboardLayout';
|
2022-03-04 21:14:52 +00:00
|
|
|
import {
|
|
|
|
MIN_WIDTH,
|
|
|
|
SNAP_WIDTH,
|
|
|
|
MIN_FULL_WIDTH,
|
|
|
|
MAX_WIDTH,
|
|
|
|
getWidthFromPreferredWidth,
|
|
|
|
} from '../util/leftPaneWidth';
|
2022-04-05 00:38:22 +00:00
|
|
|
import type { LookupConversationWithoutUuidActionsType } from '../util/lookupConversationWithoutUuid';
|
2022-06-16 19:12:50 +00:00
|
|
|
import type { ShowConversationType } from '../state/ducks/conversations';
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
import { ConversationList } from './ConversationList';
|
2021-03-03 20:09:58 +00:00
|
|
|
import { ContactCheckboxDisabledReason } from './conversationList/ContactCheckbox';
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type {
|
2021-08-06 00:17:05 +00:00
|
|
|
DeleteAvatarFromDiskActionType,
|
|
|
|
ReplaceAvatarActionType,
|
|
|
|
SaveAvatarToDiskActionType,
|
|
|
|
} from '../types/Avatar';
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
export enum LeftPaneMode {
|
|
|
|
Inbox,
|
|
|
|
Search,
|
|
|
|
Archive,
|
|
|
|
Compose,
|
2021-03-03 20:09:58 +00:00
|
|
|
ChooseGroupMembers,
|
|
|
|
SetGroupMetadata,
|
2021-02-23 20:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export type PropsType = {
|
|
|
|
// These help prevent invalid states. For example, we don't need the list of pinned
|
|
|
|
// conversations if we're trying to start a new conversation. Ideally these would be
|
|
|
|
// at the top level, but this is not supported by react-redux + TypeScript.
|
|
|
|
modeSpecificProps:
|
|
|
|
| ({
|
|
|
|
mode: LeftPaneMode.Inbox;
|
|
|
|
} & LeftPaneInboxPropsType)
|
|
|
|
| ({
|
|
|
|
mode: LeftPaneMode.Search;
|
|
|
|
} & LeftPaneSearchPropsType)
|
|
|
|
| ({
|
|
|
|
mode: LeftPaneMode.Archive;
|
|
|
|
} & LeftPaneArchivePropsType)
|
|
|
|
| ({
|
|
|
|
mode: LeftPaneMode.Compose;
|
2021-03-03 20:09:58 +00:00
|
|
|
} & LeftPaneComposePropsType)
|
|
|
|
| ({
|
|
|
|
mode: LeftPaneMode.ChooseGroupMembers;
|
|
|
|
} & LeftPaneChooseGroupMembersPropsType)
|
|
|
|
| ({
|
|
|
|
mode: LeftPaneMode.SetGroupMetadata;
|
|
|
|
} & LeftPaneSetGroupMetadataPropsType);
|
2021-11-17 21:11:21 +00:00
|
|
|
getPreferredBadge: PreferredBadgeSelectorType;
|
2019-01-14 21:49:58 +00:00
|
|
|
i18n: LocalizerType;
|
2021-10-12 23:59:08 +00:00
|
|
|
preferredWidthFromStorage: number;
|
2021-02-23 20:34:28 +00:00
|
|
|
selectedConversationId: undefined | string;
|
|
|
|
selectedMessageId: undefined | string;
|
2022-02-23 18:48:40 +00:00
|
|
|
regionCode: string | undefined;
|
2021-05-06 00:09:29 +00:00
|
|
|
challengeStatus: 'idle' | 'required' | 'pending';
|
|
|
|
setChallengeStatus: (status: 'idle') => void;
|
2022-01-11 20:02:46 +00:00
|
|
|
crashReportCount: number;
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: ThemeType;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// Action Creators
|
2022-01-27 22:12:26 +00:00
|
|
|
clearConversationSearch: () => void;
|
2021-03-03 20:09:58 +00:00
|
|
|
clearGroupCreationError: () => void;
|
2021-11-01 18:43:02 +00:00
|
|
|
clearSearch: () => void;
|
2021-03-03 20:09:58 +00:00
|
|
|
closeMaximumGroupSizeModal: () => void;
|
|
|
|
closeRecommendedGroupSizeModal: () => void;
|
2022-06-16 19:12:50 +00:00
|
|
|
composeDeleteAvatarFromDisk: DeleteAvatarFromDiskActionType;
|
|
|
|
composeReplaceAvatar: ReplaceAvatarActionType;
|
|
|
|
composeSaveAvatarToDisk: SaveAvatarToDiskActionType;
|
2021-03-03 20:09:58 +00:00
|
|
|
createGroup: () => void;
|
2021-10-12 23:59:08 +00:00
|
|
|
savePreferredLeftPaneWidth: (_: number) => void;
|
2021-11-01 18:43:02 +00:00
|
|
|
searchInConversation: (conversationId: string) => unknown;
|
2021-09-24 00:49:05 +00:00
|
|
|
setComposeGroupAvatar: (_: undefined | Uint8Array) => void;
|
2022-11-16 20:18:02 +00:00
|
|
|
setComposeGroupExpireTimer: (_: DurationInSeconds) => void;
|
2022-06-16 19:12:50 +00:00
|
|
|
setComposeGroupName: (_: string) => void;
|
|
|
|
setComposeSearchTerm: (composeSearchTerm: string) => void;
|
2019-03-12 00:20:16 +00:00
|
|
|
showArchivedConversations: () => void;
|
2022-06-16 19:12:50 +00:00
|
|
|
showChooseGroupMembers: () => void;
|
|
|
|
showConversation: ShowConversationType;
|
2019-03-12 00:20:16 +00:00
|
|
|
showInbox: () => void;
|
2021-02-23 20:34:28 +00:00
|
|
|
startComposing: () => void;
|
2021-11-01 18:43:02 +00:00
|
|
|
startSearch: () => unknown;
|
2021-03-03 20:09:58 +00:00
|
|
|
startSettingGroupMetadata: () => void;
|
2021-08-06 00:17:05 +00:00
|
|
|
toggleComposeEditingAvatar: () => unknown;
|
2022-06-16 19:12:50 +00:00
|
|
|
toggleConversationInChooseMembers: (conversationId: string) => void;
|
2021-11-01 18:43:02 +00:00
|
|
|
updateSearchTerm: (_: string) => void;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
|
|
|
// Render Props
|
2021-10-12 23:59:08 +00:00
|
|
|
renderExpiredBuildDialog: (
|
|
|
|
_: Readonly<{ containerWidthBreakpoint: WidthBreakpoint }>
|
|
|
|
) => JSX.Element;
|
2019-01-14 21:49:58 +00:00
|
|
|
renderMainHeader: () => JSX.Element;
|
2021-08-11 16:23:21 +00:00
|
|
|
renderMessageSearchResult: (id: string) => JSX.Element;
|
2021-10-12 23:59:08 +00:00
|
|
|
renderNetworkStatus: (
|
|
|
|
_: Readonly<{ containerWidthBreakpoint: WidthBreakpoint }>
|
|
|
|
) => JSX.Element;
|
|
|
|
renderRelinkDialog: (
|
|
|
|
_: Readonly<{ containerWidthBreakpoint: WidthBreakpoint }>
|
|
|
|
) => JSX.Element;
|
|
|
|
renderUpdateDialog: (
|
|
|
|
_: Readonly<{ containerWidthBreakpoint: WidthBreakpoint }>
|
|
|
|
) => JSX.Element;
|
2021-05-06 00:09:29 +00:00
|
|
|
renderCaptchaDialog: (props: { onSkip(): void }) => JSX.Element;
|
2022-01-11 20:02:46 +00:00
|
|
|
renderCrashReportDialog: () => JSX.Element;
|
2022-04-05 00:38:22 +00:00
|
|
|
} & LookupConversationWithoutUuidActionsType;
|
2019-01-14 21:49:58 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function LeftPane({
|
2021-08-06 00:17:05 +00:00
|
|
|
challengeStatus,
|
2022-01-11 20:02:46 +00:00
|
|
|
crashReportCount,
|
2022-01-27 22:12:26 +00:00
|
|
|
clearConversationSearch,
|
2021-03-03 20:09:58 +00:00
|
|
|
clearGroupCreationError,
|
2021-11-01 18:43:02 +00:00
|
|
|
clearSearch,
|
2021-03-03 20:09:58 +00:00
|
|
|
closeMaximumGroupSizeModal,
|
|
|
|
closeRecommendedGroupSizeModal,
|
2021-08-06 00:17:05 +00:00
|
|
|
composeDeleteAvatarFromDisk,
|
|
|
|
composeReplaceAvatar,
|
|
|
|
composeSaveAvatarToDisk,
|
2021-03-03 20:09:58 +00:00
|
|
|
createGroup,
|
2021-11-17 21:11:21 +00:00
|
|
|
getPreferredBadge,
|
2021-02-23 20:34:28 +00:00
|
|
|
i18n,
|
|
|
|
modeSpecificProps,
|
2021-10-12 23:59:08 +00:00
|
|
|
preferredWidthFromStorage,
|
2021-08-06 00:17:05 +00:00
|
|
|
renderCaptchaDialog,
|
2022-01-11 20:02:46 +00:00
|
|
|
renderCrashReportDialog,
|
2021-02-23 20:34:28 +00:00
|
|
|
renderExpiredBuildDialog,
|
|
|
|
renderMainHeader,
|
|
|
|
renderMessageSearchResult,
|
|
|
|
renderNetworkStatus,
|
|
|
|
renderRelinkDialog,
|
|
|
|
renderUpdateDialog,
|
2021-10-12 23:59:08 +00:00
|
|
|
savePreferredLeftPaneWidth,
|
2021-11-01 18:43:02 +00:00
|
|
|
searchInConversation,
|
2021-02-23 20:34:28 +00:00
|
|
|
selectedConversationId,
|
|
|
|
selectedMessageId,
|
2021-08-06 00:17:05 +00:00
|
|
|
setChallengeStatus,
|
2021-03-03 20:09:58 +00:00
|
|
|
setComposeGroupAvatar,
|
2021-06-25 23:52:56 +00:00
|
|
|
setComposeGroupExpireTimer,
|
2021-08-06 00:17:05 +00:00
|
|
|
setComposeGroupName,
|
|
|
|
setComposeSearchTerm,
|
2021-02-23 20:34:28 +00:00
|
|
|
showArchivedConversations,
|
2021-08-06 00:17:05 +00:00
|
|
|
showChooseGroupMembers,
|
2021-02-23 20:34:28 +00:00
|
|
|
showInbox,
|
|
|
|
startComposing,
|
2021-11-01 18:43:02 +00:00
|
|
|
startSearch,
|
2022-04-05 00:38:22 +00:00
|
|
|
showUserNotFoundModal,
|
|
|
|
setIsFetchingUUID,
|
|
|
|
lookupConversationWithoutUuid,
|
|
|
|
toggleConversationInChooseMembers,
|
|
|
|
showConversation,
|
2021-03-03 20:09:58 +00:00
|
|
|
startSettingGroupMetadata,
|
2021-11-02 23:01:13 +00:00
|
|
|
theme,
|
2021-08-06 00:17:05 +00:00
|
|
|
toggleComposeEditingAvatar,
|
2021-11-01 18:43:02 +00:00
|
|
|
updateSearchTerm,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2021-10-12 23:59:08 +00:00
|
|
|
const [preferredWidth, setPreferredWidth] = useState(
|
|
|
|
// This clamp is present just in case we get a bogus value from storage.
|
|
|
|
clamp(preferredWidthFromStorage, MIN_WIDTH, MAX_WIDTH)
|
|
|
|
);
|
|
|
|
const [isResizing, setIsResizing] = useState(false);
|
|
|
|
|
2021-03-19 00:22:17 +00:00
|
|
|
const previousModeSpecificProps = usePrevious(
|
|
|
|
modeSpecificProps,
|
|
|
|
modeSpecificProps
|
|
|
|
);
|
2021-02-23 20:34:28 +00:00
|
|
|
|
|
|
|
// The left pane can be in various modes: the inbox, the archive, the composer, etc.
|
|
|
|
// Ideally, this would render subcomponents such as `<LeftPaneInbox>` or
|
|
|
|
// `<LeftPaneArchive>` (and if there's a way to do that cleanly, we should refactor
|
|
|
|
// this).
|
|
|
|
//
|
|
|
|
// But doing that presents two problems:
|
|
|
|
//
|
|
|
|
// 1. Different components render the same logical inputs (the main header's search),
|
|
|
|
// but React doesn't know that they're the same, so you can lose focus as you change
|
|
|
|
// modes.
|
|
|
|
// 2. These components render virtualized lists, which are somewhat slow to initialize.
|
2022-02-09 20:33:19 +00:00
|
|
|
// Switching between modes can cause noticeable hiccups.
|
2021-02-23 20:34:28 +00:00
|
|
|
//
|
|
|
|
// To get around those problems, we use "helpers" which all correspond to the same
|
|
|
|
// interface.
|
|
|
|
//
|
|
|
|
// Unfortunately, there's a little bit of repetition here because TypeScript isn't quite
|
|
|
|
// smart enough.
|
|
|
|
let helper: LeftPaneHelper<unknown>;
|
|
|
|
let shouldRecomputeRowHeights: boolean;
|
|
|
|
switch (modeSpecificProps.mode) {
|
|
|
|
case LeftPaneMode.Inbox: {
|
|
|
|
const inboxHelper = new LeftPaneInboxHelper(modeSpecificProps);
|
|
|
|
shouldRecomputeRowHeights =
|
|
|
|
previousModeSpecificProps.mode === modeSpecificProps.mode
|
|
|
|
? inboxHelper.shouldRecomputeRowHeights(previousModeSpecificProps)
|
|
|
|
: true;
|
|
|
|
helper = inboxHelper;
|
|
|
|
break;
|
2020-09-29 22:07:03 +00:00
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
case LeftPaneMode.Search: {
|
|
|
|
const searchHelper = new LeftPaneSearchHelper(modeSpecificProps);
|
|
|
|
shouldRecomputeRowHeights =
|
|
|
|
previousModeSpecificProps.mode === modeSpecificProps.mode
|
|
|
|
? searchHelper.shouldRecomputeRowHeights(previousModeSpecificProps)
|
|
|
|
: true;
|
|
|
|
helper = searchHelper;
|
|
|
|
break;
|
2020-09-29 22:07:03 +00:00
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
case LeftPaneMode.Archive: {
|
|
|
|
const archiveHelper = new LeftPaneArchiveHelper(modeSpecificProps);
|
|
|
|
shouldRecomputeRowHeights =
|
|
|
|
previousModeSpecificProps.mode === modeSpecificProps.mode
|
|
|
|
? archiveHelper.shouldRecomputeRowHeights(previousModeSpecificProps)
|
|
|
|
: true;
|
|
|
|
helper = archiveHelper;
|
|
|
|
break;
|
2019-03-12 00:20:16 +00:00
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
case LeftPaneMode.Compose: {
|
|
|
|
const composeHelper = new LeftPaneComposeHelper(modeSpecificProps);
|
|
|
|
shouldRecomputeRowHeights =
|
|
|
|
previousModeSpecificProps.mode === modeSpecificProps.mode
|
|
|
|
? composeHelper.shouldRecomputeRowHeights(previousModeSpecificProps)
|
|
|
|
: true;
|
|
|
|
helper = composeHelper;
|
|
|
|
break;
|
2019-03-12 00:20:16 +00:00
|
|
|
}
|
2021-03-03 20:09:58 +00:00
|
|
|
case LeftPaneMode.ChooseGroupMembers: {
|
|
|
|
const chooseGroupMembersHelper = new LeftPaneChooseGroupMembersHelper(
|
|
|
|
modeSpecificProps
|
|
|
|
);
|
|
|
|
shouldRecomputeRowHeights =
|
|
|
|
previousModeSpecificProps.mode === modeSpecificProps.mode
|
|
|
|
? chooseGroupMembersHelper.shouldRecomputeRowHeights(
|
|
|
|
previousModeSpecificProps
|
|
|
|
)
|
|
|
|
: true;
|
|
|
|
helper = chooseGroupMembersHelper;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LeftPaneMode.SetGroupMetadata: {
|
|
|
|
const setGroupMetadataHelper = new LeftPaneSetGroupMetadataHelper(
|
|
|
|
modeSpecificProps
|
|
|
|
);
|
|
|
|
shouldRecomputeRowHeights =
|
|
|
|
previousModeSpecificProps.mode === modeSpecificProps.mode
|
|
|
|
? setGroupMetadataHelper.shouldRecomputeRowHeights(
|
|
|
|
previousModeSpecificProps
|
|
|
|
)
|
|
|
|
: true;
|
|
|
|
helper = setGroupMetadataHelper;
|
|
|
|
break;
|
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
default:
|
|
|
|
throw missingCaseError(modeSpecificProps);
|
2020-09-29 22:07:03 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const onKeyDown = (event: KeyboardEvent) => {
|
2022-03-31 05:58:28 +00:00
|
|
|
const { ctrlKey, shiftKey, altKey, metaKey } = event;
|
2021-02-23 20:34:28 +00:00
|
|
|
const commandOrCtrl = OS.isMacOS() ? metaKey : ctrlKey;
|
2022-03-31 05:58:28 +00:00
|
|
|
const key = KeyboardLayout.lookup(event);
|
2021-02-23 20:34:28 +00:00
|
|
|
|
2022-03-31 05:58:28 +00:00
|
|
|
if (key === 'Escape') {
|
2021-05-19 18:32:12 +00:00
|
|
|
const backAction = helper.getBackAction({
|
|
|
|
showInbox,
|
|
|
|
startComposing,
|
|
|
|
showChooseGroupMembers,
|
|
|
|
});
|
|
|
|
if (backAction) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
backAction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (
|
|
|
|
commandOrCtrl &&
|
|
|
|
!shiftKey &&
|
|
|
|
!altKey &&
|
|
|
|
(key === 'n' || key === 'N')
|
|
|
|
) {
|
|
|
|
startComposing();
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
return;
|
2019-11-07 21:36:16 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
let conversationToOpen:
|
|
|
|
| undefined
|
|
|
|
| {
|
|
|
|
conversationId: string;
|
|
|
|
messageId?: string;
|
|
|
|
};
|
2019-11-07 21:36:16 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
const numericIndex = keyboardKeyToNumericIndex(event.key);
|
2022-04-30 05:24:20 +00:00
|
|
|
const openedByNumber = commandOrCtrl && isNumber(numericIndex);
|
|
|
|
if (openedByNumber) {
|
2021-11-11 22:43:05 +00:00
|
|
|
conversationToOpen =
|
|
|
|
helper.getConversationAndMessageAtIndex(numericIndex);
|
2021-02-23 20:34:28 +00:00
|
|
|
} else {
|
|
|
|
let toFind: undefined | ToFindType;
|
|
|
|
if (
|
|
|
|
(altKey && !shiftKey && key === 'ArrowUp') ||
|
|
|
|
(commandOrCtrl && shiftKey && key === '[') ||
|
|
|
|
(ctrlKey && shiftKey && key === 'Tab')
|
|
|
|
) {
|
|
|
|
toFind = { direction: FindDirection.Up, unreadOnly: false };
|
|
|
|
} else if (
|
|
|
|
(altKey && !shiftKey && key === 'ArrowDown') ||
|
|
|
|
(commandOrCtrl && shiftKey && key === ']') ||
|
|
|
|
(ctrlKey && key === 'Tab')
|
|
|
|
) {
|
|
|
|
toFind = { direction: FindDirection.Down, unreadOnly: false };
|
|
|
|
} else if (altKey && shiftKey && key === 'ArrowUp') {
|
|
|
|
toFind = { direction: FindDirection.Up, unreadOnly: true };
|
|
|
|
} else if (altKey && shiftKey && key === 'ArrowDown') {
|
|
|
|
toFind = { direction: FindDirection.Down, unreadOnly: true };
|
2019-11-07 21:36:16 +00:00
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
if (toFind) {
|
|
|
|
conversationToOpen = helper.getConversationAndMessageInDirection(
|
|
|
|
toFind,
|
|
|
|
selectedConversationId,
|
|
|
|
selectedMessageId
|
|
|
|
);
|
2019-11-07 21:36:16 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-29 22:07:03 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
if (conversationToOpen) {
|
|
|
|
const { conversationId, messageId } = conversationToOpen;
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation({ conversationId, messageId });
|
2022-04-30 05:24:20 +00:00
|
|
|
if (openedByNumber) {
|
|
|
|
clearSearch();
|
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2020-10-13 18:59:30 +00:00
|
|
|
}
|
2021-11-01 18:43:02 +00:00
|
|
|
|
|
|
|
helper.onKeyDown(event, {
|
|
|
|
searchInConversation,
|
|
|
|
selectedConversationId,
|
|
|
|
startSearch,
|
|
|
|
});
|
2021-02-23 20:34:28 +00:00
|
|
|
};
|
2019-03-12 00:20:16 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
document.addEventListener('keydown', onKeyDown);
|
|
|
|
return () => {
|
|
|
|
document.removeEventListener('keydown', onKeyDown);
|
|
|
|
};
|
|
|
|
}, [
|
2022-06-16 19:12:50 +00:00
|
|
|
clearSearch,
|
2021-02-23 20:34:28 +00:00
|
|
|
helper,
|
2021-11-01 18:43:02 +00:00
|
|
|
searchInConversation,
|
2021-02-23 20:34:28 +00:00
|
|
|
selectedConversationId,
|
|
|
|
selectedMessageId,
|
2021-05-19 18:32:12 +00:00
|
|
|
showChooseGroupMembers,
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation,
|
2021-05-19 18:32:12 +00:00
|
|
|
showInbox,
|
2021-02-23 20:34:28 +00:00
|
|
|
startComposing,
|
2021-11-01 18:43:02 +00:00
|
|
|
startSearch,
|
2021-02-23 20:34:28 +00:00
|
|
|
]);
|
|
|
|
|
2021-10-12 23:59:08 +00:00
|
|
|
const requiresFullWidth = helper.requiresFullWidth();
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isResizing) {
|
|
|
|
return noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
const onMouseMove = (event: MouseEvent) => {
|
|
|
|
let width: number;
|
|
|
|
if (requiresFullWidth) {
|
|
|
|
width = Math.max(event.clientX, MIN_FULL_WIDTH);
|
2021-10-14 21:19:50 +00:00
|
|
|
} else if (event.clientX < SNAP_WIDTH) {
|
2021-10-12 23:59:08 +00:00
|
|
|
width = MIN_WIDTH;
|
|
|
|
} else {
|
2021-10-14 21:19:50 +00:00
|
|
|
width = clamp(event.clientX, MIN_FULL_WIDTH, MAX_WIDTH);
|
2021-10-12 23:59:08 +00:00
|
|
|
}
|
|
|
|
setPreferredWidth(Math.min(width, MAX_WIDTH));
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
|
|
|
|
2021-11-17 03:22:31 +00:00
|
|
|
const stopResizing = () => {
|
2021-10-12 23:59:08 +00:00
|
|
|
setIsResizing(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
document.body.addEventListener('mousemove', onMouseMove);
|
2021-11-17 03:22:31 +00:00
|
|
|
document.body.addEventListener('mouseup', stopResizing);
|
|
|
|
document.body.addEventListener('mouseleave', stopResizing);
|
2021-10-12 23:59:08 +00:00
|
|
|
|
|
|
|
return () => {
|
|
|
|
document.body.removeEventListener('mousemove', onMouseMove);
|
2021-11-17 03:22:31 +00:00
|
|
|
document.body.removeEventListener('mouseup', stopResizing);
|
|
|
|
document.body.removeEventListener('mouseleave', stopResizing);
|
2021-10-12 23:59:08 +00:00
|
|
|
};
|
|
|
|
}, [isResizing, requiresFullWidth]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!isResizing) {
|
|
|
|
return noop;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.classList.add('is-resizing-left-pane');
|
|
|
|
return () => {
|
|
|
|
document.body.classList.remove('is-resizing-left-pane');
|
|
|
|
};
|
|
|
|
}, [isResizing]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isResizing || preferredWidth === preferredWidthFromStorage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const timeout = setTimeout(() => {
|
|
|
|
savePreferredLeftPaneWidth(preferredWidth);
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearTimeout(timeout);
|
|
|
|
};
|
|
|
|
}, [
|
|
|
|
isResizing,
|
|
|
|
preferredWidth,
|
|
|
|
preferredWidthFromStorage,
|
|
|
|
savePreferredLeftPaneWidth,
|
|
|
|
]);
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
const preRowsNode = helper.getPreRowsNode({
|
2022-01-27 22:12:26 +00:00
|
|
|
clearConversationSearch,
|
2021-03-03 20:09:58 +00:00
|
|
|
clearGroupCreationError,
|
2022-01-27 22:12:26 +00:00
|
|
|
clearSearch,
|
2021-03-03 20:09:58 +00:00
|
|
|
closeMaximumGroupSizeModal,
|
|
|
|
closeRecommendedGroupSizeModal,
|
2021-08-06 00:17:05 +00:00
|
|
|
composeDeleteAvatarFromDisk,
|
|
|
|
composeReplaceAvatar,
|
|
|
|
composeSaveAvatarToDisk,
|
2021-03-03 20:09:58 +00:00
|
|
|
createGroup,
|
2021-02-23 20:34:28 +00:00
|
|
|
i18n,
|
2022-01-27 22:12:26 +00:00
|
|
|
removeSelectedContact: toggleConversationInChooseMembers,
|
2021-03-03 20:09:58 +00:00
|
|
|
setComposeGroupAvatar,
|
2021-06-25 23:52:56 +00:00
|
|
|
setComposeGroupExpireTimer,
|
2022-01-27 22:12:26 +00:00
|
|
|
setComposeGroupName,
|
2021-08-06 00:17:05 +00:00
|
|
|
toggleComposeEditingAvatar,
|
2021-03-03 20:09:58 +00:00
|
|
|
});
|
|
|
|
const footerContents = helper.getFooterContents({
|
|
|
|
createGroup,
|
|
|
|
i18n,
|
|
|
|
startSettingGroupMetadata,
|
2021-02-23 20:34:28 +00:00
|
|
|
});
|
2021-03-03 20:09:58 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
const getRow = useMemo(() => helper.getRow.bind(helper), [helper]);
|
|
|
|
|
2021-08-11 16:23:21 +00:00
|
|
|
const onSelectConversation = useCallback(
|
|
|
|
(conversationId: string, messageId?: string) => {
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation({
|
2021-08-11 16:23:21 +00:00
|
|
|
conversationId,
|
|
|
|
messageId,
|
|
|
|
switchToAssociatedView: true,
|
|
|
|
});
|
|
|
|
},
|
2022-06-16 19:12:50 +00:00
|
|
|
[showConversation]
|
2021-08-11 16:23:21 +00:00
|
|
|
);
|
|
|
|
|
2021-03-19 00:22:17 +00:00
|
|
|
const previousSelectedConversationId = usePrevious(
|
|
|
|
selectedConversationId,
|
|
|
|
selectedConversationId
|
|
|
|
);
|
2021-04-02 22:32:55 +00:00
|
|
|
|
|
|
|
const isScrollable = helper.isScrollable();
|
|
|
|
|
|
|
|
let rowIndexToScrollTo: undefined | number;
|
|
|
|
let scrollBehavior: ScrollBehavior;
|
|
|
|
if (isScrollable) {
|
|
|
|
rowIndexToScrollTo =
|
|
|
|
previousSelectedConversationId === selectedConversationId
|
|
|
|
? undefined
|
|
|
|
: helper.getRowIndexToScrollTo(selectedConversationId);
|
|
|
|
scrollBehavior = ScrollBehavior.Default;
|
|
|
|
} else {
|
|
|
|
rowIndexToScrollTo = 0;
|
|
|
|
scrollBehavior = ScrollBehavior.Hard;
|
|
|
|
}
|
2021-03-19 00:22:17 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
// We ensure that the listKey differs between some modes (e.g. inbox/archived), ensuring
|
|
|
|
// that AutoSizer properly detects the new size of its slot in the flexbox. The
|
|
|
|
// archive explainer text at the top of the archive view causes problems otherwise.
|
|
|
|
// It also ensures that we scroll to the top when switching views.
|
|
|
|
const listKey = preRowsNode ? 1 : 0;
|
|
|
|
|
2022-03-04 21:14:52 +00:00
|
|
|
const width = getWidthFromPreferredWidth(preferredWidth, {
|
|
|
|
requiresFullWidth,
|
|
|
|
});
|
|
|
|
|
2021-10-12 23:59:08 +00:00
|
|
|
const widthBreakpoint = getConversationListWidthBreakpoint(width);
|
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
return (
|
2021-10-12 23:59:08 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-left-pane',
|
|
|
|
isResizing && 'module-left-pane--is-resizing',
|
|
|
|
`module-left-pane--width-${widthBreakpoint}`
|
|
|
|
)}
|
|
|
|
style={{ width }}
|
|
|
|
>
|
2021-04-02 21:43:39 +00:00
|
|
|
{/* eslint-enable jsx-a11y/no-static-element-interactions */}
|
2021-02-23 20:34:28 +00:00
|
|
|
<div className="module-left-pane__header">
|
2021-03-03 20:09:58 +00:00
|
|
|
{helper.getHeaderContents({
|
|
|
|
i18n,
|
|
|
|
showInbox,
|
|
|
|
startComposing,
|
|
|
|
showChooseGroupMembers,
|
|
|
|
}) || renderMainHeader()}
|
2019-03-12 00:20:16 +00:00
|
|
|
</div>
|
2022-01-27 22:12:26 +00:00
|
|
|
{helper.getSearchInput({
|
|
|
|
clearConversationSearch,
|
|
|
|
clearSearch,
|
|
|
|
i18n,
|
|
|
|
onChangeComposeSearchTerm: event => {
|
|
|
|
setComposeSearchTerm(event.target.value);
|
|
|
|
},
|
|
|
|
updateSearchTerm,
|
2022-06-16 19:12:50 +00:00
|
|
|
showConversation,
|
2022-01-27 22:12:26 +00:00
|
|
|
})}
|
2022-01-31 15:45:04 +00:00
|
|
|
<div className="module-left-pane__dialogs">
|
|
|
|
{renderExpiredBuildDialog({
|
|
|
|
containerWidthBreakpoint: widthBreakpoint,
|
|
|
|
})}
|
|
|
|
{renderRelinkDialog({ containerWidthBreakpoint: widthBreakpoint })}
|
|
|
|
{renderNetworkStatus({ containerWidthBreakpoint: widthBreakpoint })}
|
|
|
|
{renderUpdateDialog({ containerWidthBreakpoint: widthBreakpoint })}
|
|
|
|
</div>
|
2021-02-23 20:34:28 +00:00
|
|
|
{preRowsNode && <React.Fragment key={0}>{preRowsNode}</React.Fragment>}
|
|
|
|
<Measure bounds>
|
|
|
|
{({ contentRect, measureRef }: MeasuredComponentProps) => (
|
|
|
|
<div className="module-left-pane__list--measure" ref={measureRef}>
|
|
|
|
<div className="module-left-pane__list--wrapper">
|
|
|
|
<div
|
|
|
|
aria-live="polite"
|
|
|
|
className="module-left-pane__list"
|
|
|
|
key={listKey}
|
|
|
|
role="presentation"
|
|
|
|
tabIndex={-1}
|
|
|
|
>
|
|
|
|
<ConversationList
|
2021-10-14 21:21:04 +00:00
|
|
|
dimensions={{
|
|
|
|
width,
|
|
|
|
height: contentRect.bounds?.height || 0,
|
|
|
|
}}
|
2021-11-17 21:11:21 +00:00
|
|
|
getPreferredBadge={getPreferredBadge}
|
2021-02-23 20:34:28 +00:00
|
|
|
getRow={getRow}
|
|
|
|
i18n={i18n}
|
|
|
|
onClickArchiveButton={showArchivedConversations}
|
2021-03-03 20:09:58 +00:00
|
|
|
onClickContactCheckbox={(
|
|
|
|
conversationId: string,
|
|
|
|
disabledReason: undefined | ContactCheckboxDisabledReason
|
|
|
|
) => {
|
|
|
|
switch (disabledReason) {
|
|
|
|
case undefined:
|
|
|
|
toggleConversationInChooseMembers(conversationId);
|
|
|
|
break;
|
2021-03-11 21:29:31 +00:00
|
|
|
case ContactCheckboxDisabledReason.AlreadyAdded:
|
2021-03-03 20:09:58 +00:00
|
|
|
case ContactCheckboxDisabledReason.MaximumContactsSelected:
|
2021-03-11 21:29:31 +00:00
|
|
|
// These are no-ops.
|
2021-03-03 20:09:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw missingCaseError(disabledReason);
|
|
|
|
}
|
|
|
|
}}
|
2022-04-05 00:38:22 +00:00
|
|
|
showUserNotFoundModal={showUserNotFoundModal}
|
|
|
|
setIsFetchingUUID={setIsFetchingUUID}
|
|
|
|
lookupConversationWithoutUuid={lookupConversationWithoutUuid}
|
|
|
|
showConversation={showConversation}
|
2021-08-11 16:23:21 +00:00
|
|
|
onSelectConversation={onSelectConversation}
|
2021-02-23 20:34:28 +00:00
|
|
|
renderMessageSearchResult={renderMessageSearchResult}
|
|
|
|
rowCount={helper.getRowCount()}
|
2021-04-02 22:32:55 +00:00
|
|
|
scrollBehavior={scrollBehavior}
|
2021-03-19 00:22:17 +00:00
|
|
|
scrollToRowIndex={rowIndexToScrollTo}
|
2021-04-02 22:32:55 +00:00
|
|
|
scrollable={isScrollable}
|
2021-02-23 20:34:28 +00:00
|
|
|
shouldRecomputeRowHeights={shouldRecomputeRowHeights}
|
2021-03-03 20:09:58 +00:00
|
|
|
showChooseGroupMembers={showChooseGroupMembers}
|
2021-11-02 23:01:13 +00:00
|
|
|
theme={theme}
|
2021-02-23 20:34:28 +00:00
|
|
|
/>
|
2020-04-23 19:20:47 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-23 20:34:28 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Measure>
|
2021-03-03 20:09:58 +00:00
|
|
|
{footerContents && (
|
|
|
|
<div className="module-left-pane__footer">{footerContents}</div>
|
|
|
|
)}
|
2022-11-18 00:45:19 +00:00
|
|
|
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
|
|
|
|
<div
|
|
|
|
className="module-left-pane__resize-grab-area"
|
|
|
|
onMouseDown={() => {
|
|
|
|
setIsResizing(true);
|
|
|
|
}}
|
|
|
|
/>
|
2021-05-06 00:09:29 +00:00
|
|
|
{challengeStatus !== 'idle' &&
|
|
|
|
renderCaptchaDialog({
|
|
|
|
onSkip() {
|
|
|
|
setChallengeStatus('idle');
|
|
|
|
},
|
|
|
|
})}
|
2022-01-11 20:02:46 +00:00
|
|
|
{crashReportCount > 0 && renderCrashReportDialog()}
|
2021-02-23 20:34:28 +00:00
|
|
|
</div>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2020-09-29 22:07:03 +00:00
|
|
|
|
2021-02-23 20:34:28 +00:00
|
|
|
function keyboardKeyToNumericIndex(key: string): undefined | number {
|
|
|
|
if (key.length !== 1) {
|
|
|
|
return undefined;
|
2020-09-29 22:07:03 +00:00
|
|
|
}
|
2021-02-23 20:34:28 +00:00
|
|
|
const result = parseInt(key, 10) - 1;
|
|
|
|
const isValidIndex = Number.isInteger(result) && result >= 0 && result <= 8;
|
|
|
|
return isValidIndex ? result : undefined;
|
2019-01-14 21:49:58 +00:00
|
|
|
}
|