# Improved participant matching with additional emails support Closes #8991 This PR extends the participant matching system to support additional emails in addition to primary emails for both calendar events and messages. Previously, the system only matched participants based on primary emails, missing matches with secondary email addresses. - Contact creation now consider both primary and additional emails when checking for existing contacts - Calendar and message participant listeners now handle both primary and additional email changes - Added tests ## To test this PR: Check that: - Primary emails take precedence over additional emails in matching - Case-insensitive email comparisons work correctly - A contact is not created if a person already exists with the email as its additional email - Event listeners handle both creation and update scenarios - Matching and unmatching logic works for complex email change scenarios - When unmatching after a change in a primary or secondary email, events and messages should be rematched if another person has this email as its primary or secondary email. --------- Co-authored-by: guillim <guigloo@msn.com>
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import { WorkspaceEntityManager } from 'src/engine/twenty-orm/entity-manager/workspace-entity-manager';
|
|
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
|
import { MatchParticipantService } from 'src/modules/match-participant/match-participant.service';
|
|
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
|
import { ParticipantWithMessageId } from 'src/modules/messaging/message-import-manager/drivers/gmail/types/gmail-message.type';
|
|
|
|
@Injectable()
|
|
export class MessagingMessageParticipantService {
|
|
constructor(
|
|
private readonly twentyORMManager: TwentyORMManager,
|
|
private readonly matchParticipantService: MatchParticipantService<MessageParticipantWorkspaceEntity>,
|
|
) {}
|
|
|
|
public async saveMessageParticipants(
|
|
participants: ParticipantWithMessageId[],
|
|
transactionManager?: WorkspaceEntityManager,
|
|
): Promise<void> {
|
|
const messageParticipantRepository =
|
|
await this.twentyORMManager.getRepository<MessageParticipantWorkspaceEntity>(
|
|
'messageParticipant',
|
|
);
|
|
|
|
const savedParticipants = await messageParticipantRepository.save(
|
|
participants.map((participant) => {
|
|
return {
|
|
messageId: participant.messageId,
|
|
role: participant.role,
|
|
handle: participant.handle,
|
|
displayName: participant.displayName,
|
|
};
|
|
}),
|
|
{},
|
|
transactionManager,
|
|
);
|
|
|
|
await this.matchParticipantService.matchParticipants({
|
|
participants: savedParticipants,
|
|
objectMetadataName: 'messageParticipant',
|
|
transactionManager,
|
|
});
|
|
}
|
|
}
|