Merge pull request #3121 from ceruleandeep/fix/handleIdForQRMenuAdd Wire up id= parameter for /qr-context*

2384031d09cfb3f362161f3ed8fcdfd6df2d5df2

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

Signed
1 files changed, +28 -15Ignore whitespace
public/scripts/extensions/quick-reply/src/SlashCommandHandler.js+28 -15
@@ -419,30 +419,35 @@ export class SlashCommandHandler {
419419 namedArgumentList: [
420420 SlashCommandNamedArgument.fromProps({
421421 name: 'set',
422422 description: 'Name of QR set nameto add the context menu to',
423423 typeList: [ARGUMENT_TYPE.STRING],
424424 isRequired: true,
425425 enumProvider: localEnumProviders.qrSets,
426426 }),
427427 SlashCommandNamedArgument.fromProps({
428428 name: 'label',
429429 description: 'Label of Quick Reply labelto add the context menu to',
430430 typeList: [ARGUMENT_TYPE.STRING],
431431 enumProvider: localEnumProviders.qrEntries,
432432 }),
433433 SlashCommandNamedArgument.fromProps({
434434 name: 'id',
435435 description: 'numericNumeric ID of Quick Reply to add the QRcontext menu to, e.g., id=42',
436436 typeList: [ARGUMENT_TYPE.NUMBER],
437437 enumProvider: localEnumProviders.qrIds,
438438 }),
439439 new SlashCommandNamedArgument(
440- 'chain', 'boolean', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false',
440+ 'chain',
441+ 'If true, button QR is sent together with (before) the clicked QR from the context menu',
442+ [ARGUMENT_TYPE.BOOLEAN],
443+ false,
444+ false,
445+ 'false',
441446 ),
442447 ],
443448 unnamedArgumentList: [
444449 SlashCommandArgument.fromProps({
445450 description: 'Name of QR set nameto add as a context menu',
446451 typeList: [ARGUMENT_TYPE.STRING],
447452 isRequired: true,
448453 enumProvider: localEnumProviders.qrSets,
@@ -450,13 +455,16 @@ export class SlashCommandHandler {
450455 ],
451456 helpString: `
452457 <div>
453458 Add a context menu preset to a QR.
459+ </div>
460+ <div>
461+ If <code>id</code> and <code>label</code> are both provided, <code>id</code> will be used.
454462 </div>
455463 <div>
456464 <strong>Example:</strong>
457465 <ul>
458466 <li>
459467 <pre><code>/qr-contextadd set=MyPresetMyQRSetWithTheButton label=MyButton chain=true MyOtherPresetMyQRSetWithContextItems</code></pre>
460468 </li>
461469 </ul>
462470 </div>
@@ -470,27 +478,27 @@ export class SlashCommandHandler {
470478 namedArgumentList: [
471479 SlashCommandNamedArgument.fromProps({
472480 name: 'set',
473481 description: 'Name of QR set nameto remove the context menu from',
474482 typeList: [ARGUMENT_TYPE.STRING],
475483 isRequired: true,
476484 enumProvider: localEnumProviders.qrSets,
477485 }),
478486 SlashCommandNamedArgument.fromProps({
479487 name: 'label',
480488 description: 'Label of Quick Reply labelto remove the context menu from',
481489 typeList: [ARGUMENT_TYPE.STRING],
482490 enumProvider: localEnumProviders.qrEntries,
483491 }),
484492 SlashCommandNamedArgument.fromProps({
485493 name: 'id',
486494 description: 'numericNumeric ID of Quick Reply to remove the QRcontext menu from, e.g., id=42',
487495 typeList: [ARGUMENT_TYPE.NUMBER],
488496 enumProvider: localEnumProviders.qrIds,
489497 }),
490498 ],
491499 unnamedArgumentList: [
492500 SlashCommandArgument.fromProps({
493501 description: 'Name of QR set nameto remove',
494502 typeList: [ARGUMENT_TYPE.STRING],
495503 isRequired: true,
496504 enumProvider: localEnumProviders.qrSets,
@@ -501,6 +509,9 @@ export class SlashCommandHandler {
501509 Remove context menu preset from a QR.
502510 </div>
503511 <div>
512+ If <code>id</code> and <code>label</code> are both provided, <code>id</code> will be used.
513+ </div>
514+ <div>
504515 <strong>Example:</strong>
505516 <ul>
506517 <li>
@@ -542,6 +553,9 @@ export class SlashCommandHandler {
542553 Remove all context menu presets from a QR.
543554 </div>
544555 <div>
556+ If <code>id</code> and a label are both provided, <code>id</code> will be used.
557+ </div>
558+ <div>
545559 <strong>Example:</strong>
546560 <ul>
547561 <li>
@@ -908,12 +922,11 @@ export class SlashCommandHandler {
908922 }
909923 }
910924
911-
912925 createContextItem(args, name) {
913926 try {
914927 this.api.createContextItem(
915928 args.set,
916- args.label,
929+ args.id !== undefined ? Number(args.id) : args.label,
917930 name,
918931 isTrueBoolean(args.chain),
919932 );
@@ -923,14 +936,14 @@ export class SlashCommandHandler {
923936 }
924937 deleteContextItem(args, name) {
925938 try {
926939 this.api.deleteContextItem(args.set, args.id !== undefined ? Number(args.id) : args.label, name);
927940 } catch (ex) {
928941 toastr.error(ex.message);
929942 }
930943 }
931944 clearContextMenu(args, label) {
932945 try {
933946 this.api.clearContextMenu(args.set, args.id !== undefined ? Number(args.id) : args.label ?? label);
934947 } catch (ex) {
935948 toastr.error(ex.message);
936949 }