Fix duplicateQrSet Fixes #4364

c8b02dfd6841806da07507be2a53d745dc717648

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +7 -3Ignore whitespace
public/scripts/extensions/quick-reply/src/QuickReplySet.js+4 -0
@@ -9,6 +9,10 @@ import { QuickReply } from './QuickReply.js';
9export class QuickReplySet {9export class QuickReplySet {
10 /**@type {QuickReplySet[]}*/ static list = [];10 /**@type {QuickReplySet[]}*/ static list = [];
1111
12 /**
13 * @param {Partial<QuickReplySet>} props
14 * @returns {QuickReplySet}
15 */
12 static from(props) {16 static from(props) {
13 props.qrList = []; //props.qrList?.map(it=>QuickReply.from(it));17 props.qrList = []; //props.qrList?.map(it=>QuickReply.from(it));
14 const instance = Object.assign(new this(), props);18 const instance = Object.assign(new this(), props);
public/scripts/extensions/quick-reply/src/ui/SettingsUi.js+3 -3
@@ -470,10 +470,10 @@ export class SettingsUi {
470 toastr.error(`A Quick Reply Set named "${newName}" already exists.`);470 toastr.error(`A Quick Reply Set named "${newName}" already exists.`);
471 return;471 return;
472 }472 }
473 const newQrSet = QuickReplySet.from(JSON.parse(JSON.stringify(this.currentQrSet)));473 const newQrSet = QuickReplySet.from(this.currentQrSet.toJSON());
474 newQrSet.name = newName;474 newQrSet.name = newName;
475 newQrSet.qrList = this.currentQrSet.qrList.map(qr => QuickReply.from(JSON.parse(JSON.stringify(qr))));475 newQrSet.qrList = this.currentQrSet.qrList.map(qr => QuickReply.from(qr.toJSON()));
476 newQrSet.addQuickReply();476 newQrSet.init();
477 const idx = QuickReplySet.list.findIndex(it => it.name.toLowerCase().localeCompare(newName.toLowerCase()) == 1);477 const idx = QuickReplySet.list.findIndex(it => it.name.toLowerCase().localeCompare(newName.toLowerCase()) == 1);
478 if (idx > -1) {478 if (idx > -1) {
479 QuickReplySet.list.splice(idx, 0, newQrSet);479 QuickReplySet.list.splice(idx, 0, newQrSet);