fix: Email notifications (#8502)

This commit is contained in:
Muhsin Keloth
2023-12-06 15:50:23 +05:30
committed by GitHub
parent db33b7d1dc
commit 6b0d1d77d3
3 changed files with 10 additions and 10 deletions

View File

@@ -19,36 +19,36 @@ class AgentNotifications::ConversationNotificationsMailer < ApplicationMailer
send_mail_with_liquid(to: @agent.email, subject: subject) and return
end
def conversation_mention(message, agent)
def conversation_mention(conversation, agent, message)
return unless smtp_config_set_or_development?
@agent = agent
@conversation = message.conversation
@conversation = conversation
@message = message
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)
send_mail_with_liquid(to: @agent.email, subject: subject) and return
end
def assigned_conversation_new_message(message, agent)
def assigned_conversation_new_message(conversation, agent, message)
return unless smtp_config_set_or_development?
# Don't spam with email notifications if agent is online
return if ::OnlineStatusTracker.get_presence(message.account_id, 'User', agent.id)
@agent = agent
@conversation = message.conversation
@conversation = conversation
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)
send_mail_with_liquid(to: @agent.email, subject: subject) and return
end
def participating_conversation_new_message(message, agent)
def participating_conversation_new_message(conversation, agent, message)
return unless smtp_config_set_or_development?
# Don't spam with email notifications if agent is online
return if ::OnlineStatusTracker.get_presence(message.account_id, 'User', agent.id)
@agent = agent
@conversation = message.conversation
@conversation = conversation
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)
send_mail_with_liquid(to: @agent.email, subject: subject) and return

View File

@@ -9,7 +9,7 @@ class Notification::EmailNotificationService
# TODO : Clean up whatever happening over here
# Segregate the mailers properly
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
private

View File

@@ -42,7 +42,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do
let(:contact) { create(:contact, name: nil, 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(: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) }
before do
@@ -72,7 +72,7 @@ RSpec.describe AgentNotifications::ConversationNotificationsMailer do
describe 'assigned_conversation_new_message' do
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
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
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
expect(mail.subject).to eq("#{agent.available_name}, New message in your participating conversation [ID - #{message.conversation.display_id}].")