mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 20:18:08 +00:00
feat: Add messages on mute / unmute actions (#1373)
This commit is contained in:
@@ -87,10 +87,12 @@ class Conversation < ApplicationRecord
|
|||||||
def mute!
|
def mute!
|
||||||
resolved!
|
resolved!
|
||||||
Redis::Alfred.setex(mute_key, 1, mute_period)
|
Redis::Alfred.setex(mute_key, 1, mute_period)
|
||||||
|
create_muted_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def unmute!
|
def unmute!
|
||||||
Redis::Alfred.delete(mute_key)
|
Redis::Alfred.delete(mute_key)
|
||||||
|
create_unmuted_message
|
||||||
end
|
end
|
||||||
|
|
||||||
def muted?
|
def muted?
|
||||||
@@ -248,6 +250,24 @@ class Conversation < ApplicationRecord
|
|||||||
messages.create(activity_message_params(content))
|
messages.create(activity_message_params(content))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_muted_message
|
||||||
|
return unless Current.user
|
||||||
|
|
||||||
|
params = { user_name: Current.user.name }
|
||||||
|
content = I18n.t('conversations.activity.muted', **params)
|
||||||
|
|
||||||
|
messages.create(activity_message_params(content))
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_unmuted_message
|
||||||
|
return unless Current.user
|
||||||
|
|
||||||
|
params = { user_name: Current.user.name }
|
||||||
|
content = I18n.t('conversations.activity.unmuted', **params)
|
||||||
|
|
||||||
|
messages.create(activity_message_params(content))
|
||||||
|
end
|
||||||
|
|
||||||
def mute_key
|
def mute_key
|
||||||
format('CONVERSATION::%<id>d::MUTED', id: id)
|
format('CONVERSATION::%<id>d::MUTED', id: id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -54,6 +54,8 @@ en:
|
|||||||
labels:
|
labels:
|
||||||
added: "%{user_name} added %{labels}"
|
added: "%{user_name} added %{labels}"
|
||||||
removed: "%{user_name} removed %{labels}"
|
removed: "%{user_name} removed %{labels}"
|
||||||
|
muted: "%{user_name} has muted the conversation"
|
||||||
|
unmuted: "%{user_name} has unmuted the conversation"
|
||||||
templates:
|
templates:
|
||||||
greeting_message_body: "%{account_name} typically replies in a few hours."
|
greeting_message_body: "%{account_name} typically replies in a few hours."
|
||||||
ways_to_reach_you_message_body: "Give the team a way to reach you."
|
ways_to_reach_you_message_body: "Give the team a way to reach you."
|
||||||
|
|||||||
@@ -276,8 +276,14 @@ RSpec.describe Conversation, type: :model do
|
|||||||
describe '#mute!' do
|
describe '#mute!' do
|
||||||
subject(:mute!) { conversation.mute! }
|
subject(:mute!) { conversation.mute! }
|
||||||
|
|
||||||
|
let(:user) do
|
||||||
|
create(:user, email: 'agent2@example.com', account: create(:account), role: :agent)
|
||||||
|
end
|
||||||
|
|
||||||
let(:conversation) { create(:conversation) }
|
let(:conversation) { create(:conversation) }
|
||||||
|
|
||||||
|
before { Current.user = user }
|
||||||
|
|
||||||
it 'marks conversation as resolved' do
|
it 'marks conversation as resolved' do
|
||||||
mute!
|
mute!
|
||||||
expect(conversation.reload.resolved?).to eq(true)
|
expect(conversation.reload.resolved?).to eq(true)
|
||||||
@@ -287,13 +293,24 @@ RSpec.describe Conversation, type: :model do
|
|||||||
mute!
|
mute!
|
||||||
expect(Redis::Alfred.get(conversation.send(:mute_key))).not_to eq(nil)
|
expect(Redis::Alfred.get(conversation.send(:mute_key))).not_to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates mute message' do
|
||||||
|
mute!
|
||||||
|
expect(conversation.messages.pluck(:content)).to include("#{user.name} has muted the conversation")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#unmute!' do
|
describe '#unmute!' do
|
||||||
subject(:unmute!) { conversation.unmute! }
|
subject(:unmute!) { conversation.unmute! }
|
||||||
|
|
||||||
|
let(:user) do
|
||||||
|
create(:user, email: 'agent2@example.com', account: create(:account), role: :agent)
|
||||||
|
end
|
||||||
|
|
||||||
let(:conversation) { create(:conversation).tap(&:mute!) }
|
let(:conversation) { create(:conversation).tap(&:mute!) }
|
||||||
|
|
||||||
|
before { Current.user = user }
|
||||||
|
|
||||||
it 'does not change conversation status' do
|
it 'does not change conversation status' do
|
||||||
expect { unmute! }.not_to(change { conversation.reload.status })
|
expect { unmute! }.not_to(change { conversation.reload.status })
|
||||||
end
|
end
|
||||||
@@ -303,6 +320,11 @@ RSpec.describe Conversation, type: :model do
|
|||||||
.to change { Redis::Alfred.get(conversation.send(:mute_key)) }
|
.to change { Redis::Alfred.get(conversation.send(:mute_key)) }
|
||||||
.to nil
|
.to nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'creates unmute message' do
|
||||||
|
unmute!
|
||||||
|
expect(conversation.messages.pluck(:content)).to include("#{user.name} has unmuted the conversation")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#muted?' do
|
describe '#muted?' do
|
||||||
|
|||||||
Reference in New Issue
Block a user