You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devdocs/assets/javascripts/views/misc/news.js

63 lines
1.4 KiB

// TODO: This file was created by bulk-decaffeinate.
// Sanity-check the conversion and remove this comment.
/*
* decaffeinate suggestions:
* DS101: Remove unnecessary use of Array.from
* DS102: Remove unnecessary code created because of implicit returns
* DS205: Consider reworking code to avoid use of IIFEs
* DS206: Consider reworking classes to avoid initClass
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
//= require views/misc/notif
app.views.News = class News extends app.views.Notif {
static initClass() {
1 year ago
this.className += " _notif-news";
this.defautOptions = { autoHide: 30000 };
}
init() {
this.unreadNews = this.getUnreadNews();
1 year ago
if (this.unreadNews.length) {
this.show();
}
this.markAllAsRead();
}
render() {
this.html(app.templates.notifNews(this.unreadNews));
}
getUnreadNews() {
let time;
1 year ago
if (!(time = this.getLastReadTime())) {
return [];
}
return (() => {
const result = [];
for (var news of Array.from(app.news)) {
1 year ago
if (new Date(news[0]).getTime() <= time) {
break;
}
result.push(news);
}
return result;
})();
}
getLastNewsTime() {
return new Date(app.news[0][0]).getTime();
}
getLastReadTime() {
1 year ago
return app.settings.get("news");
}
markAllAsRead() {
1 year ago
app.settings.set("news", this.getLastNewsTime());
}
};
app.views.News.initClass();