forked from discourse/discourse
/
user-private-messages.js
114 lines (93 loc) · 3.02 KB
/
user-private-messages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import Controller, { inject as controller } from "@ember/controller";
import { action } from "@ember/object";
import { alias, and, equal } from "@ember/object/computed";
import discourseComputed from "discourse-common/utils/decorators";
import { VIEW_NAME_WARNINGS } from "discourse/routes/user-private-messages-warnings";
import I18n from "I18n";
export const PERSONAL_INBOX = "__personal_inbox__";
const ALL_INBOX = "__all_inbox__";
export default Controller.extend({
user: controller(),
pmView: false,
viewingSelf: alias("user.viewingSelf"),
isGroup: equal("pmView", "groups"),
group: null,
groupFilter: alias("group.name"),
currentPath: alias("router._router.currentPath"),
pmTaggingEnabled: alias("site.can_tag_pms"),
tagId: null,
showNewPM: and("user.viewingSelf", "currentUser.can_send_private_messages"),
@discourseComputed("inboxes", "isAllInbox")
displayGlobalFilters(inboxes, isAllInbox) {
if (inboxes.length === 0) {
return true;
}
if (inboxes.length && isAllInbox) {
return true;
}
return false;
},
@discourseComputed("inboxes")
sectionClass(inboxes) {
const defaultClass = "user-secondary-navigation user-messages";
return inboxes.length
? `${defaultClass} user-messages-inboxes`
: defaultClass;
},
@discourseComputed("pmView")
isPersonalInbox(pmView) {
return pmView && pmView.startsWith("personal");
},
@discourseComputed("isPersonalInbox", "group.name")
isAllInbox(isPersonalInbox, groupName) {
return !this.isPersonalInbox && !groupName;
},
@discourseComputed("isPersonalInbox", "group.name")
selectedInbox(isPersonalInbox, groupName) {
if (groupName) {
return groupName;
}
return isPersonalInbox ? PERSONAL_INBOX : ALL_INBOX;
},
@discourseComputed("viewingSelf", "pmView", "currentUser.admin")
showWarningsWarning(viewingSelf, pmView, isAdmin) {
return pmView === VIEW_NAME_WARNINGS && !viewingSelf && !isAdmin;
},
@discourseComputed("model.groups")
inboxes(groups) {
const groupsWithMessages = groups?.filter((group) => {
return group.has_messages;
});
if (!groupsWithMessages || groupsWithMessages.length === 0) {
return [];
}
const inboxes = [];
inboxes.push({
id: ALL_INBOX,
name: I18n.t("user.messages.all"),
});
inboxes.push({
id: PERSONAL_INBOX,
name: I18n.t("user.messages.personal"),
icon: "envelope",
});
groupsWithMessages.forEach((group) => {
inboxes.push({ id: group.name, name: group.name, icon: "users" });
});
return inboxes;
},
@action
changeGroupNotificationLevel(notificationLevel) {
this.group.setNotification(notificationLevel, this.get("user.model.id"));
},
@action
updateInbox(inbox) {
if (inbox === ALL_INBOX) {
this.transitionToRoute("userPrivateMessages.index");
} else if (inbox === PERSONAL_INBOX) {
this.transitionToRoute("userPrivateMessages.personal");
} else {
this.transitionToRoute("userPrivateMessages.group", inbox);
}
},
});