6655 remove field direction in message and add it in mcma (#6743)

Closes #6655 
- Remove direction from message
- Add direction do mcma
- Create migration command
- Create upgrade 0.24
This commit is contained in:
Raphaël Bosi
2024-08-27 19:11:04 +02:00
committed by GitHub
parent 5ce1e6b07d
commit e771793626
26 changed files with 358 additions and 2346 deletions

View File

@ -0,0 +1,4 @@
export enum MessageDirection {
INCOMING = 'INCOMING',
OUTGOING = 'OUTGOING',
}

View File

@ -10,8 +10,12 @@ import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import {
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS,
MESSAGE_STANDARD_FIELD_IDS,
} from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
import { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum';
import { MessageChannelWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
@ -48,6 +52,30 @@ export class MessageChannelMessageAssociationWorkspaceEntity extends BaseWorkspa
@WorkspaceIsNullable()
messageThreadExternalId: string | null;
@WorkspaceField({
standardId: MESSAGE_STANDARD_FIELD_IDS.direction,
type: FieldMetadataType.SELECT,
label: 'Direction',
description: 'Message Direction',
icon: 'IconDirection',
options: [
{
value: MessageDirection.INCOMING,
label: 'Incoming',
position: 0,
color: 'green',
},
{
value: MessageDirection.OUTGOING,
label: 'Outgoing',
position: 1,
color: 'blue',
},
],
defaultValue: MessageDirection.INCOMING,
})
direction: MessageDirection;
@WorkspaceRelation({
standardId:
MESSAGE_CHANNEL_MESSAGE_ASSOCIATION_STANDARD_FIELD_IDS.messageChannel,

View File

@ -40,20 +40,6 @@ export class MessageWorkspaceEntity extends BaseWorkspaceEntity {
})
headerMessageId: string;
@WorkspaceField({
standardId: MESSAGE_STANDARD_FIELD_IDS.direction,
type: FieldMetadataType.SELECT,
label: 'Direction',
description: 'Message Direction',
icon: 'IconDirection',
options: [
{ value: 'incoming', label: 'Incoming', position: 0, color: 'green' },
{ value: 'outgoing', label: 'Outgoing', position: 1, color: 'blue' },
],
defaultValue: "'incoming'",
})
direction: string;
@WorkspaceField({
standardId: MESSAGE_STANDARD_FIELD_IDS.subject,
type: FieldMetadataType.TEXT,

View File

@ -1,4 +1,5 @@
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
import { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum';
export const computeMessageDirection = (
fromHandle: string,
@ -6,8 +7,8 @@ export const computeMessageDirection = (
ConnectedAccountWorkspaceEntity,
'handle' | 'handleAliases'
>,
): 'outgoing' | 'incoming' =>
): MessageDirection =>
connectedAccount.handle === fromHandle ||
connectedAccount.handleAliases?.includes(fromHandle)
? 'outgoing'
: 'incoming';
? MessageDirection.OUTGOING
: MessageDirection.INCOMING;

View File

@ -104,7 +104,6 @@ export class MessagingMessageService {
headerMessageId: message.headerMessageId,
subject: message.subject,
receivedAt: message.receivedAt,
direction: message.direction,
text: message.text,
messageThreadId: newOrExistingMessageThreadId,
},
@ -119,6 +118,7 @@ export class MessagingMessageService {
messageId: newMessageId,
messageExternalId: message.externalId,
messageThreadExternalId: message.messageThreadExternalId,
direction: message.direction,
},
transactionManager,
);

View File

@ -1,3 +1,4 @@
import { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { MessageWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message.workspace-entity';
@ -16,6 +17,7 @@ export type Message = Omit<
}[];
externalId: string;
messageThreadExternalId: string;
direction: MessageDirection;
};
export type MessageParticipant = Omit<

View File

@ -11,6 +11,7 @@ import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
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 { CreateCompanyAndContactService } from 'src/modules/contact-creation-manager/services/create-company-and-contact.service';
import { MessageDirection } from 'src/modules/messaging/common/enums/message-direction.enum';
import {
MessageChannelContactAutoCreationPolicy,
MessageChannelWorkspaceEntity,
@ -81,16 +82,16 @@ export class MessagingCreateCompanyAndContactAfterSyncJob {
const directionFilter =
contactAutoCreationPolicy ===
MessageChannelContactAutoCreationPolicy.SENT_AND_RECEIVED
? Any(['incoming', 'outgoing'])
: 'outgoing';
? Any([MessageDirection.INCOMING, MessageDirection.OUTGOING])
: MessageDirection.OUTGOING;
const contactsToCreate = await messageParticipantRepository.find({
where: {
message: {
messageChannelMessageAssociations: {
messageChannelId,
direction: directionFilter,
},
direction: directionFilter,
},
personId: IsNull(),
workspaceMemberId: IsNull(),