1// @ts-check 2 3import { app } from "../../app/app.js"; 4import { config } from "../../app/config.js"; 5import { notifUpdates } from "../../templates/notif_tmpl.js"; 6import { Notif } from "./notif.js"; 7/** @import { Doc } from "../../models/doc.js" */ 8 9/** 10 * The notification listing the docs that gained a new release since the 11 * user last saw it. 12 */ 13export class Updates extends Notif { 14 static className = "_notif _notif-news"; 15 16 static defautOptions = { autoHide: 30000 }; 17 18 /** @inheritdoc */ 19 init0() { 20 this.lastUpdateTime = this.getLastUpdateTime(); 21 this.updatedDocs = this.getUpdatedDocs(); 22 this.updatedDisabledDocs = this.getUpdatedDisabledDocs(); 23 if (this.updatedDocs.length > 0 || this.updatedDisabledDocs.length > 0) { 24 this.show(); 25 } 26 this.markAllAsRead(); 27 } 28 29 /** @inheritdoc */ 30 render() { 31 this.html( 32 notifUpdates(this.updatedDocs, this.updatedDisabledDocs), 33 ); 34 } 35 36 /** @returns {Doc[]} Enabled docs built since the last time updates were shown. */ 37 getUpdatedDocs() { 38 if (!this.lastUpdateTime) { 39 return []; 40 } 41 return Array.from(app.docs.all()).filter( 42 (doc) => doc.mtime > this.lastUpdateTime, 43 ); 44 } 45 46 /** 47 * @returns {Doc[]} Disabled docs built since then, but only where another 48 * version of the same doc is enabled. 49 */ 50 getUpdatedDisabledDocs() { 51 if (!this.lastUpdateTime) { 52 return []; 53 } 54 const result = []; 55 for (var doc of Array.from(app.disabledDocs.all())) { 56 if ( 57 doc.mtime > this.lastUpdateTime && 58 app.docs.findBy("slug_without_version", doc.slug_without_version) 59 ) { 60 result.push(doc); 61 } 62 } 63 return result; 64 } 65 66 /** @returns {number} When updates were last shown, as a Unix timestamp. */ 67 getLastUpdateTime() { 68 return app.settings.get("version"); 69 } 70 71 /** Records that the user has seen the current set of releases. */ 72 markAllAsRead() { 73 app.settings.set( 74 "version", 75 config.env === "production" 76 ? config.version 77 : Math.floor(Date.now() / 1000), 78 ); 79 } 80};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.