1. "What Goes Up Must Come Down" – if you subscribe to message bus, make sure you also unsubscribe 2. When you unsubscribe - remove only your subscription, not **all** subscriptions on given channel Attempt #2. The first attempt tried to extend a core `@bound` method in new-user-narrative plugin which did not work. I reworked that plugin in the meantime. This new PR also cleans up message bus subscriptions in now core-merged chat plugin.
42 lines
1015 B
JavaScript
42 lines
1015 B
JavaScript
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.onMessage);
|
|
},
|
|
|
|
teardown() {
|
|
this.messageBus?.unsubscribe("/user-tips", this.onMessage);
|
|
},
|
|
|
|
@bind
|
|
onMessage(seenUserTips) {
|
|
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
|
|
)
|
|
);
|
|
});
|
|
},
|
|
};
|