mirror of
https://github.com/discourse/discourse.git
synced 2025-01-10 07:23:48 +08:00
19214aff18
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.
35 lines
969 B
JavaScript
35 lines
969 B
JavaScript
import Controller from "@ember/controller";
|
|
import DiscourseURL from "discourse/lib/url";
|
|
import I18n from "I18n";
|
|
import ModalFunctionality from "discourse/mixins/modal-functionality";
|
|
import { bind } from "discourse-common/utils/decorators";
|
|
|
|
export default Controller.extend(ModalFunctionality, {
|
|
message: I18n.t("admin.user.merging_user"),
|
|
|
|
onShow() {
|
|
this.messageBus.subscribe("/merge_user", this.onMessage);
|
|
},
|
|
|
|
onClose() {
|
|
this.messageBus.unsubscribe("/merge_user", this.onMessage);
|
|
},
|
|
|
|
@bind
|
|
onMessage(data) {
|
|
if (data.merged) {
|
|
if (/^\/admin\/users\/list\//.test(location)) {
|
|
DiscourseURL.redirectTo(location);
|
|
} else {
|
|
DiscourseURL.redirectTo(
|
|
`/admin/users/${data.user.id}/${data.user.username}`
|
|
);
|
|
}
|
|
} else if (data.message) {
|
|
this.set("message", data.message);
|
|
} else if (data.failed) {
|
|
this.set("message", I18n.t("admin.user.merge_failed"));
|
|
}
|
|
},
|
|
});
|