Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Live-update notification panel (#37645)

Rafael dos Santos Silvaf4cad52ef781
diff --git a/frontend/discourse/app/components/user-menu/notifications-list.js b/frontend/discourse/app/components/user-menu/notifications-list.js
index 6df089fa83d..8dd58cd71be 100644
--- a/frontend/discourse/app/components/user-menu/notifications-list.js
+++ b/frontend/discourse/app/components/user-menu/notifications-list.js
@@ -1,9 +1,11 @@
import { action } from "@ember/object";
+import { cancel } from "@ember/runloop";
import { service } from "@ember/service";
import DismissNotificationConfirmationModal from "discourse/components/modal/dismiss-notification-confirmation";
import UserMenuItemsList from "discourse/components/user-menu/items-list";
import { ajax } from "discourse/lib/ajax";
import { MAX_NOTIFICATIONS_LIMIT_PARAMS } from "discourse/lib/constants";
+import discourseDebounce from "discourse/lib/debounce";
import UserMenuNotificationItem from "discourse/lib/user-menu/notification-item";
import UserMenuReviewableItem from "discourse/lib/user-menu/reviewable-item";
import {
@@ -37,6 +39,29 @@ export default class UserMenuNotificationsList extends UserMenuItemsList {
@service site;
@service modal;
+ constructor() {
+ super(...arguments);
+ this.appEvents.on(
+ "notifications:changed",
+ this,
+ this._onNotificationsChanged
+ );
+ }
+
+ willDestroy() {
+ super.willDestroy(...arguments);
+ cancel(this._refreshTimer);
+ this.appEvents.off(
+ "notifications:changed",
+ this,
+ this._onNotificationsChanged
+ );
+ }
+
+ _onNotificationsChanged() {
+ this._refreshTimer = discourseDebounce(this, this.refreshList, 500);
+ }
+
get filterByTypes() {
return this.args.filterByTypes;
}
diff --git a/frontend/discourse/tests/integration/components/user-menu/notifications-list-test.gjs b/frontend/discourse/tests/integration/components/user-menu/notifications-list-test.gjs
index 98fba67b24b..95da2202222 100644
--- a/frontend/discourse/tests/integration/components/user-menu/notifications-list-test.gjs
+++ b/frontend/discourse/tests/integration/components/user-menu/notifications-list-test.gjs
@@ -1,4 +1,4 @@
-import { click, render } from "@ember/test-helpers";
+import { click, render, settled } from "@ember/test-helpers";
import { module, test } from "qunit";
import NotificationsList from "discourse/components/user-menu/notifications-list";
import { cloneJSON } from "discourse/lib/object";
@@ -119,6 +119,18 @@ module(
.doesNotExist("dismiss button is not shown");
});
+ test("refreshes the list when notifications:changed appEvent is triggered", async function (assert) {
+ await render(<template><NotificationsList /></template>);
+ assert.strictEqual(notificationsFetches, 1);
+ this.owner.lookup("service:app-events").trigger("notifications:changed");
+ await settled();
+ assert.strictEqual(
+ notificationsFetches,
+ 2,
+ "notifications list is re-fetched"
+ );
+ });
+
test("all notifications tab shows pending reviewables and sorts them with unread notifications based on their creation date", async function (assert) {
pretender.get("/notifications", () => {
return response({