2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-01-29 21:19:24 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
|
|
|
import { action } from '@storybook/addon-actions';
|
2021-03-11 21:29:31 +00:00
|
|
|
import { times } from 'lodash';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
import type { Meta } from '@storybook/react';
|
2021-09-18 00:30:08 +00:00
|
|
|
import { setupI18n } from '../../../util/setupI18n';
|
2021-01-29 21:19:24 +00:00
|
|
|
import enMessages from '../../../../_locales/en/messages.json';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props } from './ConversationDetails';
|
|
|
|
import { ConversationDetails } from './ConversationDetails';
|
2022-04-05 00:38:22 +00:00
|
|
|
import { ChooseGroupMembersModal } from './AddGroupMembersModal/ChooseGroupMembersModal';
|
|
|
|
import { ConfirmAdditionsModal } from './AddGroupMembersModal/ConfirmAdditionsModal';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ConversationType } from '../../../state/ducks/conversations';
|
2021-01-29 21:19:24 +00:00
|
|
|
import { getDefaultConversation } from '../../../test-both/helpers/getDefaultConversation';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { makeFakeLookupConversationWithoutServiceId } from '../../../test-both/helpers/fakeLookupConversationWithoutServiceId';
|
2021-11-02 23:01:13 +00:00
|
|
|
import { ThemeType } from '../../../types/Util';
|
2022-11-16 20:18:02 +00:00
|
|
|
import { DurationInSeconds } from '../../../util/durations';
|
2023-08-09 00:53:06 +00:00
|
|
|
import { NavTab } from '../../../state/ducks/nav';
|
|
|
|
import { CallMode } from '../../../types/Calling';
|
|
|
|
import {
|
|
|
|
CallDirection,
|
|
|
|
CallType,
|
|
|
|
DirectCallStatus,
|
|
|
|
} from '../../../types/CallDisposition';
|
2021-01-29 21:19:24 +00:00
|
|
|
|
|
|
|
const i18n = setupI18n('en', enMessages);
|
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export default {
|
|
|
|
title: 'Components/Conversation/ConversationDetails/ConversationDetails',
|
2023-10-11 19:06:43 +00:00
|
|
|
} satisfies Meta<Props>;
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2021-05-07 22:21:10 +00:00
|
|
|
const conversation: ConversationType = getDefaultConversation({
|
2021-01-29 21:19:24 +00:00
|
|
|
id: '',
|
|
|
|
lastUpdated: 0,
|
|
|
|
title: 'Some Conversation',
|
2021-06-02 00:24:28 +00:00
|
|
|
groupDescription: 'Hello World!',
|
2021-01-29 21:19:24 +00:00
|
|
|
type: 'group',
|
2021-05-07 22:21:10 +00:00
|
|
|
sharedGroupNames: [],
|
2021-05-28 16:15:17 +00:00
|
|
|
conversationColor: 'ultramarine' as const,
|
2021-05-07 22:21:10 +00:00
|
|
|
});
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2022-04-05 00:38:22 +00:00
|
|
|
const allCandidateContacts = times(10, () => getDefaultConversation());
|
|
|
|
|
2022-11-16 20:18:02 +00:00
|
|
|
const createProps = (
|
|
|
|
hasGroupLink = false,
|
|
|
|
expireTimer?: DurationInSeconds
|
|
|
|
): Props => ({
|
2022-12-06 19:03:09 +00:00
|
|
|
acceptConversation: action('acceptConversation'),
|
2022-12-16 03:12:05 +00:00
|
|
|
addMembersToGroup: async () => {
|
|
|
|
action('addMembersToGroup');
|
2021-03-11 21:29:31 +00:00
|
|
|
},
|
2021-11-30 16:29:57 +00:00
|
|
|
areWeASubscriber: false,
|
2022-12-06 19:03:09 +00:00
|
|
|
blockConversation: action('blockConversation'),
|
2021-01-29 21:19:24 +00:00
|
|
|
canEditGroupInfo: false,
|
2022-09-26 16:24:52 +00:00
|
|
|
canAddNewMembers: false,
|
2021-06-01 20:45:43 +00:00
|
|
|
conversation: expireTimer
|
|
|
|
? {
|
|
|
|
...conversation,
|
|
|
|
expireTimer,
|
|
|
|
}
|
|
|
|
: conversation,
|
2022-02-16 18:33:52 +00:00
|
|
|
hasActiveCall: false,
|
2021-01-29 21:19:24 +00:00
|
|
|
hasGroupLink,
|
2021-11-17 21:11:21 +00:00
|
|
|
getPreferredBadge: () => undefined,
|
2022-12-16 03:12:05 +00:00
|
|
|
getProfilesForConversation: action('getProfilesForConversation'),
|
2022-09-26 16:24:52 +00:00
|
|
|
groupsInCommon: [],
|
2021-01-29 21:19:24 +00:00
|
|
|
i18n,
|
|
|
|
isAdmin: false,
|
2021-10-20 23:46:41 +00:00
|
|
|
isGroup: true,
|
2022-12-16 03:12:05 +00:00
|
|
|
leaveGroup: action('leaveGroup'),
|
2021-01-29 21:19:24 +00:00
|
|
|
loadRecentMediaItems: action('loadRecentMediaItems'),
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships: times(32, i => ({
|
|
|
|
isAdmin: i === 1,
|
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: i === 2,
|
|
|
|
}),
|
|
|
|
})),
|
2022-10-24 20:46:36 +00:00
|
|
|
maxGroupSize: 1001,
|
|
|
|
maxRecommendedGroupSize: 151,
|
2021-05-13 14:47:30 +00:00
|
|
|
pendingApprovalMemberships: times(8, () => ({
|
|
|
|
member: getDefaultConversation(),
|
|
|
|
})),
|
|
|
|
pendingMemberships: times(5, () => ({
|
|
|
|
metadata: {},
|
|
|
|
member: getDefaultConversation(),
|
|
|
|
})),
|
2023-08-09 00:53:06 +00:00
|
|
|
selectedNavTab: NavTab.Chats,
|
2021-01-29 21:19:24 +00:00
|
|
|
setDisappearingMessages: action('setDisappearingMessages'),
|
|
|
|
showContactModal: action('showContactModal'),
|
2022-12-14 18:41:04 +00:00
|
|
|
pushPanelForConversation: action('pushPanelForConversation'),
|
2022-10-06 15:18:48 +00:00
|
|
|
showConversation: action('showConversation'),
|
2022-12-10 02:02:22 +00:00
|
|
|
showLightboxWithMedia: action('showLightboxWithMedia'),
|
2021-03-12 23:31:47 +00:00
|
|
|
updateGroupAttributes: async () => {
|
|
|
|
action('updateGroupAttributes')();
|
|
|
|
},
|
2021-08-06 00:17:05 +00:00
|
|
|
deleteAvatarFromDisk: action('deleteAvatarFromDisk'),
|
|
|
|
replaceAvatar: action('replaceAvatar'),
|
|
|
|
saveAvatarToDisk: action('saveAvatarToDisk'),
|
2021-10-20 23:46:41 +00:00
|
|
|
setMuteExpiration: action('setMuteExpiration'),
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData: [],
|
2021-10-20 23:46:41 +00:00
|
|
|
toggleSafetyNumberModal: action('toggleSafetyNumberModal'),
|
2022-09-26 16:24:52 +00:00
|
|
|
toggleAddUserToAnotherGroupModal: action('toggleAddUserToAnotherGroup'),
|
2021-10-20 23:46:41 +00:00
|
|
|
onOutgoingAudioCallInConversation: action(
|
|
|
|
'onOutgoingAudioCallInConversation'
|
|
|
|
),
|
|
|
|
onOutgoingVideoCallInConversation: action(
|
|
|
|
'onOutgoingVideoCallInConversation'
|
|
|
|
),
|
|
|
|
searchInConversation: action('searchInConversation'),
|
2021-11-02 23:01:13 +00:00
|
|
|
theme: ThemeType.light,
|
2022-04-05 00:38:22 +00:00
|
|
|
renderChooseGroupMembersModal: props => {
|
|
|
|
return (
|
|
|
|
<ChooseGroupMembersModal
|
|
|
|
{...props}
|
|
|
|
candidateContacts={allCandidateContacts}
|
|
|
|
selectedContacts={[]}
|
|
|
|
regionCode="US"
|
|
|
|
getPreferredBadge={() => undefined}
|
|
|
|
theme={ThemeType.light}
|
|
|
|
i18n={i18n}
|
2023-08-10 16:43:33 +00:00
|
|
|
lookupConversationWithoutServiceId={makeFakeLookupConversationWithoutServiceId()}
|
2023-11-07 23:45:33 +00:00
|
|
|
ourUsername={undefined}
|
2022-04-05 00:38:22 +00:00
|
|
|
showUserNotFoundModal={action('showUserNotFoundModal')}
|
2022-06-17 00:38:28 +00:00
|
|
|
isUsernamesEnabled
|
2022-04-05 00:38:22 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderConfirmAdditionsModal: props => {
|
|
|
|
return (
|
|
|
|
<ConfirmAdditionsModal {...props} selectedContacts={[]} i18n={i18n} />
|
|
|
|
);
|
|
|
|
},
|
2021-01-29 21:19:24 +00:00
|
|
|
});
|
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function Basic(): JSX.Element {
|
2021-01-29 21:19:24 +00:00
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} />;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function AsAdmin(): JSX.Element {
|
2021-01-29 21:19:24 +00:00
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} isAdmin />;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function AsLastAdmin(): JSX.Element {
|
2021-04-05 17:44:13 +00:00
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConversationDetails
|
|
|
|
{...props}
|
|
|
|
isAdmin
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships={times(32, i => ({
|
|
|
|
isAdmin: i === 2,
|
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: i === 2,
|
|
|
|
}),
|
|
|
|
}))}
|
2021-04-05 17:44:13 +00:00
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function AsOnlyAdmin(): JSX.Element {
|
2021-04-05 17:44:13 +00:00
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConversationDetails
|
|
|
|
{...props}
|
|
|
|
isAdmin
|
2021-04-29 18:32:38 +00:00
|
|
|
memberships={[
|
|
|
|
{
|
|
|
|
isAdmin: true,
|
|
|
|
member: getDefaultConversation({
|
|
|
|
isMe: true,
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
]}
|
2021-04-05 17:44:13 +00:00
|
|
|
/>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2021-04-05 17:44:13 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function GroupEditable(): JSX.Element {
|
2021-01-29 21:19:24 +00:00
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} canEditGroupInfo />;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2021-01-29 21:19:24 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function GroupEditableWithCustomDisappearingTimeout(): JSX.Element {
|
2022-11-16 20:18:02 +00:00
|
|
|
const props = createProps(false, DurationInSeconds.fromDays(3));
|
2021-06-01 20:45:43 +00:00
|
|
|
|
|
|
|
return <ConversationDetails {...props} canEditGroupInfo />;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2022-06-07 00:48:02 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function GroupLinksOn(): JSX.Element {
|
2021-01-29 21:19:24 +00:00
|
|
|
const props = createProps(true);
|
|
|
|
|
|
|
|
return <ConversationDetails {...props} isAdmin />;
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|
2021-07-20 20:18:35 +00:00
|
|
|
|
2022-06-07 00:48:02 +00:00
|
|
|
export const _11 = (): JSX.Element => (
|
2021-10-20 23:46:41 +00:00
|
|
|
<ConversationDetails {...createProps()} isGroup={false} />
|
2022-06-07 00:48:02 +00:00
|
|
|
);
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
function mins(n: number) {
|
|
|
|
return DurationInSeconds.toMillis(DurationInSeconds.fromMinutes(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function WithCallHistoryGroup(): JSX.Element {
|
|
|
|
const props = createProps();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ConversationDetails
|
|
|
|
{...props}
|
|
|
|
callHistoryGroup={{
|
2023-08-16 20:54:39 +00:00
|
|
|
peerId: props.conversation?.serviceId ?? '',
|
2023-08-09 00:53:06 +00:00
|
|
|
mode: CallMode.Direct,
|
|
|
|
type: CallType.Video,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
status: DirectCallStatus.Accepted,
|
|
|
|
timestamp: Date.now(),
|
|
|
|
children: [
|
|
|
|
{ callId: '123', timestamp: Date.now() },
|
|
|
|
{ callId: '122', timestamp: Date.now() - mins(30) },
|
|
|
|
{ callId: '121', timestamp: Date.now() - mins(45) },
|
|
|
|
{ callId: '121', timestamp: Date.now() - mins(60) },
|
|
|
|
],
|
|
|
|
}}
|
|
|
|
selectedNavTab={NavTab.Calls}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|