2024-08-23 19:17:07 +08:00
|
|
|
import { action, computed } from "@ember/object";
|
2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2024-08-23 19:17:07 +08:00
|
|
|
import { classNames } from "@ember-decorators/component";
|
2023-07-25 09:04:28 +08:00
|
|
|
import IgnoreDurationModal from "discourse/components/modal/ignore-duration-with-username";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
2024-11-20 04:45:18 +08:00
|
|
|
import { i18n } from "discourse-i18n";
|
2023-10-11 02:38:59 +08:00
|
|
|
import DropdownSelectBox from "select-kit/components/dropdown-select-box";
|
2024-08-23 19:17:07 +08:00
|
|
|
import { selectKitOptions } from "select-kit/components/select-kit";
|
2019-03-27 17:41:50 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@classNames("user-notifications", "user-notifications-dropdown")
|
|
|
|
@selectKitOptions({
|
|
|
|
headerIcon: "userNotificationIcon",
|
|
|
|
showCaret: true,
|
|
|
|
})
|
|
|
|
export default class UserNotificationsDropdown extends DropdownSelectBox {
|
|
|
|
@service modal;
|
2023-07-25 09:04:28 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@computed("mainCollection.[]", "value")
|
|
|
|
get userNotificationIcon() {
|
2020-02-03 21:22:14 +08:00
|
|
|
return (
|
|
|
|
this.mainCollection &&
|
|
|
|
this.mainCollection.find((row) => row.id === this.value).icon
|
|
|
|
);
|
2024-08-23 19:17:07 +08:00
|
|
|
}
|
2020-02-03 21:22:14 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@computed
|
|
|
|
get content() {
|
2019-03-27 17:41:50 +08:00
|
|
|
const content = [];
|
|
|
|
|
|
|
|
content.push({
|
2024-04-24 22:07:21 +08:00
|
|
|
icon: "bell",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToNormal",
|
2024-11-20 04:45:18 +08:00
|
|
|
description: i18n("user.user_notifications.normal_option_title"),
|
|
|
|
name: i18n("user.user_notifications.normal_option"),
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
content.push({
|
2024-04-25 21:22:41 +08:00
|
|
|
icon: "bell-slash",
|
2019-03-29 18:14:53 +08:00
|
|
|
id: "changeToMuted",
|
2024-11-20 04:45:18 +08:00
|
|
|
description: i18n("user.user_notifications.mute_option_title"),
|
|
|
|
name: i18n("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",
|
2024-11-20 04:45:18 +08:00
|
|
|
description: i18n("user.user_notifications.ignore_option_title"),
|
|
|
|
name: i18n("user.user_notifications.ignore_option"),
|
2019-03-27 17:41:50 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return content;
|
2024-08-23 19:17:07 +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);
|
2024-08-23 19:17:07 +08:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:14:53 +08:00
|
|
|
changeToMuted() {
|
2022-03-09 12:51:30 +08:00
|
|
|
this.updateNotificationLevel({ level: "mute" }).catch(popupAjaxError);
|
2024-08-23 19:17:07 +08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
});
|
2024-08-23 19:17:07 +08:00
|
|
|
}
|
2019-07-31 22:31:02 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
@action
|
|
|
|
onChange(level) {
|
|
|
|
this[level]();
|
2020-02-03 21:22:14 +08:00
|
|
|
|
2024-08-23 19:17:07 +08:00
|
|
|
// hack but model.ignored/muted is not
|
|
|
|
// getting updated after updateNotificationLevel
|
|
|
|
this.set("value", level);
|
|
|
|
}
|
|
|
|
}
|