updates.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.Updates = class Updates extends app.views.Notif {
  13. static initClass() {
  14. this.className += ' _notif-news';
  15. this.defautOptions =
  16. {autoHide: 30000};
  17. }
  18. init() {
  19. this.lastUpdateTime = this.getLastUpdateTime();
  20. this.updatedDocs = this.getUpdatedDocs();
  21. this.updatedDisabledDocs = this.getUpdatedDisabledDocs();
  22. if ((this.updatedDocs.length > 0) || (this.updatedDisabledDocs.length > 0)) { this.show(); }
  23. this.markAllAsRead();
  24. }
  25. render() {
  26. this.html(app.templates.notifUpdates(this.updatedDocs, this.updatedDisabledDocs));
  27. }
  28. getUpdatedDocs() {
  29. if (!this.lastUpdateTime) { return []; }
  30. return Array.from(app.docs.all()).filter((doc) => doc.mtime > this.lastUpdateTime);
  31. }
  32. getUpdatedDisabledDocs() {
  33. if (!this.lastUpdateTime) { return []; }
  34. return (() => {
  35. const result = [];
  36. for (var doc of Array.from(app.disabledDocs.all())) { if ((doc.mtime > this.lastUpdateTime) && app.docs.findBy('slug_without_version', doc.slug_without_version)) {
  37. result.push(doc);
  38. }
  39. }
  40. return result;
  41. })();
  42. }
  43. getLastUpdateTime() {
  44. return app.settings.get('version');
  45. }
  46. markAllAsRead() {
  47. app.settings.set('version', app.config.env === 'production' ? app.config.version : Math.floor(Date.now() / 1000));
  48. }
  49. });
  50. Cls.initClass();