news.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. app.views.News = class News extends app.views.Notif {
  13. static initClass() {
  14. this.className += " _notif-news";
  15. this.defautOptions = { autoHide: 30000 };
  16. }
  17. init() {
  18. this.unreadNews = this.getUnreadNews();
  19. if (this.unreadNews.length) {
  20. this.show();
  21. }
  22. this.markAllAsRead();
  23. }
  24. render() {
  25. this.html(app.templates.notifNews(this.unreadNews));
  26. }
  27. getUnreadNews() {
  28. let time;
  29. if (!(time = this.getLastReadTime())) {
  30. return [];
  31. }
  32. return (() => {
  33. const result = [];
  34. for (var news of Array.from(app.news)) {
  35. if (new Date(news[0]).getTime() <= time) {
  36. break;
  37. }
  38. result.push(news);
  39. }
  40. return result;
  41. })();
  42. }
  43. getLastNewsTime() {
  44. return new Date(app.news[0][0]).getTime();
  45. }
  46. getLastReadTime() {
  47. return app.settings.get("news");
  48. }
  49. markAllAsRead() {
  50. app.settings.set("news", this.getLastNewsTime());
  51. }
  52. };
  53. app.views.News.initClass();