{"version":3,"file":"discourse-perspective-api.js","names":["define","_exports","_templateFactory","Object","defineProperty","value","default","_default","createTemplateFactory","id","block","moduleName","isStrictMode","_pluginApi","_ajax","_I18n","_service","initialize","api","siteSettings","container","lookup","modifyClass","pluginId","_perspective_checked","dialog","inject","perspectiveSave","force","this","set","result","save","then","finally","perspective_enabled","_super","arguments","disableSubmit","showWarning","composer","model","cantSubmitPost","Date","now","bypassPM","perspective_check_private_message","get","bypassSecuredCategories","perspective_check_secured_categories","perspectiveCheckToxicity","concat","forEach","item","content","trim","ajax","type","data","response","undefined","confirm","confirmButtonLabel","confirmButtonClass","didConfirm","isDestroying","isDestroyed","message","t","cancelButtonLabel","cancelButtonClass","didCancel","catch","name","perspective_notify_posting_min_toxicity_enable","withPluginApi"],"sources":["discourse/plugins/discourse-perspective-api/discourse/templates/composer/perspective-message.js","discourse/plugins/discourse-perspective-api/initializers/discourse-perspective.js"],"sourcesContent":["define(\"discourse/plugins/discourse-perspective-api/discourse/templates/composer/perspective-message\", [\"exports\", \"@ember/template-factory\"], function (_exports, _templateFactory) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  0; //eaimeta@70e063a35619d71f0,\"ember-cli-htmlbars\"eaimeta@70e063a35619d71f\n  var _default = (0, _templateFactory.createTemplateFactory)(\n  /*\n    <a href {{action \"closeMessage\"}} class=\"close\">{{d-icon \"close\"}}</a>\n  \n  <h3>{{i18n \"perspective.perspective_messages\"}}</h3>\n  \n  <div class=\"messages\">\n    <p>{{i18n \"perspective.perspective_warning\"}}</p>\n  </div>\n  */\n  {\n    \"id\": \"OWraz5Zd\",\n    \"block\": \"[[[11,3],[24,6,\\\"\\\"],[24,0,\\\"close\\\"],[4,[38,0],[[30,0],\\\"closeMessage\\\"],null],[12],[1,[28,[35,1],[\\\"close\\\"],null]],[13],[1,\\\"\\\\n\\\\n\\\"],[10,\\\"h3\\\"],[12],[1,[28,[35,2],[\\\"perspective.perspective_messages\\\"],null]],[13],[1,\\\"\\\\n\\\\n\\\"],[10,0],[14,0,\\\"messages\\\"],[12],[1,\\\"\\\\n  \\\"],[10,2],[12],[1,[28,[35,2],[\\\"perspective.perspective_warning\\\"],null]],[13],[1,\\\"\\\\n\\\"],[13]],[],false,[\\\"action\\\",\\\"d-icon\\\",\\\"i18n\\\"]]\",\n    \"moduleName\": \"discourse/plugins/discourse-perspective-api/discourse/templates/composer/perspective-message.hbs\",\n    \"isStrictMode\": false\n  });\n  _exports.default = _default;\n});","define(\"discourse/plugins/discourse-perspective-api/initializers/discourse-perspective\", [\"exports\", \"discourse/lib/plugin-api\", \"discourse/lib/ajax\", \"I18n\", \"@ember/service\"], function (_exports, _pluginApi, _ajax, _I18n, _service) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  0; //eaimeta@70e063a35619d71f0,\"discourse/lib/plugin-api\",0,\"discourse/lib/ajax\",0,\"I18n\",0,\"@ember/service\"eaimeta@70e063a35619d71f\n  function initialize(api) {\n    const siteSettings = api.container.lookup(\"site-settings:main\");\n    api.modifyClass(\"controller:composer\", {\n      pluginId: \"discourse-perspective-api\",\n      _perspective_checked: null,\n      dialog: (0, _service.inject)(),\n      perspectiveSave(force) {\n        this.set(\"_perspective_checked\", true);\n        const result = this.save(force);\n\n        // it's valid for save() to return null since we do that in core,\n        // handle that here because sometimes we return a promise\n        if (result != null && typeof result.then === \"function\") {\n          result.finally(() => {\n            this.set(\"disableSubmit\", false);\n            this.set(\"_perspective_checked\", false);\n          });\n        } else {\n          this.set(\"disableSubmit\", false);\n          this.set(\"_perspective_checked\", false);\n        }\n      },\n      save(force) {\n        if (!this.siteSettings.perspective_enabled) {\n          return this._super(...arguments);\n        }\n\n        // same validation code from controller\n        if (this.disableSubmit && !this._perspective_checked) {\n          return;\n        }\n        if (!this.showWarning) {\n          this.set(\"model.isWarning\", false);\n        }\n        const composer = this.model;\n        if (composer.cantSubmitPost) {\n          this.set(\"lastValidatedAt\", Date.now());\n          return;\n        } else {\n          // disable composer submit during perspective validation\n          this.set(\"disableSubmit\", true);\n        }\n        const bypassPM = !siteSettings.perspective_check_private_message && this.get(\"topic.isPrivateMessage\");\n        const bypassSecuredCategories = !siteSettings.perspective_check_secured_categories && this.get(\"model.category.read_restricted\");\n        const bypassCheck = bypassPM || bypassSecuredCategories;\n        if (!bypassCheck && !this._perspective_checked) {\n          return this.perspectiveCheckToxicity(composer, force);\n        } else {\n          this.set(\"disableSubmit\", false);\n          return this._super(force);\n        }\n      },\n      perspectiveCheckToxicity(composer, force) {\n        let concat = \"\";\n        [\"title\", \"raw\", \"reply\"].forEach(item => {\n          const content = composer.get(item);\n          if (content) {\n            concat += `${content} `;\n          }\n        });\n        concat.trim();\n        return (0, _ajax.ajax)(\"/perspective/post_toxicity\", {\n          type: \"POST\",\n          data: {\n            concat\n          }\n        }).then(response => {\n          if (response && response[\"score\"] !== undefined) {\n            this.dialog.confirm({\n              confirmButtonLabel: \"perspective.composer_edit\",\n              confirmButtonClass: \"btn-primary perspective-edit-post\",\n              didConfirm: () => {\n                if (this.isDestroying || this.isDestroyed) {\n                  return;\n                }\n                this.set(\"disableSubmit\", false);\n              },\n              message: _I18n.default.t(\"perspective.perspective_message\"),\n              cancelButtonLabel: \"perspective.composer_continue\",\n              cancelButtonClass: \"perspective-continue-post\",\n              didCancel: () => this.perspectiveSave(force)\n            });\n            return;\n          } else {\n            this.perspectiveSave(force);\n          }\n        }).catch(() => {\n          // fail silently\n          this.perspectiveSave(force);\n        });\n      }\n    });\n  }\n  var _default = {\n    name: \"discourse-perspective-api\",\n    initialize(container) {\n      const siteSettings = container.lookup(\"site-settings:main\");\n      if (siteSettings.perspective_enabled && siteSettings.perspective_notify_posting_min_toxicity_enable) {\n        (0, _pluginApi.withPluginApi)(\"0.8.17\", initialize);\n      }\n    }\n  };\n  _exports.default = _default;\n});"],"mappings":"AAAAA,OAAA,+IAAAC,EAAAC,GACA;AAE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