2019-03-27 17:41:50 +08:00
|
|
|
import DropdownSelectBox from "select-kit/components/dropdown-select-box";
|
2023-07-25 09:04:28 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2020-02-03 21:22:14 +08:00
|
|
|
import { computed } from "@ember/object";
|
2019-03-27 17:41:50 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2023-07-25 09:04:28 +08:00
|
|
|
import IgnoreDurationModal from "discourse/components/modal/ignore-duration-with-username";
|
2019-03-27 17:41:50 +08:00
|
|
|
|
|
|
|
export default DropdownSelectBox.extend({
|
2023-07-25 09:04:28 +08:00
|
|
|
modal: service(),
|
|
|
|
|
2019-03-27 17:41:50 +08:00
|
|
|
classNames: ["user-notifications", "user-notifications-dropdown"],
|
2019-07-31 22:31:02 +08:00
|
|
|
|
2020-02-03 21:22:14 +08:00
|
|
|
selectKitOptions: {
|
2022-07-19 10:27:10 +08:00
|
|
|
headerIcon: "userNotificationIcon",
|
2021-02-05 23:30:36 +08:00
|
|
|
showCaret: true,
|
2020-02-03 21:22:14 +08:00
|
|
|
},
|
|
|
|
|
2022-07-19 10:27:10 +08:00
|
|
|
userNotificationIcon: computed("mainCollection.[]", "value", function () {
|
2020-02-03 21:22:14 +08:00
|
|
|
return (
|
|
|
|
this.mainCollection &&
|
|
|
|
this.mainCollection.find((row) => row.id === this.value).icon
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
|
|
|
|
content: computed(function () {
|
2019-03-27 17:41:50 +08:00
|
|
|
const content = [];
|
|
|
|
|
|
|
|
content.push({
|
|
|
|
icon: "user",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToNormal",
|
|
|
|
description: I18n.t("user.user_notifications.normal_option_title"),
|
2020-02-03 21:22:14 +08:00
|
|
|
name: I18n.t("user.user_notifications.normal_option"),
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
content.push({
|
|
|
|
icon: "times-circle",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToMuted",
|
|
|
|
description: I18n.t("user.user_notifications.mute_option_title"),
|
2020-02-03 21:22:14 +08:00
|
|
|
name: I18n.t("user.user_notifications.mute_option"),
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
if (this.get("user.can_ignore_user")) {
|
|
|
|
content.push({
|
2020-01-07 01:27:20 +08:00
|
|
|
icon: "far-eye-slash",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToIgnored",
|
|
|
|
description: I18n.t("user.user_notifications.ignore_option_title"),
|
2020-02-03 21:22:14 +08:00
|
|
|
name: I18n.t("user.user_notifications.ignore_option"),
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
2020-02-03 21:22:14 +08:00
|
|
|
}),
|
2019-07-31 22:31:02 +08:00
|
|
|
|
2019-03-29 18:14:53 +08:00
|
|
|
changeToNormal() {
|
2022-03-09 12:51:30 +08:00
|
|
|
this.updateNotificationLevel({ level: "normal" }).catch(popupAjaxError);
|
2019-03-29 18:14:53 +08:00
|
|
|
},
|
|
|
|
changeToMuted() {
|
2022-03-09 12:51:30 +08:00
|
|
|
this.updateNotificationLevel({ level: "mute" }).catch(popupAjaxError);
|
2019-03-29 18:14:53 +08:00
|
|
|
},
|
|
|
|
changeToIgnored() {
|
2023-07-25 09:04:28 +08:00
|
|
|
this.modal.show(IgnoreDurationModal, {
|
|
|
|
model: {
|
|
|
|
ignoredUsername: this.user.username,
|
|
|
|
enableSelection: false,
|
|
|
|
},
|
2019-03-29 18:14:53 +08:00
|
|
|
});
|
2019-07-31 22:31:02 +08:00
|
|
|
},
|
|
|
|
|
2019-03-27 17:41:50 +08:00
|
|
|
actions: {
|
2020-02-03 21:22:14 +08:00
|
|
|
onChange(level) {
|
2019-03-29 18:14:53 +08:00
|
|
|
this[level]();
|
2020-02-03 21:22:14 +08:00
|
|
|
|
|
|
|
// hack but model.ignored/muted is not
|
|
|
|
// getting updated after updateNotificationLevel
|
|
|
|
this.set("value", level);
|
2019-03-27 17:41:50 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|