don't try to parse empty qrJson on add from text

This commit is contained in:
LenAnderson
2024-07-23 11:40:23 -04:00
parent 3b2dcd60da
commit 80879e0c51

View File

@@ -241,22 +241,26 @@ export class QuickReplySet {
} }
addQuickReplyFromText(qrJson) { addQuickReplyFromText(qrJson) {
let data; let data;
try { if (qrJson) {
data = JSON.parse(qrJson ?? '{}'); try {
delete data.id; data = JSON.parse(qrJson ?? '{}');
} catch { delete data.id;
// not JSON data } catch {
} // not JSON data
if (data) { }
// JSON data if (data) {
if (data.label === undefined || data.message === undefined) { // JSON data
// not a QR if (data.label === undefined || data.message === undefined) {
toastr.error('Not a QR.'); // not a QR
return; toastr.error('Not a QR.');
return;
}
} else {
// no JSON, use plaintext as QR message
data = { message: qrJson };
} }
} else { } else {
// no JSON, use plaintext as QR message data = {};
data = { message: qrJson };
} }
const newQr = this.addQuickReply(data); const newQr = this.addQuickReply(data);
return newQr; return newQr;