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
|
|
|
|
|
|
|
|
def perform(conversation_id, queued_time)
|
|
|
|
@conversation = Conversation.find(conversation_id)
|
|
|
|
|
|
|
|
# send the email
|
2020-07-15 11:03:52 +00:00
|
|
|
if @conversation.messages.incoming&.last&.content_type == 'incoming_email'
|
|
|
|
ConversationReplyMailer.reply_without_summary(@conversation, queued_time).deliver_later
|
|
|
|
else
|
|
|
|
ConversationReplyMailer.reply_with_summary(@conversation, queued_time).deliver_later
|
|
|
|
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
|
|
|
|
|
|
|
|
def conversation_mail_key
|
|
|
|
format(::Redis::Alfred::CONVERSATION_MAILER_KEY, conversation_id: @conversation.id)
|
|
|
|
end
|
2020-01-23 17:29:07 +00:00
|
|
|
end
|