Merge branch 'main' into 4385-companies-people-count-broken-when-adding-another-people-relation-field

This commit is contained in:
martmull 2024-07-08 16:59:30 +02:00
commit caea7092cf
29 changed files with 336 additions and 304 deletions

View File

@ -1,9 +1,17 @@
import { MessageChannelVisibility } from '~/generated/graphql';
export enum MessageChannelContactAutoCreationPolicy {
SENT_AND_RECEIVED = 'SENT_AND_RECEIVED',
SENT = 'SENT',
NONE = 'NONE',
}
export type MessageChannel = {
id: string;
handle: string;
isContactAutoCreationEnabled?: boolean;
contactAutoCreationPolicy?: MessageChannelContactAutoCreationPolicy;
excludeNonProfessionalEmails: boolean;
excludeGroupEmails: boolean;
isSyncEnabled: boolean;
visibility: MessageChannelVisibility;
syncStatus: string;

View File

@ -12,6 +12,7 @@ export const OnboardingSyncEmailsSettingsCard = ({
value = MessageChannelVisibility.ShareEverything,
}: OnboardingSyncEmailsSettingsCardProps) => (
<SettingsAccountsRadioSettingsCard
name="sync-emails-visiblity"
options={onboardingSyncEmailsOptions}
value={value}
onChange={onChange}

View File

@ -1,9 +1,9 @@
import { SettingsAccountsVisibilityIcon } from '@/settings/accounts/components/SettingsAccountsVisibilityIcon';
import styled from '@emotion/styled';
import { SettingsAccountsVisibilitySettingCardMedia } from '@/settings/accounts/components/SettingsAccountsVisibilitySettingCardMedia';
import { MessageChannelVisibility } from '~/generated/graphql';
const StyledCardMedia = styled(SettingsAccountsVisibilitySettingCardMedia)`
const StyledCardMedia = styled(SettingsAccountsVisibilityIcon)`
width: ${({ theme }) => theme.spacing(10)};
`;

View File

@ -2,18 +2,12 @@ import { CalendarChannel } from '@/accounts/types/CalendarChannel';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { SettingsAccountsEventVisibilitySettingsCard } from '@/settings/accounts/components/SettingsAccountsCalendarVisibilitySettingsCard';
import { SettingsAccountsCardMedia } from '@/settings/accounts/components/SettingsAccountsCardMedia';
import { SettingsAccountsToggleSettingCard } from '@/settings/accounts/components/SettingsAccountsToggleSettingCard';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { Section } from '@react-email/components';
import { H2Title, IconRefresh, IconUser } from 'twenty-ui';
import { H2Title } from 'twenty-ui';
import { CalendarChannelVisibility } from '~/generated-metadata/graphql';
const StyledCardMedia = styled(SettingsAccountsCardMedia)`
height: ${({ theme }) => theme.spacing(6)};
`;
const StyledDetailsContainer = styled.div`
display: flex;
flex-direction: column;
@ -31,8 +25,6 @@ type SettingsAccountsCalendarChannelDetailsProps = {
export const SettingsAccountsCalendarChannelDetails = ({
calendarChannel,
}: SettingsAccountsCalendarChannelDetailsProps) => {
const theme = useTheme();
const { updateOneRecord } = useUpdateOneRecord<CalendarChannel>({
objectNameSingular: CoreObjectNameSingular.CalendarChannel,
});
@ -55,14 +47,6 @@ export const SettingsAccountsCalendarChannelDetails = ({
});
};
const handleSyncEventsToggle = (value: boolean) => {
updateOneRecord({
idToUpdate: calendarChannel.id,
updateOneRecordInput: {
isSyncEnabled: value,
},
});
};
return (
<StyledDetailsContainer>
<Section>
@ -81,36 +65,14 @@ export const SettingsAccountsCalendarChannelDetails = ({
description="Automatically create contacts for people you've participated in an event with."
/>
<SettingsAccountsToggleSettingCard
cardMedia={
<StyledCardMedia>
<IconUser
size={theme.icon.size.sm}
stroke={theme.icon.stroke.lg}
/>
</StyledCardMedia>
}
title="Auto-creation"
value={!!calendarChannel.isContactAutoCreationEnabled}
onToggle={handleContactAutoCreationToggle}
/>
</Section>
<Section>
<H2Title
title="Synchronization"
description="Past and future calendar events will automatically be synced to this workspace"
/>
<SettingsAccountsToggleSettingCard
cardMedia={
<StyledCardMedia>
<IconRefresh
size={theme.icon.size.sm}
stroke={theme.icon.stroke.lg}
/>
</StyledCardMedia>
}
title="Sync events"
value={!!calendarChannel.isSyncEnabled}
onToggle={handleSyncEventsToggle}
parameters={[
{
value: !!calendarChannel.isContactAutoCreationEnabled,
title: 'Auto-creation',
description: 'Automatically create contacts for people.',
onToggle: handleContactAutoCreationToggle,
},
]}
/>
</Section>
</StyledDetailsContainer>

View File

@ -11,6 +11,7 @@ import { SettingsAccountsListEmptyStateCard } from '@/settings/accounts/componen
import { SETTINGS_ACCOUNT_CALENDAR_CHANNELS_TAB_LIST_COMPONENT_ID } from '@/settings/accounts/constants/SettingsAccountCalendarChannelsTabListComponentId';
import { TabList } from '@/ui/layout/tab/components/TabList';
import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
import React from 'react';
export const SettingsAccountsCalendarChannelsContainer = () => {
const { activeTabIdState } = useTabList(
@ -59,13 +60,13 @@ export const SettingsAccountsCalendarChannelsContainer = () => {
tabs={tabs}
/>
{calendarChannels.map((calendarChannel) => (
<>
<React.Fragment key={calendarChannel.id}>
{calendarChannel.id === activeTabId && (
<SettingsAccountsCalendarChannelDetails
calendarChannel={calendarChannel}
/>
)}
</>
</React.Fragment>
))}
{false && activeTabId === 'general' && (
<SettingsAccountsCalendarChannelsGeneral />

View File

@ -1,7 +1,7 @@
import styled from '@emotion/styled';
import { SettingsAccountsRadioSettingsCard } from '@/settings/accounts/components/SettingsAccountsRadioSettingsCard';
import { SettingsAccountsVisibilitySettingCardMedia } from '@/settings/accounts/components/SettingsAccountsVisibilitySettingCardMedia';
import { SettingsAccountsVisibilityIcon } from '@/settings/accounts/components/SettingsAccountsVisibilityIcon';
import { CalendarChannelVisibility } from '~/generated/graphql';
type SettingsAccountsEventVisibilitySettingsCardProps = {
@ -9,7 +9,7 @@ type SettingsAccountsEventVisibilitySettingsCardProps = {
value?: CalendarChannelVisibility;
};
const StyledCardMedia = styled(SettingsAccountsVisibilitySettingCardMedia)`
const StyledCardMedia = styled(SettingsAccountsVisibilityIcon)`
height: ${({ theme }) => theme.spacing(6)};
`;
@ -33,6 +33,7 @@ export const SettingsAccountsEventVisibilitySettingsCard = ({
value = CalendarChannelVisibility.ShareEverything,
}: SettingsAccountsEventVisibilitySettingsCardProps) => (
<SettingsAccountsRadioSettingsCard
name="event-visibility"
options={eventSettingsVisibilityOptions}
value={value}
onChange={onChange}

View File

@ -0,0 +1,48 @@
import { MessageChannelContactAutoCreationPolicy } from '@/accounts/types/MessageChannel';
import { SettingsAccountsMessageAutoCreationIcon } from '@/settings/accounts/components/SettingsAccountsMessageAutoCreationIcon';
import { SettingsAccountsRadioSettingsCard } from '@/settings/accounts/components/SettingsAccountsRadioSettingsCard';
type SettingsAccountsMessageAutoCreationCardProps = {
onChange: (nextValue: MessageChannelContactAutoCreationPolicy) => void;
value?: MessageChannelContactAutoCreationPolicy;
};
const autoCreationOptions = [
{
title: 'Send and Received',
description: 'People Ive sent emails to and received emails from.',
value: MessageChannelContactAutoCreationPolicy.SENT_AND_RECEIVED,
cardMedia: (
<SettingsAccountsMessageAutoCreationIcon isSentActive isReceivedActive />
),
},
{
title: 'Sent',
description: 'People Ive sent emails to.',
value: MessageChannelContactAutoCreationPolicy.SENT,
cardMedia: <SettingsAccountsMessageAutoCreationIcon isSentActive />,
},
{
title: 'None',
description: 'Dont auto-create contacts.',
value: MessageChannelContactAutoCreationPolicy.NONE,
cardMedia: (
<SettingsAccountsMessageAutoCreationIcon
isSentActive={false}
isReceivedActive={false}
/>
),
},
];
export const SettingsAccountsMessageAutoCreationCard = ({
onChange,
value = MessageChannelContactAutoCreationPolicy.SENT_AND_RECEIVED,
}: SettingsAccountsMessageAutoCreationCardProps) => (
<SettingsAccountsRadioSettingsCard
name="message-auto-creation"
options={autoCreationOptions}
value={value}
onChange={onChange}
/>
);

View File

@ -0,0 +1,31 @@
import styled from '@emotion/styled';
import { SettingsAccountsCardMedia } from '@/settings/accounts/components/SettingsAccountsCardMedia';
type SettingsAccountsMessageAutoCreationIconProps = {
className?: string;
isSentActive?: boolean;
isReceivedActive?: boolean;
};
const StyledIconContainer = styled(SettingsAccountsCardMedia)`
align-items: stretch;
`;
const StyledDirectionSkeleton = styled.div<{ isActive?: boolean }>`
background-color: ${({ isActive, theme }) =>
isActive ? theme.accent.accent4060 : theme.background.quaternary};
border-radius: 1px;
height: 24px;
`;
export const SettingsAccountsMessageAutoCreationIcon = ({
className,
isSentActive,
isReceivedActive,
}: SettingsAccountsMessageAutoCreationIconProps) => (
<StyledIconContainer className={className}>
<StyledDirectionSkeleton isActive={isSentActive} />
<StyledDirectionSkeleton isActive={isReceivedActive} />
</StyledIconContainer>
);

View File

@ -1,12 +1,14 @@
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { H2Title, IconRefresh, IconUser } from 'twenty-ui';
import { H2Title } from 'twenty-ui';
import { MessageChannel } from '@/accounts/types/MessageChannel';
import {
MessageChannel,
MessageChannelContactAutoCreationPolicy,
} from '@/accounts/types/MessageChannel';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { SettingsAccountsCardMedia } from '@/settings/accounts/components/SettingsAccountsCardMedia';
import { SettingsAccountsInboxVisibilitySettingsCard } from '@/settings/accounts/components/SettingsAccountsInboxVisibilitySettingsCard';
import { SettingsAccountsMessageAutoCreationCard } from '@/settings/accounts/components/SettingsAccountsMessageAutoCreationCard';
import { SettingsAccountsMessageVisibilityCard } from '@/settings/accounts/components/SettingsAccountsMessageVisibilityCard';
import { SettingsAccountsToggleSettingCard } from '@/settings/accounts/components/SettingsAccountsToggleSettingCard';
import { Section } from '@/ui/layout/section/components/Section';
import { MessageChannelVisibility } from '~/generated-metadata/graphql';
@ -14,7 +16,12 @@ import { MessageChannelVisibility } from '~/generated-metadata/graphql';
type SettingsAccountsMessageChannelDetailsProps = {
messageChannel: Pick<
MessageChannel,
'id' | 'visibility' | 'isContactAutoCreationEnabled' | 'isSyncEnabled'
| 'id'
| 'visibility'
| 'contactAutoCreationPolicy'
| 'excludeNonProfessionalEmails'
| 'excludeGroupEmails'
| 'isSyncEnabled'
>;
};
@ -28,8 +35,6 @@ const StyledDetailsContainer = styled.div`
export const SettingsAccountsMessageChannelDetails = ({
messageChannel,
}: SettingsAccountsMessageChannelDetailsProps) => {
const theme = useTheme();
const { updateOneRecord } = useUpdateOneRecord<MessageChannel>({
objectNameSingular: CoreObjectNameSingular.MessageChannel,
});
@ -43,20 +48,31 @@ export const SettingsAccountsMessageChannelDetails = ({
});
};
const handleContactAutoCreationToggle = (value: boolean) => {
const handleContactAutoCreationChange = (
value: MessageChannelContactAutoCreationPolicy,
) => {
updateOneRecord({
idToUpdate: messageChannel.id,
updateOneRecordInput: {
isContactAutoCreationEnabled: value,
contactAutoCreationPolicy: value,
},
});
};
const handleIsSyncEnabledToggle = (value: boolean) => {
const handleIsGroupEmailExcludedToggle = (value: boolean) => {
updateOneRecord({
idToUpdate: messageChannel.id,
updateOneRecordInput: {
isSyncEnabled: value,
excludeGroupEmails: value,
},
});
};
const handleIsNonProfessionalEmailExcludedToggle = (value: boolean) => {
updateOneRecord({
idToUpdate: messageChannel.id,
updateOneRecordInput: {
excludeNonProfessionalEmails: value,
},
});
};
@ -68,7 +84,7 @@ export const SettingsAccountsMessageChannelDetails = ({
title="Visibility"
description="Define what will be visible to other users in your workspace"
/>
<SettingsAccountsInboxVisibilitySettingsCard
<SettingsAccountsMessageVisibilityCard
value={messageChannel.visibility}
onChange={handleVisibilityChange}
/>
@ -76,39 +92,29 @@ export const SettingsAccountsMessageChannelDetails = ({
<Section>
<H2Title
title="Contact auto-creation"
description="Automatically create contacts for people youve sent emails to"
description="Automatically create People records when receiving or sending emails"
/>
<SettingsAccountsToggleSettingCard
cardMedia={
<SettingsAccountsCardMedia>
<IconUser
size={theme.icon.size.sm}
stroke={theme.icon.stroke.lg}
/>
</SettingsAccountsCardMedia>
}
title="Auto-creation"
value={!!messageChannel.isContactAutoCreationEnabled}
onToggle={handleContactAutoCreationToggle}
<SettingsAccountsMessageAutoCreationCard
value={messageChannel.contactAutoCreationPolicy}
onChange={handleContactAutoCreationChange}
/>
</Section>
<Section>
<H2Title
title="Synchronization"
description="Past and future emails will automatically be synced to this workspace"
/>
<SettingsAccountsToggleSettingCard
cardMedia={
<SettingsAccountsCardMedia>
<IconRefresh
size={theme.icon.size.sm}
stroke={theme.icon.stroke.lg}
/>
</SettingsAccountsCardMedia>
}
title="Sync emails"
value={!!messageChannel.isSyncEnabled}
onToggle={handleIsSyncEnabledToggle}
parameters={[
{
title: 'Exclude non-professional emails',
description: 'Dont sync emails from/to Gmail, Outlook...',
value: !!messageChannel.excludeNonProfessionalEmails,
onToggle: handleIsNonProfessionalEmailExcludedToggle,
},
{
title: 'Exclude group emails',
description: 'Dont sync emails from team@ support@ noreply@...',
value: !!messageChannel.excludeGroupEmails,
onToggle: handleIsGroupEmailExcludedToggle,
},
]}
/>
</Section>
</StyledDetailsContainer>

View File

@ -10,6 +10,7 @@ import { SettingsAccountsMessageChannelDetails } from '@/settings/accounts/compo
import { SETTINGS_ACCOUNT_MESSAGE_CHANNELS_TAB_LIST_COMPONENT_ID } from '@/settings/accounts/constants/SettingsAccountMessageChannelsTabListComponentId';
import { TabList } from '@/ui/layout/tab/components/TabList';
import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
import React from 'react';
export const SettingsAccountsMessageChannelsContainer = () => {
const { activeTabIdState } = useTabList(
@ -58,13 +59,13 @@ export const SettingsAccountsMessageChannelsContainer = () => {
tabs={tabs}
/>
{messageChannels.map((messageChannel) => (
<>
<React.Fragment key={messageChannel.id}>
{messageChannel.id === activeTabId && (
<SettingsAccountsMessageChannelDetails
messageChannel={messageChannel}
/>
)}
</>
</React.Fragment>
))}
</>
);

View File

@ -1,8 +1,8 @@
import { SettingsAccountsRadioSettingsCard } from '@/settings/accounts/components/SettingsAccountsRadioSettingsCard';
import { SettingsAccountsVisibilitySettingCardMedia } from '@/settings/accounts/components/SettingsAccountsVisibilitySettingCardMedia';
import { SettingsAccountsVisibilityIcon } from '@/settings/accounts/components/SettingsAccountsVisibilityIcon';
import { MessageChannelVisibility } from '~/generated/graphql';
type SettingsAccountsInboxVisibilitySettingsCardProps = {
type SettingsAccountsMessageVisibilityCardProps = {
onChange: (nextValue: MessageChannelVisibility) => void;
value?: MessageChannelVisibility;
};
@ -13,7 +13,7 @@ const inboxSettingsVisibilityOptions = [
description: 'Subject, body and attachments will be shared with your team.',
value: MessageChannelVisibility.ShareEverything,
cardMedia: (
<SettingsAccountsVisibilitySettingCardMedia
<SettingsAccountsVisibilityIcon
metadata="active"
subject="active"
body="active"
@ -25,7 +25,7 @@ const inboxSettingsVisibilityOptions = [
description: 'Subject and metadata will be shared with your team.',
value: MessageChannelVisibility.Subject,
cardMedia: (
<SettingsAccountsVisibilitySettingCardMedia
<SettingsAccountsVisibilityIcon
metadata="active"
subject="active"
body="inactive"
@ -37,7 +37,7 @@ const inboxSettingsVisibilityOptions = [
description: 'Timestamp and participants will be shared with your team.',
value: MessageChannelVisibility.Metadata,
cardMedia: (
<SettingsAccountsVisibilitySettingCardMedia
<SettingsAccountsVisibilityIcon
metadata="active"
subject="inactive"
body="inactive"
@ -46,11 +46,12 @@ const inboxSettingsVisibilityOptions = [
},
];
export const SettingsAccountsInboxVisibilitySettingsCard = ({
export const SettingsAccountsMessageVisibilityCard = ({
onChange,
value = MessageChannelVisibility.ShareEverything,
}: SettingsAccountsInboxVisibilitySettingsCardProps) => (
}: SettingsAccountsMessageVisibilityCardProps) => (
<SettingsAccountsRadioSettingsCard
name="message-visibility"
options={inboxSettingsVisibilityOptions}
value={value}
onChange={onChange}

View File

@ -1,5 +1,5 @@
import { ReactNode } from 'react';
import styled from '@emotion/styled';
import { ReactNode } from 'react';
import { Radio } from '@/ui/input/components/Radio';
import { Card } from '@/ui/layout/card/components/Card';
@ -10,6 +10,7 @@ type SettingsAccountsRadioSettingsCardProps<Option extends { value: string }> =
onChange: (nextValue: Option['value']) => void;
options: Option[];
value: Option['value'];
name: string;
};
const StyledCardContent = styled(CardContent)`
@ -49,6 +50,7 @@ export const SettingsAccountsRadioSettingsCard = <
onChange,
options,
value,
name,
}: SettingsAccountsRadioSettingsCardProps<Option>) => (
<Card rounded>
{options.map((option, index) => (
@ -63,6 +65,7 @@ export const SettingsAccountsRadioSettingsCard = <
<StyledDescription>{option.description}</StyledDescription>
</div>
<StyledRadio
name={name}
value={option.value}
onCheckedChange={() => onChange(option.value)}
checked={value === option.value}

View File

@ -54,9 +54,7 @@ export const SettingsAccountsRowDropdownMenu = ({
LeftIcon={IconMail}
text="Emails settings"
onClick={() => {
navigate(
`/settings/accounts/emails/${account.messageChannels[0].id}`,
);
navigate(`/settings/accounts/emails`);
closeDropdown();
}}
/>
@ -64,9 +62,7 @@ export const SettingsAccountsRowDropdownMenu = ({
LeftIcon={IconCalendarEvent}
text="Calendar settings"
onClick={() => {
navigate(
`/settings/accounts/calendars/${account.calendarChannels[0].id}`,
);
navigate(`/settings/accounts/calendars`);
closeDropdown();
}}
/>

View File

@ -1,31 +0,0 @@
import { useGetSyncStatusOptions } from '@/settings/accounts/hooks//useGetSyncStatusOptions';
import { Status } from '@/ui/display/status/components/Status';
export type SettingsAccountsSynchronizationStatusProps = {
syncStatus: string;
isSyncEnabled?: boolean;
};
export const SettingsAccountsSynchronizationStatus = ({
syncStatus,
isSyncEnabled,
}: SettingsAccountsSynchronizationStatusProps) => {
const syncStatusOptions = useGetSyncStatusOptions();
const syncStatusOption = syncStatusOptions?.find(
(option) => option.value === syncStatus,
);
if (!isSyncEnabled) {
return <Status color="gray" text="Not synced" weight="medium" />;
}
return (
<Status
color={syncStatusOption?.color ?? 'gray'}
isLoaderVisible={syncStatus === 'ONGOING' || syncStatus === 'PENDING'}
text={syncStatusOption?.label ?? 'Not synced'}
weight="medium"
/>
);
};

View File

@ -1,22 +1,24 @@
import { ReactNode } from 'react';
import styled from '@emotion/styled';
import { Toggle } from '@/ui/input/components/Toggle';
import { Card } from '@/ui/layout/card/components/Card';
import { CardContent } from '@/ui/layout/card/components/CardContent';
type SettingsAccountsToggleSettingCardProps = {
cardMedia: ReactNode;
type Parameter = {
value: boolean;
onToggle: (value: boolean) => void;
title: string;
description: string;
onToggle: (value: boolean) => void;
};
type SettingsAccountsToggleSettingCardProps = {
parameters: Parameter[];
};
const StyledCardContent = styled(CardContent)`
align-items: center;
display: flex;
gap: ${({ theme }) => theme.spacing(4)};
padding: ${({ theme }) => theme.spacing(2, 4)};
cursor: pointer;
&:hover {
@ -24,23 +26,37 @@ const StyledCardContent = styled(CardContent)`
}
`;
const StyledTitle = styled.span`
const StyledTitle = styled.div`
color: ${({ theme }) => theme.font.color.primary};
font-weight: ${({ theme }) => theme.font.weight.medium};
margin-right: auto;
margin-bottom: ${({ theme }) => theme.spacing(2)};
`;
const StyledDescription = styled.div`
color: ${({ theme }) => theme.font.color.tertiary};
font-size: ${({ theme }) => theme.font.size.sm};
`;
const StyledToggle = styled(Toggle)`
margin-left: auto;
`;
export const SettingsAccountsToggleSettingCard = ({
cardMedia,
value,
onToggle,
title,
parameters,
}: SettingsAccountsToggleSettingCardProps) => (
<Card rounded>
<StyledCardContent onClick={() => onToggle(!value)}>
{cardMedia}
<StyledTitle>{title}</StyledTitle>
<Toggle value={value} onChange={onToggle} />
</StyledCardContent>
{parameters.map((parameter, index) => (
<StyledCardContent
key={index}
divider={index < parameters.length - 1}
onClick={() => parameter.onToggle(!parameter.value)}
>
<div>
<StyledTitle>{parameter.title}</StyledTitle>
<StyledDescription>{parameter.description}</StyledDescription>
</div>
<StyledToggle value={parameter.value} onChange={parameter.onToggle} />
</StyledCardContent>
))}
</Card>
);

View File

@ -4,7 +4,7 @@ import { SettingsAccountsCardMedia } from '@/settings/accounts/components/Settin
type VisibilityElementState = 'active' | 'inactive';
type SettingsAccountsVisibilitySettingCardMediaProps = {
type SettingsAccountsVisibilityIconProps = {
className?: string;
metadata?: VisibilityElementState;
subject?: VisibilityElementState;
@ -31,12 +31,12 @@ const StyledBodySkeleton = styled(StyledSubjectSkeleton)`
flex: 1 0 auto;
`;
export const SettingsAccountsVisibilitySettingCardMedia = ({
export const SettingsAccountsVisibilityIcon = ({
className,
metadata,
subject,
body,
}: SettingsAccountsVisibilitySettingCardMediaProps) => (
}: SettingsAccountsVisibilityIconProps) => (
<StyledCardMedia className={className}>
{!!metadata && <StyledMetadataSkeleton isActive={metadata === 'active'} />}
{!!subject && <StyledSubjectSkeleton isActive={subject === 'active'} />}

View File

@ -1,6 +1,7 @@
import { Meta, StoryObj } from '@storybook/react';
import { ComponentDecorator } from 'twenty-ui';
import { MessageChannelContactAutoCreationPolicy } from '@/accounts/types/MessageChannel';
import { SettingsAccountsMessageChannelDetails } from '@/settings/accounts/components/SettingsAccountsMessageChannelDetails';
import { MessageChannelVisibility } from '~/generated/graphql';
@ -12,7 +13,9 @@ const meta: Meta<typeof SettingsAccountsMessageChannelDetails> = {
args: {
messageChannel: {
id: '20202020-ef5a-4822-9e08-ce6e6a4dcb6a',
isContactAutoCreationEnabled: true,
contactAutoCreationPolicy: MessageChannelContactAutoCreationPolicy.SENT,
excludeNonProfessionalEmails: true,
excludeGroupEmails: false,
isSyncEnabled: true,
visibility: MessageChannelVisibility.ShareEverything,
},

View File

@ -1,8 +1,9 @@
import * as React from 'react';
import styled from '@emotion/styled';
import { motion } from 'framer-motion';
import * as React from 'react';
import { RGBA } from 'twenty-ui';
import { v4 } from 'uuid';
import { RadioGroup } from './RadioGroup';
export enum RadioSize {
@ -105,6 +106,7 @@ const StyledLabel = styled.label<LabelProps>`
export type RadioProps = {
checked?: boolean;
className?: string;
name?: string;
disabled?: boolean;
label?: string;
labelPosition?: LabelPosition;
@ -118,6 +120,7 @@ export type RadioProps = {
export const Radio = ({
checked,
className,
name = 'input-radio',
disabled = false,
label,
labelPosition = LabelPosition.Right,
@ -131,12 +134,14 @@ export const Radio = ({
onCheckedChange?.(event.target.checked);
};
const optionId = v4();
return (
<StyledContainer className={className} labelPosition={labelPosition}>
<StyledRadioInput
type="radio"
id="input-radio"
name="input-radio"
id={optionId}
name={name}
data-testid="input-radio"
checked={checked}
value={value || label}
@ -149,7 +154,7 @@ export const Radio = ({
/>
{label && (
<StyledLabel
htmlFor="input-radio"
htmlFor={optionId}
labelPosition={labelPosition}
disabled={disabled}
>

View File

@ -24,7 +24,7 @@ const StyledDropdownMenu = styled.div<{
display: flex;
flex-direction: column;
z-index: 1;
z-index: 30;
width: ${({ width = 160 }) =>
typeof width === 'number' ? `${width}px` : width};
`;

View File

@ -1,4 +1,3 @@
import * as React from 'react';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { IconComponent, Pill } from 'twenty-ui';
@ -41,6 +40,7 @@ const StyledHover = styled.span`
padding: ${({ theme }) => theme.spacing(1)};
padding-left: ${({ theme }) => theme.spacing(2)};
padding-right: ${({ theme }) => theme.spacing(2)};
font-weight: ${({ theme }) => theme.font.weight.medium};
&:hover {
background: ${({ theme }) => theme.background.tertiary};

View File

@ -40,11 +40,6 @@ export const seedFeatureFlags = async (
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsContactCreationForSentAndReceivedEmailsEnabled,
workspaceId: workspaceId,
value: true,
},
{
key: FeatureFlagKeys.IsMessagingAliasFetchingEnabled,
workspaceId: workspaceId,

View File

@ -1,19 +1,19 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { IDField } from '@ptc-org/nestjs-query-graphql';
import {
Entity,
Unique,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
Entity,
ManyToOne,
PrimaryGeneratedColumn,
Relation,
Unique,
UpdateDateColumn,
} from 'typeorm';
import { IDField } from '@ptc-org/nestjs-query-graphql';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { UUIDScalarType } from 'src/engine/api/graphql/workspace-schema-builder/graphql-types/scalars';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
export enum FeatureFlagKeys {
IsBlocklistEnabled = 'IS_BLOCKLIST_ENABLED',
@ -21,7 +21,6 @@ export enum FeatureFlagKeys {
IsAirtableIntegrationEnabled = 'IS_AIRTABLE_INTEGRATION_ENABLED',
IsPostgreSQLIntegrationEnabled = 'IS_POSTGRESQL_INTEGRATION_ENABLED',
IsStripeIntegrationEnabled = 'IS_STRIPE_INTEGRATION_ENABLED',
IsContactCreationForSentAndReceivedEmailsEnabled = 'IS_CONTACT_CREATION_FOR_SENT_AND_RECEIVED_EMAILS_ENABLED',
IsForeignKeyCommentConstraintEnabled = 'IS_FOREIGN_KEY_COMMENT_CONSTRAINT_ENABLED',
IsCopilotEnabled = 'IS_COPILOT_ENABLED',
IsMessagingAliasFetchingEnabled = 'IS_MESSAGING_ALIAS_FETCHING_ENABLED',

View File

@ -4,12 +4,12 @@ import { InjectDataSource } from '@nestjs/typeorm';
import { Command, CommandRunner, Option } from 'nest-commander';
import { DataSource } from 'typeorm';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
import { standardObjectMetadataDefinitions } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects';
import { StandardObjectFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-object.factory';
import { StandardFieldFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { CustomWorkspaceEntity } from 'src/engine/twenty-orm/custom.workspace-entity';
import { StandardFieldFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-field.factory';
import { StandardObjectFactory } from 'src/engine/workspace-manager/workspace-sync-metadata/factories/standard-object.factory';
import { standardObjectMetadataDefinitions } from 'src/engine/workspace-manager/workspace-sync-metadata/standard-objects';
import { computeStandardFields } from 'src/engine/workspace-manager/workspace-sync-metadata/utils/compute-standard-fields.util';
interface RunCommandOptions {
@ -58,7 +58,6 @@ export class AddStandardIdCommand extends CommandRunner {
IS_AIRTABLE_INTEGRATION_ENABLED: true,
IS_POSTGRESQL_INTEGRATION_ENABLED: true,
IS_STRIPE_INTEGRATION_ENABLED: false,
IS_CONTACT_CREATION_FOR_SENT_AND_RECEIVED_EMAILS_ENABLED: true,
IS_FOREIGN_KEY_COMMENT_CONSTRAINT_ENABLED: false,
IS_COPILOT_ENABLED: false,
IS_MESSAGING_ALIAS_FETCHING_ENABLED: true,
@ -78,7 +77,6 @@ export class AddStandardIdCommand extends CommandRunner {
IS_AIRTABLE_INTEGRATION_ENABLED: true,
IS_POSTGRESQL_INTEGRATION_ENABLED: true,
IS_STRIPE_INTEGRATION_ENABLED: false,
IS_CONTACT_CREATION_FOR_SENT_AND_RECEIVED_EMAILS_ENABLED: true,
IS_FOREIGN_KEY_COMMENT_CONSTRAINT_ENABLED: false,
IS_COPILOT_ENABLED: false,
IS_MESSAGING_ALIAS_FETCHING_ENABLED: true,

View File

@ -1,30 +1,30 @@
import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { EntityManager } from 'typeorm';
import compact from 'lodash.compact';
import chunk from 'lodash.chunk';
import compact from 'lodash.compact';
import { EntityManager } from 'typeorm';
import { getDomainNameFromHandle } from 'src/modules/calendar-messaging-participant/utils/get-domain-name-from-handle.util';
import { CreateCompanyService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/create-company/create-company.service';
import { CreateContactService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/create-contact/create-contact.service';
import { PersonRepository } from 'src/modules/person/repositories/person.repository';
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
import { isWorkEmail } from 'src/utils/is-work-email';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
import { getUniqueContactsAndHandles } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/get-unique-contacts-and-handles.util';
import { filterOutSelfAndContactsFromCompanyOrWorkspace } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/filter-out-contacts-from-company-or-workspace.util';
import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { WorkspaceDataSource } from 'src/engine/twenty-orm/datasource/workspace.datasource';
import { InjectWorkspaceDatasource } from 'src/engine/twenty-orm/decorators/inject-workspace-datasource.decorator';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { getDomainNameFromHandle } from 'src/modules/calendar-messaging-participant/utils/get-domain-name-from-handle.util';
import { CalendarEventParticipantService } from 'src/modules/calendar/calendar-event-participant-manager/services/calendar-event-participant.service';
import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/connected-account/auto-companies-and-contacts-creation/constants/contacts-creation-batch-size.constant';
import { Contact } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/connected-account/auto-companies-and-contacts-creation/constants/contacts-creation-batch-size.constant';
import { CreateCompanyService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/create-company/create-company.service';
import { CreateContactService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/create-contact/create-contact.service';
import { Contact } from 'src/modules/connected-account/auto-companies-and-contacts-creation/types/contact.type';
import { filterOutSelfAndContactsFromCompanyOrWorkspace } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/filter-out-contacts-from-company-or-workspace.util';
import { getUniqueContactsAndHandles } from 'src/modules/connected-account/auto-companies-and-contacts-creation/utils/get-unique-contacts-and-handles.util';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { PersonRepository } from 'src/modules/person/repositories/person.repository';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
import { WorkspaceMemberRepository } from 'src/modules/workspace-member/repositories/workspace-member.repository';
import { WorkspaceMemberWorkspaceEntity } from 'src/modules/workspace-member/standard-objects/workspace-member.workspace-entity';
import { isWorkEmail } from 'src/utils/is-work-email';
@Injectable()
export class CreateCompanyAndContactService {
@ -52,9 +52,6 @@ export class CreateCompanyAndContactService {
return [];
}
// TODO: This is a feature that may be implemented in the future
const isContactAutoCreationForNonWorkEmailsEnabled = false;
const workspaceMembers =
await this.workspaceMemberRepository.getAllByWorkspaceId(
workspaceId,
@ -89,9 +86,7 @@ export class CreateCompanyAndContactService {
const filteredContactsToCreate = uniqueContacts.filter(
(participant) =>
!alreadyCreatedContactEmails.includes(participant.handle) &&
participant.handle.includes('@') &&
(isContactAutoCreationForNonWorkEmailsEnabled ||
isWorkEmail(participant.handle)),
participant.handle.includes('@'),
);
const filteredContactsToCreateWithCompanyDomainNames =

View File

@ -1,31 +1,33 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { InjectRepository } from '@nestjs/typeorm';
import { EntityManager, Repository } from 'typeorm';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator';
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
import { MessageQueueService } from 'src/engine/integrations/message-queue/services/message-queue.service';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import {
CreateCompanyAndContactJobData,
CreateCompanyAndContactJob,
CreateCompanyAndContactJobData,
} from 'src/modules/connected-account/auto-companies-and-contacts-creation/jobs/create-company-and-contact.job';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service';
import { MessagingMessageService } from 'src/modules/messaging/common/services/messaging-message.service';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
MessageChannelContactAutoCreationPolicy,
MessageChannelWorkspaceEntity,
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import {
GmailMessage,
Participant,
ParticipantWithMessageId,
} from 'src/modules/messaging/message-import-manager/drivers/gmail/types/gmail-message';
import { MessagingMessageService } from 'src/modules/messaging/common/services/messaging-message.service';
import { MessagingMessageParticipantService } from 'src/modules/messaging/common/services/messaging-message-participant.service';
import { InjectMessageQueue } from 'src/engine/integrations/message-queue/decorators/message-queue.decorator';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { isGroupEmail } from 'src/utils/is-group-email';
import { isWorkEmail } from 'src/utils/is-work-email';
@Injectable()
export class MessagingSaveMessagesAndEnqueueContactCreationService {
@ -51,18 +53,8 @@ export class MessagingSaveMessagesAndEnqueueContactCreationService {
workspaceId,
);
const isContactCreationForSentAndReceivedEmailsEnabledFeatureFlag =
await this.featureFlagRepository.findOneBy({
workspaceId: workspaceId,
key: FeatureFlagKeys.IsContactCreationForSentAndReceivedEmailsEnabled,
value: true,
});
const emailAliases = connectedAccount.emailAliases?.split(',') || [];
const isContactCreationForSentAndReceivedEmailsEnabled =
isContactCreationForSentAndReceivedEmailsEnabledFeatureFlag?.value;
let savedMessageParticipants: MessageParticipantWorkspaceEntity[] = [];
const participantsWithMessageId = await workspaceDataSource?.transaction(
@ -87,14 +79,35 @@ export class MessagingSaveMessagesAndEnqueueContactCreationService {
message.participants.find((p) => p.role === 'from')?.handle ||
'';
const isMessageSentByConnectedAccount =
emailAliases.includes(fromHandle);
const isParticipantConnectedAccount = emailAliases.includes(
participant.handle,
);
const isExcludedByNonProfessionalEmails =
messageChannel.excludeNonProfessionalEmails &&
!isWorkEmail(participant.handle);
const isExcludedByGroupEmails =
messageChannel.excludeGroupEmails &&
isGroupEmail(participant.handle);
const shouldCreateContact =
!isParticipantConnectedAccount &&
!isExcludedByNonProfessionalEmails &&
!isExcludedByGroupEmails &&
(messageChannel.contactAutoCreationPolicy ===
MessageChannelContactAutoCreationPolicy.SENT_AND_RECEIVED ||
(messageChannel.contactAutoCreationPolicy ===
MessageChannelContactAutoCreationPolicy.SENT &&
isMessageSentByConnectedAccount));
return {
...participant,
messageId,
shouldCreateContact:
messageChannel.isContactAutoCreationEnabled &&
(isContactCreationForSentAndReceivedEmailsEnabled ||
emailAliases.includes(fromHandle)) &&
!emailAliases.includes(participant.handle),
shouldCreateContact,
};
})
: [];

View File

@ -1,29 +1,29 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { IsFeatureEnabledService } from 'src/engine/core-modules/feature-flag/services/is-feature-enabled.service';
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
import { InjectCacheStorage } from 'src/engine/integrations/cache-storage/decorators/cache-storage.decorator';
import { CacheStorageNamespace } from 'src/engine/integrations/cache-storage/types/cache-storage-namespace.enum';
import { CacheStorageService } from 'src/engine/integrations/cache-storage/cache-storage.service';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { EmailAliasManagerService } from 'src/modules/connected-account/email-alias-manager/services/email-alias-manager.service';
import { BlocklistRepository } from 'src/modules/connected-account/repositories/blocklist.repository';
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
import { GoogleAPIRefreshAccessTokenService } from 'src/modules/connected-account/services/google-api-refresh-access-token/google-api-refresh-access-token.service';
import { BlocklistWorkspaceEntity } from 'src/modules/connected-account/standard-objects/blocklist.workspace-entity';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { BlocklistRepository } from 'src/modules/connected-account/repositories/blocklist.repository';
import { MessagingTelemetryService } from 'src/modules/messaging/common/services/messaging-telemetry.service';
import {
MessageChannelWorkspaceEntity,
MessageChannelSyncStage,
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { filterEmails } from 'src/modules/messaging/message-import-manager/utils/filter-emails.util';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
import { MessagingChannelSyncStatusService } from 'src/modules/messaging/common/services/messaging-channel-sync-status.service';
import { MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE } from 'src/modules/messaging/message-import-manager/drivers/gmail/constants/messaging-gmail-users-messages-get-batch-size.constant';
import { MessagingGmailFetchMessagesByBatchesService } from 'src/modules/messaging/message-import-manager/drivers/gmail/services/messaging-gmail-fetch-messages-by-batches.service';
import { MessagingErrorHandlingService } from 'src/modules/messaging/common/services/messaging-error-handling.service';
import { MessagingSaveMessagesAndEnqueueContactCreationService } from 'src/modules/messaging/common/services/messaging-save-messages-and-enqueue-contact-creation.service';
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
import { EmailAliasManagerService } from 'src/modules/connected-account/email-alias-manager/services/email-alias-manager.service';
import { IsFeatureEnabledService } from 'src/engine/core-modules/feature-flag/services/is-feature-enabled.service';
import { FeatureFlagKeys } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
import { MessagingTelemetryService } from 'src/modules/messaging/common/services/messaging-telemetry.service';
import {
MessageChannelSyncStage,
MessageChannelWorkspaceEntity,
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MESSAGING_GMAIL_USERS_MESSAGES_GET_BATCH_SIZE } from 'src/modules/messaging/message-import-manager/drivers/gmail/constants/messaging-gmail-users-messages-get-batch-size.constant';
import { MessagingGmailFetchMessagesByBatchesService } from 'src/modules/messaging/message-import-manager/drivers/gmail/services/messaging-gmail-fetch-messages-by-batches.service';
import { filterEmails } from 'src/modules/messaging/message-import-manager/utils/filter-emails.util';
@Injectable()
export class MessagingGmailMessagesImportService {

View File

@ -9,7 +9,7 @@ export const filterEmails = (
) => {
return filterOutBlocklistedMessages(
messageChannelHandle,
filterOutIcsAttachments(filterOutNonPersonalEmails(messages)),
filterOutIcsAttachments(messages),
blocklist,
);
};
@ -46,22 +46,3 @@ const filterOutIcsAttachments = (messages: GmailMessage[]) => {
);
});
};
const isPersonEmail = (email: string): boolean => {
const nonPersonalPattern =
/noreply|no-reply|do_not_reply|no\.reply|^(info@|contact@|hello@|support@|feedback@|service@|help@|invites@|invite@|welcome@|alerts@|team@|notifications@|notification@|news@)/;
return !nonPersonalPattern.test(email);
};
const filterOutNonPersonalEmails = (messages: GmailMessage[]) => {
return messages.filter((message) => {
if (!message.participants) {
return true;
}
return message.participants.every((participant) =>
isPersonEmail(participant.handle),
);
});
};

View File

@ -3,21 +3,21 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import {
FeatureFlagEntity,
FeatureFlagKeys,
} from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { CreateCompanyAndContactService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service';
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
import { MessageParticipantRepository } from 'src/modules/messaging/common/repositories/message-participant.repository';
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { FeatureFlagEntity } from 'src/engine/core-modules/feature-flag/feature-flag.entity';
import { Process } from 'src/engine/integrations/message-queue/decorators/process.decorator';
import { Processor } from 'src/engine/integrations/message-queue/decorators/processor.decorator';
import { MessageQueue } from 'src/engine/integrations/message-queue/message-queue.constants';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { CreateCompanyAndContactService } from 'src/modules/connected-account/auto-companies-and-contacts-creation/services/create-company-and-contact.service';
import { ConnectedAccountRepository } from 'src/modules/connected-account/repositories/connected-account.repository';
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessageChannelRepository } from 'src/modules/messaging/common/repositories/message-channel.repository';
import { MessageParticipantRepository } from 'src/modules/messaging/common/repositories/message-participant.repository';
import {
MessageChannelContactAutoCreationPolicy,
MessageChannelWorkspaceEntity,
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
export type MessagingCreateCompanyAndContactAfterSyncJobData = {
workspaceId: string;
@ -55,10 +55,11 @@ export class MessagingCreateCompanyAndContactAfterSyncJob {
workspaceId,
);
const { isContactAutoCreationEnabled, connectedAccountId } =
messageChannel[0];
const { contactAutoCreationPolicy, connectedAccountId } = messageChannel[0];
if (!isContactAutoCreationEnabled) {
if (
contactAutoCreationPolicy === MessageChannelContactAutoCreationPolicy.NONE
) {
return;
}
@ -73,25 +74,17 @@ export class MessagingCreateCompanyAndContactAfterSyncJob {
);
}
const isContactCreationForSentAndReceivedEmailsEnabledFeatureFlag =
await this.featureFlagRepository.findOneBy({
workspaceId: workspaceId,
key: FeatureFlagKeys.IsContactCreationForSentAndReceivedEmailsEnabled,
value: true,
});
const isContactCreationForSentAndReceivedEmailsEnabled =
isContactCreationForSentAndReceivedEmailsEnabledFeatureFlag?.value;
const contactsToCreate = isContactCreationForSentAndReceivedEmailsEnabled
? await this.messageParticipantRepository.getByMessageChannelIdWithoutPersonIdAndWorkspaceMemberId(
messageChannelId,
workspaceId,
)
: await this.messageParticipantRepository.getByMessageChannelIdWithoutPersonIdAndWorkspaceMemberIdAndMessageOutgoing(
messageChannelId,
workspaceId,
);
const contactsToCreate =
contactAutoCreationPolicy ===
MessageChannelContactAutoCreationPolicy.SENT_AND_RECEIVED
? await this.messageParticipantRepository.getByMessageChannelIdWithoutPersonIdAndWorkspaceMemberId(
messageChannelId,
workspaceId,
)
: await this.messageParticipantRepository.getByMessageChannelIdWithoutPersonIdAndWorkspaceMemberIdAndMessageOutgoing(
messageChannelId,
workspaceId,
);
await this.createCompanyAndContactService.createCompaniesAndContactsAndUpdateParticipants(
connectedAccount,

View File

@ -0,0 +1,6 @@
export const isGroupEmail = (email: string): boolean => {
const isGroupPattern =
/noreply|no-reply|do_not_reply|no\.reply|^(info@|contact@|hello@|support@|feedback@|service@|help@|invites@|invite@|welcome@|alerts@|team@|notifications@|notification@|news@)/;
return isGroupPattern.test(email);
};