1
0

updates.js 1.9 KB

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