diff --git a/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js b/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js index b8482db4e96..9170ab69a9c 100644 --- a/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js +++ b/app/assets/javascripts/discourse/app/initializers/subscribe-user-notifications.js @@ -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"); diff --git a/app/assets/javascripts/discourse/app/models/user.js b/app/assets/javascripts/discourse/app/models/user.js index c84356eb23d..646ac080051 100644 --- a/app/assets/javascripts/discourse/app/models/user.js +++ b/app/assets/javascripts/discourse/app/models/user.js @@ -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 && diff --git a/app/assets/javascripts/discourse/app/services/user-status.js b/app/assets/javascripts/discourse/app/services/user-status.js index a306a5db33c..b152a556984 100644 --- a/app/assets/javascripts/discourse/app/services/user-status.js +++ b/app/assets/javascripts/discourse/app/services/user-status.js @@ -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); } } diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-status-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-status-test.js index 3ef6a5346b8..67e6815ccb0 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-status-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-status-test.js @@ -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;