Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: clear 7 day old trash automatically

thecodrrdaccdd9f4d96
diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.js
index a64df11bd..6dd324e3d 100644
--- a/packages/core/collections/notes.js
+++ b/packages/core/collections/notes.js
@@ -5,7 +5,8 @@ import sort from "fast-sort";
import {
getWeekGroupFromTimestamp,
months,
- getLastWeekTimestamp
+ getLastWeekTimestamp,
+ get7DayTimestamp
} from "../utils/date";
import Storage from "../database/storage";
import Notebooks from "./notebooks";
@@ -144,7 +145,7 @@ export default class Notes {
default:
let timestamps = {
recent: getLastWeekTimestamp(7),
- lastWeek: getLastWeekTimestamp(7) - 604800000 //seven day timestamp value
+ lastWeek: getLastWeekTimestamp(7) - get7DayTimestamp() //seven day timestamp value
};
return groupBy(
notes,
diff --git a/packages/core/collections/trash.js b/packages/core/collections/trash.js
index 546452eef..c998ed223 100644
--- a/packages/core/collections/trash.js
+++ b/packages/core/collections/trash.js
@@ -2,6 +2,8 @@ import CachedCollection from "../database/cached-collection";
import Notes from "./notes";
import Notebooks from "./notebooks";
import Storage from "../database/storage";
+import { get7DayTimestamp } from "../utils/date";
+
export default class Trash {
constructor(context) {
this._collection = new CachedCollection(context, "trash");
@@ -17,6 +19,16 @@ export default class Trash {
this._notes = notes;
this._notebooks = notebooks;
await this._collection.init();
+ await this.cleanup();
+ }
+
+ async cleanup() {
+ const sevenDayPreviousTimestamp = Date.now() - get7DayTimestamp();
+ this.all.forEach(async item => {
+ if (item.dateDeleted < sevenDayPreviousTimestamp) {
+ await this.delete(item.id);
+ }
+ });
}
get all() {
diff --git a/packages/core/utils/date.js b/packages/core/utils/date.js
index 98dcade23..c8ee1d714 100644
--- a/packages/core/utils/date.js
+++ b/packages/core/utils/date.js
@@ -50,11 +50,9 @@ function getWeeksInYear(year) {
return weeks;
}
-/* function getDayTimestamp(last) {
- to = new Date().getDate() - last;
- date = new Date();
- return date.setDate(to);
-} */
+export function get7DayTimestamp() {
+ return 604800000;
+}
export function getLastWeekTimestamp() {
const t = new Date().getDate() + (6 - new Date().getDay() - 1) - 6;