news.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Sanity-check the conversion and remove this comment.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS101: Remove unnecessary use of Array.from
  6. * DS102: Remove unnecessary code created because of implicit returns
  7. * DS205: Consider reworking code to avoid use of IIFEs
  8. * DS206: Consider reworking classes to avoid initClass
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
  10. */
  11. //= require views/misc/notif
  12. const Cls = (app.views.News = class News extends app.views.Notif {
  13. static initClass() {
  14. this.className += ' _notif-news';
  15. this.defautOptions =
  16. {autoHide: 30000};
  17. }
  18. init() {
  19. this.unreadNews = this.getUnreadNews();
  20. if (this.unreadNews.length) { this.show(); }
  21. this.markAllAsRead();
  22. }
  23. render() {
  24. this.html(app.templates.notifNews(this.unreadNews));
  25. }
  26. getUnreadNews() {
  27. let time;
  28. if (!(time = this.getLastReadTime())) { return []; }
  29. return (() => {
  30. const result = [];
  31. for (var news of Array.from(app.news)) {
  32. if (new Date(news[0]).getTime() <= time) { break; }
  33. result.push(news);
  34. }
  35. return result;
  36. })();
  37. }
  38. getLastNewsTime() {
  39. return new Date(app.news[0][0]).getTime();
  40. }
  41. getLastReadTime() {
  42. return app.settings.get('news');
  43. }
  44. markAllAsRead() {
  45. app.settings.set('news', this.getLastNewsTime());
  46. }
  47. });
  48. Cls.initClass();