Standardize on showConversation function, delete unused functions

This commit is contained in:
Scott Nonnenberg 2022-12-14 11:05:32 -08:00 committed by GitHub
parent 1dc3ed914f
commit f2f1c3c021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 174 additions and 198 deletions

View file

@ -167,20 +167,20 @@ export function AddUserToAnotherGroupModal({
>
<ConversationList
dimensions={contentRect.bounds}
rowCount={filteredConversations.length}
getRow={handleGetRow}
shouldRecomputeRowHeights={false}
showConversation={noop}
getPreferredBadge={() => undefined}
getRow={handleGetRow}
i18n={i18n}
theme={theme}
lookupConversationWithoutUuid={async _ => undefined}
onClickArchiveButton={noop}
onClickContactCheckbox={noop}
onSelectConversation={setSelectedGroupId}
showChooseGroupMembers={noop}
lookupConversationWithoutUuid={async _ => undefined}
showUserNotFoundModal={noop}
rowCount={filteredConversations.length}
setIsFetchingUUID={noop}
shouldRecomputeRowHeights={false}
showChooseGroupMembers={noop}
showConversation={noop}
showUserNotFoundModal={noop}
theme={theme}
/>
</div>
)}

View file

@ -2,7 +2,10 @@
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import type { ConversationType } from '../state/ducks/conversations';
import type {
ConversationType,
ShowConversationType,
} from '../state/ducks/conversations';
import { Intl } from './Intl';
import type { LocalizerType, ThemeType } from '../types/Util';
import { Modal } from './Modal';
@ -11,14 +14,14 @@ import { ConversationListItem } from './conversationList/ConversationListItem';
type PropsType = {
groupAdmins: Array<ConversationType>;
i18n: LocalizerType;
openConversation: (conversationId: string) => unknown;
showConversation: ShowConversationType;
theme: ThemeType;
};
export function AnnouncementsOnlyGroupBanner({
groupAdmins,
i18n,
openConversation,
showConversation,
theme,
}: PropsType): JSX.Element {
const [isShowingAdmins, setIsShowingAdmins] = useState(false);
@ -35,13 +38,13 @@ export function AnnouncementsOnlyGroupBanner({
{groupAdmins.map(admin => (
<ConversationListItem
{...admin}
i18n={i18n}
onClick={() => {
openConversation(admin.id);
}}
draftPreview=""
i18n={i18n}
lastMessage={undefined}
lastUpdated={undefined}
onClick={() => {
showConversation({ conversationId: admin.id });
}}
theme={theme}
/>
))}

View file

@ -117,8 +117,8 @@ const useProps = (overrideProps: Partial<Props> = {}): Props => ({
),
areWeAdmin: boolean('areWeAdmin', Boolean(overrideProps.areWeAdmin)),
groupAdmins: [],
openConversation: action('openConversation'),
onCancelJoinRequest: action('onCancelJoinRequest'),
showConversation: action('showConversation'),
// SMS-only
isSMSOnly: overrideProps.isSMSOnly || false,
isFetchingUUID: overrideProps.isFetchingUUID || false,

View file

@ -40,7 +40,10 @@ import type {
import { isImageAttachment } from '../types/Attachment';
import { AudioCapture } from './conversation/AudioCapture';
import { CompositionUpload } from './CompositionUpload';
import type { ConversationType } from '../state/ducks/conversations';
import type {
ConversationType,
ShowConversationType,
} from '../state/ducks/conversations';
import type { EmojiPickDataType } from './emoji/EmojiPicker';
import type { LinkPreviewType } from '../types/message/LinkPreviews';
@ -117,7 +120,6 @@ export type OwnProps = Readonly<{
voiceNoteAttachment?: InMemoryAttachmentDraftType;
}
): unknown;
openConversation(conversationId: string): unknown;
quotedMessageId?: string;
quotedMessageProps?: Omit<
QuoteProps,
@ -131,6 +133,7 @@ export type OwnProps = Readonly<{
messageId: string | undefined
): unknown;
shouldSendHighQualityAttachments: boolean;
showConversation: ShowConversationType;
startRecording: () => unknown;
theme: ThemeType;
}>;
@ -257,7 +260,7 @@ export function CompositionArea({
areWeAdmin,
groupAdmins,
onCancelJoinRequest,
openConversation,
showConversation,
// SMS-only contacts
isSMSOnly,
isFetchingUUID,
@ -594,7 +597,7 @@ export function CompositionArea({
<AnnouncementsOnlyGroupBanner
groupAdmins={groupAdmins}
i18n={i18n}
openConversation={openConversation}
showConversation={showConversation}
theme={theme}
/>
);

View file

@ -135,10 +135,6 @@ export function Inbox({
prevConversation.trigger('unload', 'force unload requested');
}
function onShowConversation(id: string, messageId?: string): void {
showConversation({ conversationId: id, messageId });
}
function packInstallFailed() {
showToast(ToastStickerPackInstallFailed);
}
@ -147,14 +143,12 @@ export function Inbox({
window.Whisper.events.on('pack-install-failed', packInstallFailed);
window.Whisper.events.on('refreshConversation', refreshConversation);
window.Whisper.events.on('setupAsNewDevice', unload);
window.Whisper.events.on('showConversation', onShowConversation);
return () => {
window.Whisper.events.off('loadingProgress', setLoadingMessageCount);
window.Whisper.events.off('pack-install-failed', packInstallFailed);
window.Whisper.events.off('refreshConversation', refreshConversation);
window.Whisper.events.off('setupAsNewDevice', unload);
window.Whisper.events.off('showConversation', onShowConversation);
};
}, [prevConversation, showConversation]);

View file

@ -148,8 +148,8 @@ const useProps = (overrideProps: Partial<PropsType> = {}): PropsType => {
getPreferredBadge={() => undefined}
i18n={i18n}
id={id}
showConversation={action('showConversation')}
sentAt={1587358800000}
showConversation={action('showConversation')}
snippet="Lorem <<left>>ipsum<<right>> wow"
theme={ThemeType.light}
to={defaultConversations[1]}

View file

@ -142,7 +142,6 @@ export type PropsType = {
export function LeftPane({
challengeStatus,
crashReportCount,
clearConversationSearch,
clearGroupCreationError,
clearSearch,
@ -151,9 +150,11 @@ export function LeftPane({
composeDeleteAvatarFromDisk,
composeReplaceAvatar,
composeSaveAvatarToDisk,
crashReportCount,
createGroup,
getPreferredBadge,
i18n,
lookupConversationWithoutUuid,
modeSpecificProps,
preferredWidthFromStorage,
renderCaptchaDialog,
@ -173,19 +174,18 @@ export function LeftPane({
setComposeGroupExpireTimer,
setComposeGroupName,
setComposeSearchTerm,
setIsFetchingUUID,
showArchivedConversations,
showChooseGroupMembers,
showConversation,
showInbox,
showUserNotFoundModal,
startComposing,
startSearch,
showUserNotFoundModal,
setIsFetchingUUID,
lookupConversationWithoutUuid,
toggleConversationInChooseMembers,
showConversation,
startSettingGroupMetadata,
theme,
toggleComposeEditingAvatar,
toggleConversationInChooseMembers,
updateSearchTerm,
}: PropsType): JSX.Element {
const [preferredWidth, setPreferredWidth] = useState(

View file

@ -16,15 +16,15 @@ type PropsType = {
clearSearch: () => void;
disabled?: boolean;
i18n: LocalizerType;
searchConversation?: ConversationType;
searchTerm: string;
startSearchCounter: number;
updateSearchTerm: (searchTerm: string) => void;
showConversation: ShowConversationType;
onEnterKeyDown?: (
clearSearch: () => void,
showConversation: ShowConversationType
) => void;
searchConversation?: ConversationType;
searchTerm: string;
showConversation: ShowConversationType;
startSearchCounter: number;
updateSearchTerm: (searchTerm: string) => void;
};
export function LeftPaneSearchInput({
@ -32,12 +32,12 @@ export function LeftPaneSearchInput({
clearSearch,
disabled,
i18n,
onEnterKeyDown,
searchConversation,
searchTerm,
showConversation,
startSearchCounter,
updateSearchTerm,
showConversation,
onEnterKeyDown,
}: PropsType): JSX.Element {
const inputRef = useRef<null | HTMLInputElement>(null);

View file

@ -1193,22 +1193,22 @@ export function EditDistributionListModal({
getPreferredBadge={getPreferredBadge}
getRow={getRow}
i18n={i18n}
lookupConversationWithoutUuid={asyncShouldNeverBeCalled}
onClickArchiveButton={shouldNeverBeCalled}
onClickContactCheckbox={(conversationId: string) => {
toggleSelectedConversation(conversationId);
}}
lookupConversationWithoutUuid={asyncShouldNeverBeCalled}
showConversation={shouldNeverBeCalled}
showUserNotFoundModal={shouldNeverBeCalled}
setIsFetchingUUID={shouldNeverBeCalled}
onSelectConversation={shouldNeverBeCalled}
renderMessageSearchResult={() => {
shouldNeverBeCalled();
return <div />;
}}
rowCount={rowCount}
setIsFetchingUUID={shouldNeverBeCalled}
shouldRecomputeRowHeights={false}
showChooseGroupMembers={shouldNeverBeCalled}
showConversation={shouldNeverBeCalled}
showUserNotFoundModal={shouldNeverBeCalled}
theme={ThemeType.dark}
/>
</div>

View file

@ -57,7 +57,7 @@ const MESSAGE_DEFAULT_PROPS = {
markViewed: shouldNeverBeCalled,
messageExpanded: shouldNeverBeCalled,
// Called when clicking mention, but shouldn't do anything.
openConversation: noop,
showConversation: noop,
openGiftBadge: shouldNeverBeCalled,
openLink: shouldNeverBeCalled,
previews: [],

View file

@ -20,7 +20,7 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
{ incoming: 'incoming', outgoing: 'outgoing' },
overrideProps.direction || 'incoming'
),
openConversation: action('openConversation'),
showConversation: action('showConversation'),
text: text('text', overrideProps.text || ''),
});

View file

@ -13,14 +13,17 @@ import type {
export type Props = {
bodyRanges?: HydratedBodyRangesType;
direction?: 'incoming' | 'outgoing';
openConversation?: (conversationId: string, messageId?: string) => void;
showConversation?: (options: {
conversationId: string;
messageId?: string;
}) => unknown;
text: string;
};
export function AtMentionify({
bodyRanges,
direction,
openConversation,
showConversation,
text,
}: Props): JSX.Element {
if (!bodyRanges) {
@ -53,17 +56,17 @@ export function AtMentionify({
className={`MessageBody__at-mention MessageBody__at-mention--${direction}`}
key={range.start}
onClick={() => {
if (openConversation) {
openConversation(range.conversationID);
if (showConversation) {
showConversation({ conversationId: range.conversationID });
}
}}
onKeyUp={e => {
if (
e.target === e.currentTarget &&
e.keyCode === 13 &&
openConversation
showConversation
) {
openConversation(range.conversationID);
showConversation({ conversationId: range.conversationID });
}
}}
tabIndex={0}

View file

@ -63,8 +63,8 @@ enum SubModalState {
}
export function ContactModal({
areWeASubscriber,
areWeAdmin,
areWeASubscriber,
badges,
contact,
conversation,
@ -76,9 +76,9 @@ export function ContactModal({
removeMemberFromGroup,
showConversation,
theme,
toggleAddUserToAnotherGroupModal,
toggleAdmin,
toggleSafetyNumberModal,
toggleAddUserToAnotherGroupModal,
updateConversationModelSharedGroups,
viewUserStories,
}: PropsType): JSX.Element {

View file

@ -81,23 +81,21 @@ export type PropsDataType = {
export type PropsActionsType = {
destroyMessages: (conversationId: string) => void;
onSearchInConversation: () => void;
onOutgoingAudioCallInConversation: (conversationId: string) => void;
onOutgoingVideoCallInConversation: (conversationId: string) => void;
onShowConversationDetails: () => void;
onShowAllMedia: () => void;
onShowGroupMembers: () => void;
onGoBack: () => void;
onArchive: () => void;
onGoBack: () => void;
onMarkUnread: () => void;
onMoveToInbox: () => void;
setMuteExpiration: (conversationId: string, seconds: number) => void;
onOutgoingAudioCallInConversation: (conversationId: string) => void;
onOutgoingVideoCallInConversation: (conversationId: string) => void;
onSearchInConversation: () => void;
onShowAllMedia: () => void;
onShowConversationDetails: () => void;
onShowGroupMembers: () => void;
setDisappearingMessages: (
conversationId: string,
seconds: DurationInSeconds
) => void;
setMuteExpiration: (conversationId: string, seconds: number) => void;
setPinned: (conversationId: string, value: boolean) => void;
viewUserStories: ViewUserStoriesActionCreatorType;
};

View file

@ -15,6 +15,7 @@ import type {
ConversationTypeType,
InteractionModeType,
SaveAttachmentActionCreatorType,
ShowConversationType,
} from '../../state/ducks/conversations';
import type { ViewStoryActionCreatorType } from '../../state/ducks/stories';
import type { ReadStatus } from '../../messages/MessageReadStatus';
@ -299,7 +300,7 @@ export type PropsActions = {
showMessageDetail: (id: string) => void;
startConversation: (e164: string, uuid: UUIDStringType) => void;
openConversation: (conversationId: string, messageId?: string) => void;
showConversation: ShowConversationType;
openGiftBadge: (messageId: string) => void;
showContactDetail: (options: {
contact: EmbeddedContactType;
@ -1709,13 +1710,13 @@ export class Message extends React.PureComponent<Props, State> {
displayLimit,
i18n,
id,
messageExpanded,
openConversation,
kickOffAttachmentDownload,
messageExpanded,
showConversation,
status,
text,
textDirection,
textAttachment,
textDirection,
} = this.props;
const { metadataWidth } = this.state;
const isRTL = textDirection === TextDirection.RightToLeft;
@ -1747,13 +1748,11 @@ export class Message extends React.PureComponent<Props, State> {
>
<MessageBodyReadMore
bodyRanges={bodyRanges}
disableLinks={!this.areLinksEnabled()}
direction={direction}
disableLinks={!this.areLinksEnabled()}
displayLimit={displayLimit}
i18n={i18n}
id={id}
messageExpanded={messageExpanded}
openConversation={openConversation}
kickOffBodyDownload={() => {
if (!textAttachment) {
return;
@ -1763,6 +1762,8 @@ export class Message extends React.PureComponent<Props, State> {
messageId: id,
});
}}
messageExpanded={messageExpanded}
showConversation={showConversation}
text={contents || ''}
textAttachment={textAttachment}
/>

View file

@ -13,31 +13,27 @@ import { Emojify } from './Emojify';
import { AddNewLines } from './AddNewLines';
import { Linkify } from './Linkify';
import type { ShowConversationType } from '../../state/ducks/conversations';
import type {
HydratedBodyRangesType,
LocalizerType,
RenderTextCallbackType,
} from '../../types/Util';
type OpenConversationActionType = (
conversationId: string,
messageId?: string
) => void;
export type Props = {
direction?: 'incoming' | 'outgoing';
text: string;
author?: string;
textAttachment?: Pick<AttachmentType, 'pending' | 'digest' | 'key'>;
bodyRanges?: HydratedBodyRangesType;
direction?: 'incoming' | 'outgoing';
/** If set, all emoji will be the same size. Otherwise, just one emoji will be large. */
disableJumbomoji?: boolean;
/** If set, links will be left alone instead of turned into clickable `<a>` tags. */
disableLinks?: boolean;
i18n: LocalizerType;
bodyRanges?: HydratedBodyRangesType;
onIncreaseTextLength?: () => unknown;
openConversation?: OpenConversationActionType;
kickOffBodyDownload?: () => void;
onIncreaseTextLength?: () => unknown;
showConversation?: ShowConversationType;
text: string;
textAttachment?: Pick<AttachmentType, 'pending' | 'digest' | 'key'>;
};
const renderEmoji = ({
@ -67,17 +63,17 @@ const renderEmoji = ({
* them for you.
*/
export function MessageBody({
author,
bodyRanges,
direction,
disableJumbomoji,
disableLinks,
i18n,
onIncreaseTextLength,
openConversation,
text,
author,
textAttachment,
kickOffBodyDownload,
onIncreaseTextLength,
showConversation,
text,
textAttachment,
}: Props): JSX.Element {
const hasReadMore = Boolean(onIncreaseTextLength);
const textWithSuffix =
@ -100,10 +96,10 @@ export function MessageBody({
renderNonNewLine={({ text: innerText, key: innerKey }) => (
<AtMentionify
key={innerKey}
direction={direction}
text={innerText}
bodyRanges={bodyRanges}
openConversation={openConversation}
direction={direction}
showConversation={showConversation}
text={innerText}
/>
)}
/>

View file

@ -9,14 +9,14 @@ import { graphemeAndLinkAwareSlice } from '../../util/graphemeAndLinkAwareSlice'
export type Props = Pick<
MessageBodyPropsType,
| 'bodyRanges'
| 'direction'
| 'text'
| 'textAttachment'
| 'disableLinks'
| 'i18n'
| 'bodyRanges'
| 'openConversation'
| 'kickOffBodyDownload'
| 'showConversation'
| 'text'
| 'textAttachment'
> & {
id: string;
displayLimit?: number;
@ -38,9 +38,9 @@ export function MessageBodyReadMore({
displayLimit,
i18n,
id,
messageExpanded,
openConversation,
kickOffBodyDownload,
messageExpanded,
showConversation,
text,
textAttachment,
}: Props): JSX.Element {
@ -61,12 +61,12 @@ export function MessageBodyReadMore({
return (
<MessageBody
bodyRanges={bodyRanges}
disableLinks={disableLinks}
direction={direction}
disableLinks={disableLinks}
i18n={i18n}
onIncreaseTextLength={onIncreaseTextLength}
openConversation={openConversation}
kickOffBodyDownload={kickOffBodyDownload}
onIncreaseTextLength={onIncreaseTextLength}
showConversation={showConversation}
text={slicedText}
textAttachment={textAttachment}
/>

View file

@ -78,7 +78,7 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
kickOffAttachmentDownload: action('kickOffAttachmentDownload'),
markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'),
markViewed: action('markViewed'),
openConversation: action('openConversation'),
showConversation: action('showConversation'),
openGiftBadge: action('openGiftBadge'),
openLink: action('openLink'),
renderAudioAttachment: () => <div>*AudioAttachment*</div>,

View file

@ -81,7 +81,6 @@ export type PropsBackboneActions = Pick<
MessagePropsType,
| 'kickOffAttachmentDownload'
| 'markAttachmentAsCorrupted'
| 'openConversation'
| 'openGiftBadge'
| 'openLink'
| 'renderAudioAttachment'
@ -98,6 +97,7 @@ export type PropsReduxActions = Pick<
| 'doubleCheckMissingQuoteReference'
| 'saveAttachment'
| 'showContactModal'
| 'showConversation'
| 'showLightbox'
| 'showLightboxForViewOnceMedia'
| 'viewStory'
@ -290,13 +290,13 @@ export class MessageDetail extends React.Component<Props> {
kickOffAttachmentDownload,
markAttachmentAsCorrupted,
markViewed,
openConversation,
openGiftBadge,
openLink,
renderAudioAttachment,
saveAttachment,
showContactDetail,
showContactModal,
showConversation,
showExpiredIncomingTapToViewToast,
showExpiredOutgoingTapToViewToast,
showLightbox,
@ -336,7 +336,7 @@ export class MessageDetail extends React.Component<Props> {
markAttachmentAsCorrupted={markAttachmentAsCorrupted}
markViewed={markViewed}
messageExpanded={noop}
openConversation={openConversation}
showConversation={showConversation}
openGiftBadge={openGiftBadge}
openLink={openLink}
renderAudioAttachment={renderAudioAttachment}

View file

@ -112,7 +112,7 @@ const defaultMessageProps: TimelineMessagesProps = {
markAttachmentAsCorrupted: action('default--markAttachmentAsCorrupted'),
markViewed: action('default--markViewed'),
messageExpanded: action('default--message-expanded'),
openConversation: action('default--openConversation'),
showConversation: action('default--showConversation'),
openGiftBadge: action('openGiftBadge'),
openLink: action('default--openLink'),
previews: [],

View file

@ -282,10 +282,10 @@ const actions = () => ({
deleteMessage: action('deleteMessage'),
deleteMessageForEveryone: action('deleteMessageForEveryone'),
showMessageDetail: action('showMessageDetail'),
openConversation: action('openConversation'),
saveAttachment: action('saveAttachment'),
showContactDetail: action('showContactDetail'),
showContactModal: action('showContactModal'),
showConversation: action('showConversation'),
kickOffAttachmentDownload: action('kickOffAttachmentDownload'),
markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'),
markViewed: action('markViewed'),

View file

@ -244,8 +244,8 @@ const getActions = createSelector(
'toggleForwardMessageModal',
'deleteMessage',
'deleteMessageForEveryone',
'showConversation',
'showMessageDetail',
'openConversation',
'openGiftBadge',
'setQuoteByMessageId',
'showContactDetail',

View file

@ -78,7 +78,7 @@ const getDefaultProps = () => ({
markViewed: action('markViewed'),
messageExpanded: action('messageExpanded'),
showMessageDetail: action('showMessageDetail'),
openConversation: action('openConversation'),
showConversation: action('showConversation'),
openGiftBadge: action('openGiftBadge'),
saveAttachment: action('saveAttachment'),
showContactDetail: action('showContactDetail'),

View file

@ -279,7 +279,7 @@ const createProps = (overrideProps: Partial<Props> = {}): Props => ({
markAttachmentAsCorrupted: action('markAttachmentAsCorrupted'),
markViewed: action('markViewed'),
messageExpanded: action('messageExpanded'),
openConversation: action('openConversation'),
showConversation: action('showConversation'),
openGiftBadge: action('openGiftBadge'),
openLink: action('openLink'),
previews: overrideProps.previews || [],