news.js 901 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //= require views/misc/notif
  2. app.views.News = class News extends app.views.Notif {
  3. static className = "_notif _notif-news";
  4. static defaultOptions = { autoHide: 30000 };
  5. init0() {
  6. this.unreadNews = this.getUnreadNews();
  7. if (this.unreadNews.length) {
  8. this.show();
  9. }
  10. this.markAllAsRead();
  11. }
  12. render() {
  13. this.html(app.templates.notifNews(this.unreadNews));
  14. }
  15. getUnreadNews() {
  16. const time = this.getLastReadTime();
  17. if (!time) {
  18. return [];
  19. }
  20. const result = [];
  21. for (var news of app.news) {
  22. if (new Date(news[0]).getTime() <= time) {
  23. break;
  24. }
  25. result.push(news);
  26. }
  27. return result;
  28. }
  29. getLastNewsTime() {
  30. return new Date(app.news[0][0]).getTime();
  31. }
  32. getLastReadTime() {
  33. return app.settings.get("news");
  34. }
  35. markAllAsRead() {
  36. app.settings.set("news", this.getLastNewsTime());
  37. }
  38. };