DEV: do not trigger the user-status:changed event twice (#16954)

This commit is contained in:
Andrei Prigorshnev
2022-05-30 19:23:21 +04:00
committed by GitHub
parent 38324da6db
commit c5c9b2eced
4 changed files with 21 additions and 16 deletions

View File

@@ -113,7 +113,8 @@ export default {
});
bus.subscribe(`/user-status/${user.id}`, (data) => {
user.updateStatus(data);
user.set("status", data);
appEvents.trigger("user-status:changed");
});
const site = container.lookup("site:main");

View File

@@ -1002,11 +1002,6 @@ const User = RestModel.extend({
this.appEvents.trigger("do-not-disturb:changed", this.do_not_disturb_until);
},
updateStatus(status) {
this.set("status", status);
this.appEvents.trigger("user-status:changed");
},
isInDoNotDisturb() {
return (
this.do_not_disturb_until &&

View File

@@ -11,7 +11,7 @@ export default class UserStatusService extends Service {
data: { description: status.description },
});
this.currentUser.updateStatus(status);
this.currentUser.set("status", status);
}
async clear() {
@@ -20,6 +20,6 @@ export default class UserStatusService extends Service {
type: "DELETE",
});
this.currentUser.updateStatus(null);
this.currentUser.set("status", null);
}
}

View File

@@ -1,6 +1,7 @@
import {
acceptance,
exists,
publishToMessageBus,
query,
updateCurrentUser,
} from "discourse/tests/helpers/qunit-helpers";
@@ -8,16 +9,24 @@ import { click, fillIn, visit } from "@ember/test-helpers";
import { test } from "qunit";
acceptance("User Status", function (needs) {
needs.user();
needs.pretender((server, helper) => {
server.put("/user-status.json", () => helper.response({ success: true }));
server.delete("/user-status.json", () =>
helper.response({ success: true })
);
});
const userStatusFallbackEmoji = "mega";
const userStatus = "off to dentist";
const userId = 1;
needs.user({ id: userId });
needs.pretender((server, helper) => {
server.put("/user-status.json", () => {
publishToMessageBus(`/user-status/${userId}`, {
description: userStatus,
});
return helper.response({ success: true });
});
server.delete("/user-status.json", () => {
publishToMessageBus(`/user-status/${userId}`, null);
return helper.response({ success: true });
});
});
test("doesn't show the user status button on the menu by default", async function (assert) {
this.siteSettings.enable_user_status = false;