3369 rename messagerecipients table into messageparticipants (#3457)
* renaming * renaming
This commit is contained in:
@ -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(
|
||||
|
||||
@ -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,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user