2021-01-11 12:04:41 +00:00
|
|
|
# TODO: lets move this to active job, since thats what we use over all
|
2020-03-01 13:36:13 +00:00
|
|
|
class ConversationReplyEmailWorker
|
2020-01-23 17:29:07 +00:00
|
|
|
include Sidekiq::Worker
|
|
|
|
sidekiq_options queue: :mailers
|
|
|
|
|
2021-10-14 07:25:46 +00:00
|
|
|
def perform(conversation_id, last_queued_id)
|
2020-01-23 17:29:07 +00:00
|
|
|
@conversation = Conversation.find(conversation_id)
|
|
|
|
|
|
|
|
# send the email
|
2021-10-14 07:25:46 +00:00
|
|
|
if @conversation.messages.incoming&.last&.content_type == 'incoming_email'
|
|
|
|
ConversationReplyMailer.with(account: @conversation.account).reply_without_summary(@conversation, last_queued_id).deliver_later
|
2020-07-15 11:03:52 +00:00
|
|
|
else
|
2021-10-14 07:25:46 +00:00
|
|
|
ConversationReplyMailer.with(account: @conversation.account).reply_with_summary(@conversation, last_queued_id).deliver_later
|
2020-07-15 11:03:52 +00:00
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
|
|
|
|
# delete the redis set from the first new message on the conversation
|
|
|
|
Redis::Alfred.delete(conversation_mail_key)
|
|
|
|
end
|
2020-07-07 18:44:07 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-17 17:13:32 +00:00
|
|
|
def email_inbox?
|
|
|
|
@conversation.inbox&.inbox_type == 'Email'
|
|
|
|
end
|
|
|
|
|
2020-07-07 18:44:07 +00:00
|
|
|
def conversation_mail_key
|
|
|
|
format(::Redis::Alfred::CONVERSATION_MAILER_KEY, conversation_id: @conversation.id)
|
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|