Skip to content

Commit

Permalink
Fixed messages sent in duplicate. (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Utar94 authored Jun 26, 2024
1 parent 0144aec commit 372a8b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

namespace Logitar.Portal.Application.Messages.Commands;

public record SendEmailCommand(ActorId ActorId, MessageAggregate Message, SenderAggregate Sender) : INotification;
public record SendEmailCommand(ActorId ActorId, MessageAggregate Message, SenderAggregate Sender) : IRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ namespace Logitar.Portal.Application.Messages.Commands;
internal class SendMessageInternalCommandHandler : IRequestHandler<SendMessageInternalCommand, SentMessages>
{
private readonly IDictionaryRepository _dictionaryRepository;
private readonly IMediator _mediator;
private readonly IMessageRepository _messageRepository;
private readonly ISender _sender;
private readonly ISenderRepository _senderRepository;
private readonly ITemplateRepository _templateRepository;
private readonly IUserRepository _userRepository;

public SendMessageInternalCommandHandler(IDictionaryRepository dictionaryRepository, IMediator mediator, IMessageRepository messageRepository,
public SendMessageInternalCommandHandler(IDictionaryRepository dictionaryRepository, IMessageRepository messageRepository, ISender sender,
ISenderRepository senderRepository, ITemplateRepository templateRepository, IUserRepository userRepository)
{
_dictionaryRepository = dictionaryRepository;
_mediator = mediator;
_messageRepository = messageRepository;
_sender = sender;
_senderRepository = senderRepository;
_templateRepository = templateRepository;
_userRepository = userRepository;
Expand Down Expand Up @@ -67,13 +67,13 @@ public async Task<SentMessages> Handle(SendMessageInternalCommand command, Cance

SubjectUnit subject = new(dictionaries.Translate(template.Subject.Value));
LocaleUnit? locale = dictionaries.Target?.Locale ?? dictionaries.Default?.Locale;
ContentUnit body = await _mediator.Send(new CompileTemplateCommand(id, template, dictionaries, locale, recipient.User, variables), cancellationToken);
ContentUnit body = await _sender.Send(new CompileTemplateCommand(id, template, dictionaries, locale, recipient.User, variables), cancellationToken);
IReadOnlyCollection<RecipientUnit> recipients = [recipient, .. allRecipients.CC, .. allRecipients.Bcc];

MessageAggregate message = new(subject, body, recipients, sender, template, ignoreUserLocale, locale, variableDictionary, payload.IsDemo, tenantId, actorId, id);
messages.Add(message);

await _mediator.Publish(new SendEmailCommand(actorId, message, sender), cancellationToken);
await _sender.Send(new SendEmailCommand(actorId, message, sender), cancellationToken);
}
await _messageRepository.SaveAsync(messages, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Logitar.Portal.Infrastructure.Messages.Commands;

internal class SendEmailCommandHandler : INotificationHandler<SendEmailCommand>
internal class SendEmailCommandHandler : IRequestHandler<SendEmailCommand>
{
private readonly JsonSerializerOptions _serializerOptions;

Expand Down

0 comments on commit 372a8b0

Please sign in to comment.