Skip to content

Commit

Permalink
fix: Email notifications (#8502)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Dec 6, 2023
1 parent db33b7d commit 6b0d1d7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Expand Up @@ -19,36 +19,36 @@ def conversation_assignment(conversation, agent)
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
Expand Down
2 changes: 1 addition & 1 deletion app/services/notification/email_notification_service.rb
Expand Up @@ -9,7 +9,7 @@ def perform
# 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
Expand Down
Expand Up @@ -42,7 +42,7 @@
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
Expand Down Expand Up @@ -72,7 +72,7 @@

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}].")
Expand All @@ -90,7 +90,7 @@

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}].")
Expand Down

0 comments on commit 6b0d1d7

Please sign in to comment.