/
user-tips.js
53 lines (43 loc) · 1.16 KB
/
user-tips.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
import { bind } from "discourse-common/utils/decorators";
export default {
name: "user-tips",
after: "message-bus",
initialize(container) {
this.currentUser = container.lookup("service:current-user");
if (!this.currentUser) {
return;
}
this.messageBus = container.lookup("service:message-bus");
this.site = container.lookup("service:site");
this.messageBus.subscribe(
`/user-tips/${this.currentUser.id}`,
this.onMessage
);
},
teardown() {
if (this.currentUser) {
this.messageBus?.unsubscribe(
`/user-tips/${this.currentUser.id}`,
this.onMessage
);
}
},
@bind
onMessage(seenUserTips) {
if (!this.site.user_tips) {
return;
}
this.currentUser.set("seen_popups", seenUserTips);
if (!this.currentUser.user_option) {
this.currentUser.set("user_option", {});
}
this.currentUser.set("user_option.seen_popups", seenUserTips);
(seenUserTips || []).forEach((userTipId) => {
this.currentUser.hideUserTipForever(
Object.keys(this.site.user_tips).find(
(id) => this.site.user_tips[id] === userTipId
)
);
});
},
};