{"version":3,"file":"discourse-restore-pm-mentions.js","names":["define","_exports","_pluginApi","_service","_template","initWithApi","api","container","lookup","restore_pm_mentions_enabled","modifyClass","pluginId","didInsertElement","_this2","this","_super","arguments","originalWarn","_warnCannotSeeMention","bind","Object","defineProperty","value","warnedCannotSeeMentions","push","writable","configurable","dialog","inject","save","_len","length","args","Array","_key","_this","currentUser","staff","mentioned","$","each","group","text","toLowerCase","trim","confirm","message","htmlSafe","I18n","t","shouldDisplayCancel","confirmButtonLabel","confirmButtonClass","didConfirm","call","cancelButtonLabel","cancelButtonClass","didCancel","default","name","initialize","withPluginApi"],"sources":["discourse/plugins/discourse-restore-pm-mentions/discourse/initializers/restore-admin-mentions.js"],"sourcesContent":["define(\"discourse/plugins/discourse-restore-pm-mentions/discourse/initializers/restore-admin-mentions\", [\"exports\", \"discourse/lib/plugin-api\", \"@ember/service\", \"@ember/template\"], function (_exports, _pluginApi, _service, _template) {\n  \"use strict\";\n\n  Object.defineProperty(_exports, \"__esModule\", {\n    value: true\n  });\n  _exports.default = void 0;\n  function initWithApi(api) {\n    const siteSettings = api.container.lookup(\"site-settings:main\");\n    if (!siteSettings.restore_pm_mentions_enabled) return;\n\n    // the plugin allows mentioning @admins but we get a warning for that, so we must suppress it\n    // for some reason we are unable to override controller:composer cannotSeeMention()\n    // so we resort to overriding this one and add admins to the list of stuff we've already warned for\n    // this effectively suppresses the warning\n\n    // Since Discourse 3.4 that method does not work anymore\n    // it yields \"Uncaught (in promise) TypeError: \"_warnCannotSeeMention\" is read-only\"\n    // Luckily enough, a good friend suggested this workaround\n    // \"you can try modifying the method before it's used\"\n\n    api.modifyClass(\"component:composer-editor\", {\n      pluginId: \"discourse-restore-pm-mentions\",\n      didInsertElement() {\n        var _this2 = this;\n        this._super(...arguments);\n        let originalWarn = this._warnCannotSeeMention.bind(this);\n        Object.defineProperty(this, \"_warnCannotSeeMention\", {\n          value: function () {\n            _this2.warnedCannotSeeMentions.push(\"admins\");\n            _this2.warnedCannotSeeMentions.push(\"administrators\");\n            return originalWarn(...arguments);\n          },\n          writable: false,\n          configurable: true // Allow future modifications\n        });\n      }\n    });\n    api.modifyClass(\"controller:composer\", {\n      pluginId: \"discourse-restore-pm-mentions\",\n      dialog: (0, _service.inject)(),\n      save() {\n        for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {\n          args[_key] = arguments[_key];\n        }\n        const _this = this;\n        const _super = this._super;\n        if (this.currentUser.staff) {\n          return this._super(...args);\n        }\n        let mentioned = 0;\n        $(\".d-editor-preview a.mention-group\").each(function () {\n          const group = $(this).text().toLowerCase().trim();\n          if (group === \"@admins\" || group === \"@administrators\") {\n            mentioned++;\n          }\n        });\n        if (!mentioned) {\n          return this._super(...args);\n        }\n        this.dialog.confirm({\n          message: (0, _template.htmlSafe)(I18n.t(\"restore_pm_mentions.alert\")),\n          shouldDisplayCancel: false,\n          confirmButtonLabel: \"restore_pm_mentions.proceed\",\n          confirmButtonClass: \"btn-danger\",\n          didConfirm: () => {\n            return _super.call(_this, ...args);\n          },\n          cancelButtonLabel: \"restore_pm_mentions.back\",\n          cancelButtonClass: \"btn-default\",\n          didCancel: () => {\n            // cancel\n          }\n        });\n      }\n    });\n  }\n  var _default = _exports.default = {\n    name: \"restore-admin-mentions\",\n    initialize() {\n      (0, _pluginApi.withPluginApi)(\"0.8\", initWithApi);\n    }\n  };\n});"],"mappings":"AAAAA,OAAA,mLAAAC,EAAAC,EAAAC,EAAAC,GACA;AAMA,SAAAC,EAAAC,GACAA,EAAAC,UAAAC,OAAA,sBACAC,8BAYAH,EAAAI,YAAA,6BACAC,SAAA,gCACA,gBAAAC,GACA,IAAAC,EAAAC;AACAA,KAAAC,UAAAC;AACA,IAAAC,EAAAH,KAAAI,sBAAAC,KAAAL;AACAM,OAAAC,eAAAP,KAAA,yBACAQ,MAAA,WAGA,OAFAT,EAAAU,wBAAAC,KAAA,UACAX,EAAAU,wBAAAC,KAAA,kBACAP,KAAAD,UACA,EACAS,UAAA,EACAC,c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