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

48 lines
901 B

//= require views/misc/notif
app.views.News = class News extends app.views.Notif {
static className = "_notif _notif-news";
1 year ago
static defaultOptions = { autoHide: 30000 };
init0() {
this.unreadNews = this.getUnreadNews();
1 year ago
if (this.unreadNews.length) {
this.show();
}
this.markAllAsRead();
}
render() {
this.html(app.templates.notifNews(this.unreadNews));
}
getUnreadNews() {
const time = this.getLastReadTime();
if (!time) {
1 year ago
return [];
}
const result = [];
for (var news of app.news) {
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());
}
};