fix: Add correct thread message_id to the email message (#1659)
Co-authored-by: Sojan <sojan@pepalo.com>
This commit is contained in:
@@ -37,7 +37,7 @@ class Channel::Email < ApplicationRecord
|
||||
private
|
||||
|
||||
def ensure_forward_to_address
|
||||
# TODO : implement better logic here
|
||||
self.forward_to_address ||= "#{SecureRandom.hex}@xyc.com"
|
||||
email_domain = InstallationConfig.find_by(name: 'MAILER_INBOUND_EMAIL_DOMAIN')&.value
|
||||
self.forward_to_address ||= "#{SecureRandom.hex}@#{email_domain}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -128,8 +128,7 @@ class Message < ApplicationRecord
|
||||
private
|
||||
|
||||
def execute_after_create_commit_callbacks
|
||||
# rails issue with order of active record callbacks being executed
|
||||
# https://github.com/rails/rails/issues/20911
|
||||
# rails issue with order of active record callbacks being executed https://github.com/rails/rails/issues/20911
|
||||
set_conversation_activity
|
||||
dispatch_create_events
|
||||
send_reply
|
||||
@@ -169,8 +168,7 @@ class Message < ApplicationRecord
|
||||
|
||||
def can_notify_via_mail?
|
||||
return unless email_notifiable_message?
|
||||
return false if conversation.contact.email.blank?
|
||||
return false unless %w[Website Email].include? inbox.inbox_type
|
||||
return false if conversation.contact.email.blank? || !(%w[Website Email].include? inbox.inbox_type)
|
||||
|
||||
true
|
||||
end
|
||||
@@ -178,10 +176,19 @@ class Message < ApplicationRecord
|
||||
def notify_via_mail
|
||||
return unless can_notify_via_mail?
|
||||
|
||||
# set a redis key for the conversation so that we don't need to send email for every new message
|
||||
trigger_notify_via_mail
|
||||
end
|
||||
|
||||
def trigger_notify_via_mail
|
||||
# will set a redis key for the conversation so that we don't need to send email for every new message
|
||||
# last few messages coupled together is sent every 2 minutes rather than one email for each message
|
||||
if Redis::Alfred.get(conversation_mail_key).nil?
|
||||
Redis::Alfred.setex(conversation_mail_key, Time.zone.now)
|
||||
# if redis key exists there is an unprocessed job that will take care of delivering the email
|
||||
return if Redis::Alfred.get(conversation_mail_key).present?
|
||||
|
||||
Redis::Alfred.setex(conversation_mail_key, Time.zone.now)
|
||||
if inbox.inbox_type == 'Email'
|
||||
ConversationReplyEmailWorker.perform_in(2.seconds, conversation.id, Time.zone.now)
|
||||
else
|
||||
ConversationReplyEmailWorker.perform_in(2.minutes, conversation.id, Time.zone.now)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user