This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/widgets/quick-access-notifications.js
Jarek Radosz 67b34600d5
DEV: Use type instead of method in ajax calls (#8974)
Even though `type` is an alias for `method`, we have custom logic in `/discourse/lib/ajax` that checks only `type`, and ~200 other ajax calls in the codebase already use `type` param.
2020-03-26 21:00:10 +01:00

56 lines
1.4 KiB
JavaScript

import { ajax } from "discourse/lib/ajax";
import { createWidgetFrom } from "discourse/widgets/widget";
import QuickAccessPanel from "discourse/widgets/quick-access-panel";
createWidgetFrom(QuickAccessPanel, "quick-access-notifications", {
buildKey: () => "quick-access-notifications",
emptyStatePlaceholderItemKey: "notifications.empty",
markReadRequest() {
return ajax("/notifications/mark-read", { type: "PUT" });
},
newItemsLoaded() {
if (!this.currentUser.enforcedSecondFactor) {
this.currentUser.set("unread_notifications", 0);
}
},
itemHtml(notification) {
const notificationName = this.site.notificationLookup[
notification.notification_type
];
return this.attach(
`${notificationName.dasherize()}-notification-item`,
notification,
{},
{ fallbackWidgetName: "default-notification-item" }
);
},
findNewItems() {
return this._findStaleItemsInStore().refresh();
},
showAllHref() {
return `${this.attrs.path}/notifications`;
},
hasUnread() {
return this.getItems().filterBy("read", false).length > 0;
},
_findStaleItemsInStore() {
return this.store.findStale(
"notification",
{
recent: true,
silent: this.currentUser.enforcedSecondFactor,
limit: this.estimateItemLimit()
},
{ cacheKey: "recent-notifications" }
);
}
});