fix: canned responses not working when signature is present (#8176)

Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
Shivam Mishra
2023-10-26 11:35:46 +05:30
committed by GitHub
parent 736f269c49
commit d02cfff4cc

View File

@@ -532,17 +532,25 @@ export default {
} }
}, },
message(updatedMessage) { message(updatedMessage) {
this.hasSlashCommand = // Check if the message starts with a slash.
updatedMessage[0] === '/' && !this.showRichContentEditor; const bodyWithoutSignature = removeSignature(
const hasNextWord = updatedMessage.includes(' '); updatedMessage,
const isShortCodeActive = this.hasSlashCommand && !hasNextWord; this.signatureToApply
if (isShortCodeActive) { );
this.mentionSearchKey = updatedMessage.substring(1); const startsWithSlash = bodyWithoutSignature.startsWith('/');
this.showMentions = true;
} else { // Determine if the user is potentially typing a slash command.
this.mentionSearchKey = ''; // This is true if the message starts with a slash and the rich content editor is not active.
this.showMentions = false; this.hasSlashCommand = startsWithSlash && !this.showRichContentEditor;
} this.showMentions = this.hasSlashCommand;
// If a slash command is active, extract the command text after the slash.
// If not, reset the mentionSearchKey.
this.mentionSearchKey = this.hasSlashCommand
? bodyWithoutSignature.substring(1)
: '';
// Autosave the current message draft.
this.doAutoSaveDraft(); this.doAutoSaveDraft();
}, },
replyType(updatedReplyType, oldReplyType) { replyType(updatedReplyType, oldReplyType) {
@@ -820,10 +828,18 @@ export default {
this.hideWhatsappTemplatesModal(); this.hideWhatsappTemplatesModal();
}, },
replaceText(message) { replaceText(message) {
if (this.sendWithSignature && !this.private) {
// if signature is enabled, append it to the message
// appendSignature ensures that the signature is not duplicated
// so we don't need to check if the signature is already present
message = appendSignature(message, this.signatureToApply);
}
const updatedMessage = replaceVariablesInMessage({ const updatedMessage = replaceVariablesInMessage({
message, message,
variables: this.messageVariables, variables: this.messageVariables,
}); });
setTimeout(() => { setTimeout(() => {
this.$track(CONVERSATION_EVENTS.INSERTED_A_CANNED_RESPONSE); this.$track(CONVERSATION_EVENTS.INSERTED_A_CANNED_RESPONSE);
this.message = updatedMessage; this.message = updatedMessage;