DEV: Port user-private-messages controller to native class (#19285)

This commit is contained in:
Alan Guo Xiang Tan 2022-12-02 07:02:04 +08:00 committed by GitHub
parent 7658765736
commit a2cec6366f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,47 +1,47 @@
import Controller, { inject as controller } from "@ember/controller"; import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object"; import { action, computed } from "@ember/object";
import { inject as service } from "@ember/service"; import { inject as service } from "@ember/service";
import { alias, and, equal, readOnly } from "@ember/object/computed"; import { alias, and, equal, readOnly } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators"; import { tracked } from "@glimmer/tracking";
import I18n from "I18n"; import I18n from "I18n";
export const PERSONAL_INBOX = "__personal_inbox__"; export const PERSONAL_INBOX = "__personal_inbox__";
export default Controller.extend({ export default class extends Controller {
user: controller(), @service router;
router: service(), @controller user;
viewingSelf: alias("user.viewingSelf"), @tracked group;
isGroup: equal("currentParentRouteName", "userPrivateMessages.group"), @tracked tagId;
isPersonal: equal("currentParentRouteName", "userPrivateMessages.user"),
group: null,
groupFilter: alias("group.name"),
currentRouteName: readOnly("router.currentRouteName"),
currentParentRouteName: readOnly("router.currentRoute.parent.name"),
pmTaggingEnabled: alias("site.can_tag_pms"),
tagId: null,
showNewPM: and("user.viewingSelf", "currentUser.can_send_private_messages"), @alias("group.name") groupFilter;
@and("user.viewingSelf", "currentUser.can_send_private_messages") showNewPM;
@equal("currentParentRouteName", "userPrivateMessages.group") isGroup;
@equal("currentParentRouteName", "userPrivateMessages.user") isPersonal;
@readOnly("user.viewingSelf") viewingSelf;
@readOnly("router.currentRouteName") currentRouteName;
@readOnly("router.currentRoute.parent.name") currentParentRouteName;
@readOnly("site.can_tag_pms") pmTaggingEnabled;
@discourseComputed( @computed(
"pmTopicTrackingState.newIncoming.[]", "pmTopicTrackingState.newIncoming.[]",
"pmTopicTrackingState.statesModificationCounter", "pmTopicTrackingState.statesModificationCounter",
"group" "group"
) )
newLinkText() { get newLinkText() {
return this._linkText("new"); return this.#linkText("new");
}, }
@discourseComputed( @computed(
"pmTopicTrackingState.newIncoming.[]", "pmTopicTrackingState.newIncoming.[]",
"pmTopicTrackingState.statesModificationCounter", "pmTopicTrackingState.statesModificationCounter",
"group" "group"
) )
unreadLinkText() { get unreadLinkText() {
return this._linkText("unread"); return this.#linkText("unread");
}, }
_linkText(type) { #linkText(type) {
const count = this.pmTopicTrackingState?.lookupCount(type) || 0; const count = this.pmTopicTrackingState?.lookupCount(type) || 0;
if (count === 0) { if (count === 0) {
@ -49,10 +49,10 @@ export default Controller.extend({
} else { } else {
return I18n.t(`user.messages.${type}_with_count`, { count }); return I18n.t(`user.messages.${type}_with_count`, { count });
} }
}, }
@action @action
changeGroupNotificationLevel(notificationLevel) { changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.model.id")); this.group.setNotification(notificationLevel, this.get("user.model.id"));
}, }
}); }