discourse/app/assets/javascripts/select-kit/addon/components/email-group-user-chooser.js
Osama Sayegh db7b7eed9d
FIX: Restore support for pasting multiple PM recipients (#11945)
This is a regression from 98201ecc24.

Meta topic: https://meta.discourse.org/t/-/178167?u=osama.

Signed-off-by: OsamaSayegh <asooomaasoooma90@gmail.com>
2021-02-03 18:06:16 +03:00

48 lines
1.3 KiB
JavaScript

import UserChooserComponent from "select-kit/components/user-chooser";
export default UserChooserComponent.extend({
pluginApiIdentifiers: ["email-group-user-chooser"],
classNames: ["email-group-user-chooser"],
valueProperty: "id",
nameProperty: "name",
modifyComponentForRow() {
return "email-group-user-chooser-row";
},
selectKitOptions: {
headerComponent: "email-group-user-chooser-header",
filterComponent: "email-group-user-chooser-filter",
autoWrap: false,
},
search() {
const superPromise = this._super(...arguments);
if (!superPromise) {
return;
}
return superPromise.then((results) => {
if (!results || results.length === 0) {
return;
}
return results.map((item) => {
const reconstructed = {};
if (item.username) {
reconstructed.id = item.username;
if (item.username.includes("@")) {
reconstructed.isEmail = true;
} else {
reconstructed.isUser = true;
reconstructed.name = item.name;
}
} else if (item.name) {
reconstructed.id = item.name;
reconstructed.name = item.full_name;
reconstructed.isGroup = true;
}
return Object.assign({}, item, reconstructed);
});
});
},
});