3369 rename messagerecipients table into messageparticipants (#3457)

* renaming

* renaming
This commit is contained in:
bosiraphael 2024-01-15 16:55:19 +01:00 committed by GitHub
parent 8682f3c0c0
commit 4695e99458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 85 additions and 85 deletions

View File

@ -9,7 +9,7 @@ export enum CoreObjectNameSingular {
Favorite = 'favorite',
Message = 'message',
MessageChannel = 'messageChannel',
MessageRecipient = 'messageRecipient',
MessageParticipant = 'messageParticipant',
MessageThread = 'messageThread',
Opportunity = 'opportunity',
Person = 'person',

View File

@ -244,9 +244,9 @@ export const graphqlMocks = {
edges: mockWorkspaceMembers.map((member) => ({
node: {
...member,
messageRecipients: {
messageParticipants: {
edges: [],
__typename: 'MessageRecipientConnection',
__typename: 'MessageParticipantConnection',
},
authoredAttachments: {
edges: [],

View File

@ -82,9 +82,9 @@ export const mockedPeopleMetadata = {
__typename: 'field',
id: 'c606dfb1-a24c-4f9b-b626-0df1c845e6e8',
type: 'RELATION',
name: 'messageRecipients',
label: 'Message Recipients',
description: 'Message Recipients',
name: 'messageParticipants',
label: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
isCustom: false,
isActive: true,
@ -100,8 +100,8 @@ export const mockedPeopleMetadata = {
__typename: 'object',
id: 'dd41deae-84d5-4a66-8947-260b0c72677c',
dataSourceId: 'cabbcaa6-05d6-41f4-920f-9144172a4f08',
nameSingular: 'messageRecipient',
namePlural: 'messageRecipients',
nameSingular: 'messageParticipant',
namePlural: 'messageParticipants',
},
toFieldMetadataId: '88ab56e5-828e-4fb2-a37c-314b8803f361',
},
@ -1883,17 +1883,17 @@ export const mockedFavoritesMetadata = {
},
};
export const mockedMessageRecipientsMetadata = {
export const mockedMessageParticipantsMetadata = {
__typename: 'objectEdge',
node: {
__typename: 'object',
id: 'dd41deae-84d5-4a66-8947-260b0c72677c',
dataSourceId: 'cabbcaa6-05d6-41f4-920f-9144172a4f08',
nameSingular: 'messageRecipient',
namePlural: 'messageRecipients',
labelSingular: 'Message Recipient',
labelPlural: 'Message Recipients',
description: 'Message Recipients',
nameSingular: 'messageParticipant',
namePlural: 'messageParticipants',
labelSingular: 'Message Participant',
labelPlural: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
isCustom: false,
isActive: true,
@ -3144,9 +3144,9 @@ export const mockedWorkspaceMembersMetadata = {
__typename: 'field',
id: 'f13cce91-5f98-4eb0-8c6e-c1cf41ad168f',
type: 'RELATION',
name: 'messageRecipients',
label: 'Message Recipients',
description: 'Message Recipients',
name: 'messageParticipants',
label: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
isCustom: false,
isActive: true,
@ -3162,8 +3162,8 @@ export const mockedWorkspaceMembersMetadata = {
__typename: 'object',
id: 'dd41deae-84d5-4a66-8947-260b0c72677c',
dataSourceId: 'cabbcaa6-05d6-41f4-920f-9144172a4f08',
nameSingular: 'messageRecipient',
namePlural: 'messageRecipients',
nameSingular: 'messageParticipant',
namePlural: 'messageParticipants',
},
toFieldMetadataId: '22883ca2-34e2-40ab-9e7b-fde5836cb5d2',
},
@ -3927,9 +3927,9 @@ export const mockedMessagesMetadata = {
__typename: 'field',
id: '9c58971b-4e40-4f49-b125-ff014f909744',
type: 'RELATION',
name: 'messageRecipients',
label: 'Message Recipients',
description: 'Message Recipients',
name: 'messageParticipants',
label: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
isCustom: false,
isActive: true,
@ -3945,8 +3945,8 @@ export const mockedMessagesMetadata = {
__typename: 'object',
id: 'dd41deae-84d5-4a66-8947-260b0c72677c',
dataSourceId: 'cabbcaa6-05d6-41f4-920f-9144172a4f08',
nameSingular: 'messageRecipient',
namePlural: 'messageRecipients',
nameSingular: 'messageParticipant',
namePlural: 'messageParticipants',
},
toFieldMetadataId: '663612f4-7eb8-4b21-886e-730f3b047ee7',
},

View File

@ -28,8 +28,8 @@ export class TimelineMessagingService {
last_message_subject,
last_message_body,
last_message_received_at,
last_message_recipient_handle,
last_message_recipient_displayName
last_message_participant_handle,
last_message_participant_displayName
FROM (
SELECT
mt.*,
@ -37,15 +37,15 @@ export class TimelineMessagingService {
FIRST_VALUE(m."subject") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_subject,
FIRST_VALUE(m."body") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_body,
FIRST_VALUE(m."receivedAt") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_received_at,
FIRST_VALUE(mr."handle") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_recipient_handle,
FIRST_VALUE(mr."displayName") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_recipient_displayName,
FIRST_VALUE(mr."handle") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_participant_handle,
FIRST_VALUE(mr."displayName") OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS last_message_participant_displayName,
ROW_NUMBER() OVER (PARTITION BY mt."id" ORDER BY m."receivedAt" DESC) AS rn
FROM
${dataSourceMetadata.schema}."messageThread" mt
LEFT JOIN
${dataSourceMetadata.schema}."message" m ON mt."id" = m."messageThreadId"
LEFT JOIN
${dataSourceMetadata.schema}."messageRecipient" mr ON m."id" = mr."messageId"
${dataSourceMetadata.schema}."messageParticipant" mr ON m."id" = mr."messageId"
WHERE
mr."personId" IN (SELECT unnest($1::uuid[]))
) AS subquery
@ -61,7 +61,7 @@ export class TimelineMessagingService {
const formattedMessageThreads = messageThreads.map((messageThread) => {
return {
read: true,
senderName: messageThread.last_message_recipient_handle,
senderName: messageThread.last_message_participant_handle,
senderPictureUrl: '',
numberOfMessagesInThread: messageThread.message_count,
subject: messageThread.last_message_subject,

View File

@ -5,7 +5,7 @@ import { simpleParser, AddressObject } from 'mailparser';
import {
GmailMessage,
Recipient,
Participant,
} from 'src/workspace/messaging/types/gmailMessage';
import { MessageQuery } from 'src/workspace/messaging/types/messageOrThreadQuery';
import { GmailMessageParsedResponse } from 'src/workspace/messaging/types/gmailMessageParsedResponse';
@ -190,11 +190,11 @@ export class FetchMessagesByBatchesService {
if (!from) throw new Error('From value is missing');
if (!to) throw new Error('To value is missing');
const recipients = [
...this.formatAddressObjectAsRecipients(from, 'from'),
...this.formatAddressObjectAsRecipients(to, 'to'),
...this.formatAddressObjectAsRecipients(cc, 'cc'),
...this.formatAddressObjectAsRecipients(bcc, 'bcc'),
const participants = [
...this.formatAddressObjectAsParticipants(from, 'from'),
...this.formatAddressObjectAsParticipants(to, 'to'),
...this.formatAddressObjectAsParticipants(cc, 'cc'),
...this.formatAddressObjectAsParticipants(bcc, 'bcc'),
];
const messageFromGmail: GmailMessage = {
@ -206,7 +206,7 @@ export class FetchMessagesByBatchesService {
internalDate,
fromHandle: from.value[0].address || '',
fromDisplayName: from.value[0].name || '',
recipients,
participants,
text: text || '',
html: html || '',
attachments,
@ -234,14 +234,14 @@ export class FetchMessagesByBatchesService {
return Array.isArray(addressObject) ? addressObject : [addressObject];
}
formatAddressObjectAsRecipients(
formatAddressObjectAsParticipants(
addressObject: AddressObject | AddressObject[] | undefined,
role: 'from' | 'to' | 'cc' | 'bcc',
): Recipient[] {
): Participant[] {
if (!addressObject) return [];
const addressObjects = this.formatAddressObjectAsArray(addressObject);
const recipients = addressObjects.map((addressObject) => {
const participants = addressObjects.map((addressObject) => {
const emailAdresses = addressObject.value;
return emailAdresses.map((emailAddress) => {
@ -255,7 +255,7 @@ export class FetchMessagesByBatchesService {
});
});
return recipients.flat();
return participants.flat();
}
async formatBatchResponsesAsGmailMessages(

View File

@ -8,7 +8,7 @@ import { DataSourceService } from 'src/metadata/data-source/data-source.service'
import { DataSourceEntity } from 'src/metadata/data-source/data-source.entity';
import {
GmailMessage,
Recipient,
Participant,
} from 'src/workspace/messaging/types/gmailMessage';
import { GmailThread } from 'src/workspace/messaging/types/gmailThread';
import { MessageQuery } from 'src/workspace/messaging/types/messageOrThreadQuery';
@ -79,7 +79,7 @@ export class MessagingUtilsService {
internalDate,
fromHandle,
fromDisplayName,
recipients,
participants,
text,
} = message;
@ -127,7 +127,7 @@ export class MessagingUtilsService {
);
await manager.query(
`INSERT INTO ${dataSourceMetadata.schema}."messageRecipient" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
`INSERT INTO ${dataSourceMetadata.schema}."messageParticipant" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
[
messageId,
'from',
@ -138,8 +138,8 @@ export class MessagingUtilsService {
],
);
await this.saveMessageRecipients(
recipients,
await this.saveMessageParticipants(
participants,
dataSourceMetadata,
messageId,
manager,
@ -148,40 +148,40 @@ export class MessagingUtilsService {
}
}
public async saveMessageRecipients(
recipients: Recipient[],
public async saveMessageParticipants(
participants: Participant[],
dataSourceMetadata: DataSourceEntity,
messageId: string,
manager: EntityManager,
): Promise<void> {
if (!recipients) return;
if (!participants) return;
for (const recipient of recipients) {
const recipientPerson = await manager.query(
for (const participant of participants) {
const participantPerson = await manager.query(
`SELECT * FROM ${dataSourceMetadata.schema}."person" WHERE "email" = $1`,
[recipient.handle],
[participant.handle],
);
const recipientPersonId = recipientPerson[0]?.id;
const participantPersonId = participantPerson[0]?.id;
const workspaceMember = await manager.query(
`SELECT "workspaceMember"."id" FROM ${dataSourceMetadata.schema}."workspaceMember"
JOIN ${dataSourceMetadata.schema}."connectedAccount" ON ${dataSourceMetadata.schema}."workspaceMember"."id" = ${dataSourceMetadata.schema}."connectedAccount"."accountOwnerId"
WHERE ${dataSourceMetadata.schema}."connectedAccount"."handle" = $1`,
[recipient.handle],
[participant.handle],
);
const recipientWorkspaceMemberId = workspaceMember[0]?.id;
const participantWorkspaceMemberId = workspaceMember[0]?.id;
await manager.query(
`INSERT INTO ${dataSourceMetadata.schema}."messageRecipient" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
`INSERT INTO ${dataSourceMetadata.schema}."messageParticipant" ("messageId", "role", "handle", "displayName", "personId", "workspaceMemberId") VALUES ($1, $2, $3, $4, $5, $6)`,
[
messageId,
recipient.role,
recipient.handle,
recipient.displayName,
recipientPersonId,
recipientWorkspaceMemberId,
participant.role,
participant.handle,
participant.displayName,
participantPersonId,
participantWorkspaceMemberId,
],
);
}

View File

@ -9,13 +9,13 @@ export type GmailMessage = {
internalDate: string;
fromHandle: string;
fromDisplayName: string;
recipients: Recipient[];
participants: Participant[];
text: string;
html: string;
attachments: Attachment[];
};
export type Recipient = {
export type Participant = {
role: 'from' | 'to' | 'cc' | 'bcc';
handle: string;
displayName: string;

View File

@ -7,7 +7,7 @@ import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/sta
import { ConnectedAccountObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata';
import { FavoriteObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata';
import { MessageChannelObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-channel.object-metadata';
import { MessageRecipientObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata';
import { MessageParticipantObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-participant.object-metadata';
import { MessageThreadObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata';
import { MessageObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message.object-metadata';
import { OpportunityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata';
@ -41,5 +41,5 @@ export const standardObjectMetadata = [
MessageThreadObjectMetadata,
MessageObjectMetadata,
MessageChannelObjectMetadata,
MessageRecipientObjectMetadata,
MessageParticipantObjectMetadata,
];

View File

@ -10,17 +10,17 @@ import { PersonObjectMetadata } from 'src/workspace/workspace-sync-metadata/stan
import { WorkspaceMemberObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/workspace-member.object-metadata';
@ObjectMetadata({
namePlural: 'messageRecipients',
labelSingular: 'Message Recipient',
labelPlural: 'Message Recipients',
description: 'Message Recipients',
namePlural: 'messageParticipants',
labelSingular: 'Message Participant',
labelPlural: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
})
@Gate({
featureFlag: 'IS_MESSAGING_ENABLED',
})
@IsSystem()
export class MessageRecipientObjectMetadata extends BaseObjectMetadata {
export class MessageParticipantObjectMetadata extends BaseObjectMetadata {
@FieldMetadata({
type: FieldMetadataType.RELATION,
label: 'Message',

View File

@ -7,7 +7,7 @@ import { IsSystem } from 'src/workspace/workspace-sync-metadata/decorators/is-sy
import { ObjectMetadata } from 'src/workspace/workspace-sync-metadata/decorators/object-metadata.decorator';
import { RelationMetadata } from 'src/workspace/workspace-sync-metadata/decorators/relation-metadata.decorator';
import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata';
import { MessageRecipientObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata';
import { MessageParticipantObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-participant.object-metadata';
import { MessageThreadObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-thread.object-metadata';
@ObjectMetadata({
@ -90,15 +90,15 @@ export class MessageObjectMetadata extends BaseObjectMetadata {
@FieldMetadata({
type: FieldMetadataType.RELATION,
label: 'Message Recipients',
description: 'Message Recipients',
label: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
})
@RelationMetadata({
type: RelationMetadataType.ONE_TO_MANY,
objectName: 'messageRecipient',
objectName: 'messageParticipant',
inverseSideFieldName: 'message',
})
@IsNullable()
messageRecipients: MessageRecipientObjectMetadata[];
messageParticipants: MessageParticipantObjectMetadata[];
}

View File

@ -13,7 +13,7 @@ import { AttachmentObjectMetadata } from 'src/workspace/workspace-sync-metadata/
import { BaseObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/base.object-metadata';
import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata';
import { FavoriteObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata';
import { MessageRecipientObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata';
import { MessageParticipantObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-participant.object-metadata';
import { OpportunityObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/opportunity.object-metadata';
@ObjectMetadata({
@ -176,18 +176,18 @@ export class PersonObjectMetadata extends BaseObjectMetadata {
@FieldMetadata({
type: FieldMetadataType.RELATION,
label: 'Message Recipients',
description: 'Message Recipients',
label: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
})
@RelationMetadata({
type: RelationMetadataType.ONE_TO_MANY,
objectName: 'messageRecipient',
objectName: 'messageParticipant',
inverseSideFieldName: 'person',
})
@Gate({
featureFlag: 'IS_MESSAGING_ENABLED',
})
@IsNullable()
messageRecipients: MessageRecipientObjectMetadata[];
messageParticipants: MessageParticipantObjectMetadata[];
}

View File

@ -14,7 +14,7 @@ import { CommentObjectMetadata } from 'src/workspace/workspace-sync-metadata/sta
import { CompanyObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/company.object-metadata';
import { ConnectedAccountObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/connected-account.object-metadata';
import { FavoriteObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/favorite.object-metadata';
import { MessageRecipientObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-recipient.object-metadata';
import { MessageParticipantObjectMetadata } from 'src/workspace/workspace-sync-metadata/standard-objects/message-participant.object-metadata';
@ObjectMetadata({
namePlural: 'workspaceMembers',
@ -178,18 +178,18 @@ export class WorkspaceMemberObjectMetadata extends BaseObjectMetadata {
@FieldMetadata({
type: FieldMetadataType.RELATION,
label: 'Message Recipients',
description: 'Message Recipients',
label: 'Message Participants',
description: 'Message Participants',
icon: 'IconUserCircle',
})
@RelationMetadata({
type: RelationMetadataType.ONE_TO_MANY,
objectName: 'messageRecipient',
objectName: 'messageParticipant',
inverseSideFieldName: 'workspaceMember',
})
@Gate({
featureFlag: 'IS_MESSAGING_ENABLED',
})
@IsNullable()
messageRecipients: MessageRecipientObjectMetadata[];
messageParticipants: MessageParticipantObjectMetadata[];
}