fix: Prevent CC/BCC field reset on chat activity actions (#11342)
# Pull Request Template ## Description This PR fixes the CC/BCC field reset issue on activity action. Fixes [CW-4256](https://linear.app/chatwoot/issue/CW-4256/emails-added-in-cc-and-bcc-disappears-when-you-click-on-assign-to-me), #5234 ### Cause of the Issue Previously, the CC and BCC fields in the reply box were being reset whenever a conversation activity occurred (such as assignment, status change, etc.). This happened because watchers on the current chat messages array and current chat object would trigger `setCCAndToEmailsFromLastChat` even when the last message was an activity or system message, not a real email. ### Solution - The updated logic ensures that the CC and BCC fields are only set under the following conditions: **1**. Switching to a new conversation. **2**. In the same conversation, only if the last message is not an activity (i.e., only for actual emails). - It uses the `lastEmail` computed property, which filters out private and activity messages, ensuring only real email context changes update the fields. - This prevents user-entered `CC/BCC` values from being cleared after system events (e.g., assignments or status changes), while still updating the fields correctly when relevant messages are received. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? ### Loom video **Before** https://www.loom.com/share/2ec50dd1c0ed4eaf9170465274bea41e?sid=cc8b88cb-fd39-473a-8df3-78a242c8407b **After** https://www.loom.com/share/17fd2d96d5d84a049dcbf20d401d2ada?sid=8949ad48-7769-49d2-92c5-267da8c60d6e ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
This commit is contained in:
@@ -388,9 +388,14 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
currentChat(conversation) {
|
currentChat(conversation, oldConversation) {
|
||||||
const { can_reply: canReply } = conversation;
|
const { can_reply: canReply } = conversation;
|
||||||
this.setCCAndToEmailsFromLastChat();
|
if (oldConversation && oldConversation.id !== conversation.id) {
|
||||||
|
// Only update email fields when switching to a completely different conversation (by ID)
|
||||||
|
// This prevents overwriting user input (e.g., CC/BCC fields) when performing actions
|
||||||
|
// like self-assign or other updates that do not actually change the conversation context
|
||||||
|
this.setCCAndToEmailsFromLastChat();
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isOnPrivateNote) {
|
if (this.isOnPrivateNote) {
|
||||||
return;
|
return;
|
||||||
@@ -406,13 +411,12 @@ export default {
|
|||||||
},
|
},
|
||||||
// When moving from one conversation to another, the store may not have the
|
// When moving from one conversation to another, the store may not have the
|
||||||
// list of all the messages. A fetch is subsequently made to get the messages.
|
// list of all the messages. A fetch is subsequently made to get the messages.
|
||||||
// However, this update does not trigger the `currentChat` watcher.
|
// This watcher handles two main cases:
|
||||||
// We can add a deep watcher to it, but then, that would be too broad of a net to cast
|
// 1. When switching conversations and messages are fetched/updated, ensures CC/BCC fields are set from the latest OUTGOING/INCOMING email (not activity/private messages).
|
||||||
// And would impact performance too. So we watch the messages directly.
|
// 2. Fixes and issue where CC/BCC fields could be reset/lost after assignment/activity actions or message mutations that did not represent a true email context change.
|
||||||
// The watcher here is `deep` too, because the messages array is mutated and
|
lastEmail: {
|
||||||
// not replaced. So, a shallow watcher would not catch the change.
|
handler(lastEmail) {
|
||||||
'currentChat.messages': {
|
if (!lastEmail) return;
|
||||||
handler() {
|
|
||||||
this.setCCAndToEmailsFromLastChat();
|
this.setCCAndToEmailsFromLastChat();
|
||||||
},
|
},
|
||||||
deep: true,
|
deep: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user