updates.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //= require views/misc/notif
  2. app.views.Updates = class Updates extends app.views.Notif {
  3. static className = "_notif _notif-news";
  4. static defautOptions = { autoHide: 30000 };
  5. init0() {
  6. this.lastUpdateTime = this.getLastUpdateTime();
  7. this.updatedDocs = this.getUpdatedDocs();
  8. this.updatedDisabledDocs = this.getUpdatedDisabledDocs();
  9. if (this.updatedDocs.length > 0 || this.updatedDisabledDocs.length > 0) {
  10. this.show();
  11. }
  12. this.markAllAsRead();
  13. }
  14. render() {
  15. this.html(
  16. app.templates.notifUpdates(this.updatedDocs, this.updatedDisabledDocs),
  17. );
  18. }
  19. getUpdatedDocs() {
  20. if (!this.lastUpdateTime) {
  21. return [];
  22. }
  23. return Array.from(app.docs.all()).filter(
  24. (doc) => doc.mtime > this.lastUpdateTime,
  25. );
  26. }
  27. getUpdatedDisabledDocs() {
  28. if (!this.lastUpdateTime) {
  29. return [];
  30. }
  31. const result = [];
  32. for (var doc of Array.from(app.disabledDocs.all())) {
  33. if (
  34. doc.mtime > this.lastUpdateTime &&
  35. app.docs.findBy("slug_without_version", doc.slug_without_version)
  36. ) {
  37. result.push(doc);
  38. }
  39. }
  40. return result;
  41. }
  42. getLastUpdateTime() {
  43. return app.settings.get("version");
  44. }
  45. markAllAsRead() {
  46. app.settings.set(
  47. "version",
  48. app.config.env === "production"
  49. ? app.config.version
  50. : Math.floor(Date.now() / 1000),
  51. );
  52. }
  53. };