fix: Email notifications (#8502)
This commit is contained in:
@@ -19,36 +19,36 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
|
|||||||
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
||||||
end
|
end
|
||||||
|
|
||||||
def conversation_mention(message, agent)
|
def conversation_mention(conversation, agent, message)
|
||||||
return unless smtp_config_set_or_development?
|
return unless smtp_config_set_or_development?
|
||||||
|
|
||||||
@agent = agent
|
@agent = agent
|
||||||
@conversation = message.conversation
|
@conversation = conversation
|
||||||
@message = message
|
@message = message
|
||||||
subject = "#{@agent.available_name}, You have been mentioned in conversation [ID - #{@conversation.display_id}]"
|
subject = "#{@agent.available_name}, You have been mentioned in conversation [ID - #{@conversation.display_id}]"
|
||||||
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
||||||
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
||||||
end
|
end
|
||||||
|
|
||||||
def assigned_conversation_new_message(message, agent)
|
def assigned_conversation_new_message(conversation, agent, message)
|
||||||
return unless smtp_config_set_or_development?
|
return unless smtp_config_set_or_development?
|
||||||
# Don't spam with email notifications if agent is online
|
# Don't spam with email notifications if agent is online
|
||||||
return if ::OnlineStatusTracker.get_presence(message.account_id, 'User', agent.id)
|
return if ::OnlineStatusTracker.get_presence(message.account_id, 'User', agent.id)
|
||||||
|
|
||||||
@agent = agent
|
@agent = agent
|
||||||
@conversation = message.conversation
|
@conversation = conversation
|
||||||
subject = "#{@agent.available_name}, New message in your assigned conversation [ID - #{@conversation.display_id}]."
|
subject = "#{@agent.available_name}, New message in your assigned conversation [ID - #{@conversation.display_id}]."
|
||||||
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
||||||
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
||||||
end
|
end
|
||||||
|
|
||||||
def participating_conversation_new_message(message, agent)
|
def participating_conversation_new_message(conversation, agent, message)
|
||||||
return unless smtp_config_set_or_development?
|
return unless smtp_config_set_or_development?
|
||||||
# Don't spam with email notifications if agent is online
|
# Don't spam with email notifications if agent is online
|
||||||
return if ::OnlineStatusTracker.get_presence(message.account_id, 'User', agent.id)
|
return if ::OnlineStatusTracker.get_presence(message.account_id, 'User', agent.id)
|
||||||
|
|
||||||
@agent = agent
|
@agent = agent
|
||||||
@conversation = message.conversation
|
@conversation = conversation
|
||||||
subject = "#{@agent.available_name}, New message in your participating conversation [ID - #{@conversation.display_id}]."
|
subject = "#{@agent.available_name}, New message in your participating conversation [ID - #{@conversation.display_id}]."
|
||||||
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
@action_url = app_account_conversation_url(account_id: @conversation.account_id, id: @conversation.display_id)
|
||||||
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
send_mail_with_liquid(to: @agent.email, subject: subject) and return
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class Notification::EmailNotificationService
|
|||||||
# TODO : Clean up whatever happening over here
|
# TODO : Clean up whatever happening over here
|
||||||
# Segregate the mailers properly
|
# Segregate the mailers properly
|
||||||
AgentNotifications::ConversationNotificationsMailer.with(account: notification.account).public_send(notification
|
AgentNotifications::ConversationNotificationsMailer.with(account: notification.account).public_send(notification
|
||||||
.notification_type.to_s, notification.primary_actor, notification.user).deliver_now
|
.notification_type.to_s, notification.primary_actor, notification.user, notification.secondary_actor).deliver_later
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do
|
|||||||
let(:contact) { create(:contact, name: nil, account: account) }
|
let(:contact) { create(:contact, name: nil, account: account) }
|
||||||
let(:another_agent) { create(:user, email: 'agent2@example.com', account: account) }
|
let(:another_agent) { create(:user, email: 'agent2@example.com', account: account) }
|
||||||
let(:message) { create(:message, conversation: conversation, account: account, sender: another_agent) }
|
let(:message) { create(:message, conversation: conversation, account: account, sender: another_agent) }
|
||||||
let(:mail) { described_class.with(account: account).conversation_mention(message, agent).deliver_now }
|
let(:mail) { described_class.with(account: account).conversation_mention(conversation, agent, message).deliver_now }
|
||||||
let(:contact_inbox) { create(:contact_inbox, account: account, inbox: conversation.inbox) }
|
let(:contact_inbox) { create(:contact_inbox, account: account, inbox: conversation.inbox) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@@ -72,7 +72,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do
|
|||||||
|
|
||||||
describe 'assigned_conversation_new_message' do
|
describe 'assigned_conversation_new_message' do
|
||||||
let(:message) { create(:message, conversation: conversation, account: account) }
|
let(:message) { create(:message, conversation: conversation, account: account) }
|
||||||
let(:mail) { described_class.with(account: account).assigned_conversation_new_message(message, agent).deliver_now }
|
let(:mail) { described_class.with(account: account).assigned_conversation_new_message(conversation, agent, message).deliver_now }
|
||||||
|
|
||||||
it 'renders the subject' do
|
it 'renders the subject' do
|
||||||
expect(mail.subject).to eq("#{agent.available_name}, New message in your assigned conversation [ID - #{message.conversation.display_id}].")
|
expect(mail.subject).to eq("#{agent.available_name}, New message in your assigned conversation [ID - #{message.conversation.display_id}].")
|
||||||
@@ -90,7 +90,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do
|
|||||||
|
|
||||||
describe 'participating_conversation_new_message' do
|
describe 'participating_conversation_new_message' do
|
||||||
let(:message) { create(:message, conversation: conversation, account: account) }
|
let(:message) { create(:message, conversation: conversation, account: account) }
|
||||||
let(:mail) { described_class.with(account: account).participating_conversation_new_message(message, agent).deliver_now }
|
let(:mail) { described_class.with(account: account).participating_conversation_new_message(conversation, agent, message).deliver_now }
|
||||||
|
|
||||||
it 'renders the subject' do
|
it 'renders the subject' do
|
||||||
expect(mail.subject).to eq("#{agent.available_name}, New message in your participating conversation [ID - #{message.conversation.display_id}].")
|
expect(mail.subject).to eq("#{agent.available_name}, New message in your participating conversation [ID - #{message.conversation.display_id}].")
|
||||||
|
|||||||
Reference in New Issue
Block a user