diff --git a/packages/core/api/index.js b/packages/core/api/index.js
index 3e9ca0166..b3e81104f 100644
--- a/packages/core/api/index.js
+++ b/packages/core/api/index.js
@@ -47,6 +47,7 @@ import EventManager from "../utils/event-manager";
import Pricing from "./pricing";
import { logger } from "../logger";
import Shortcuts from "../collections/shortcuts";
+import Reminders from "../collections/reminders";
/**
* @type {EventSource}
@@ -143,6 +144,8 @@ class Database {
this.noteHistory = await NoteHistory.new(this, "notehistory", false);
/**@type {Shortcuts} */
this.shortcuts = await Shortcuts.new(this, "shortcuts");
+ /**@type {Reminders} */
+ this.reminders = await Reminders.new(this, "reminders");
this.trash = new Trash(this);
diff --git a/packages/core/api/migrations.js b/packages/core/api/migrations.js
index 123f9b6cc..de6335fab 100644
--- a/packages/core/api/migrations.js
+++ b/packages/core/api/migrations.js
@@ -82,6 +82,10 @@ class Migrations {
index: () => this._db.shortcuts.raw,
dbCollection: this._db.shortcuts
},
+ {
+ index: () => this._db.reminders.raw,
+ dbCollection: this._db.reminders
+ },
{
index: () => this._db.noteHistory.sessionContent.all(),
dbCollection: this._db.noteHistory
diff --git a/packages/core/api/sync/collector.js b/packages/core/api/sync/collector.js
index 378beb0b9..cb322139e 100644
--- a/packages/core/api/sync/collector.js
+++ b/packages/core/api/sync/collector.js
@@ -43,6 +43,7 @@ class Collector {
notebook: this._db.notebooks.raw,
content: await this._db.content.all(),
attachment: this._db.attachments.syncable,
+ reminder: this._db.reminders.raw,
settings: [this._db.settings.raw]
};
diff --git a/packages/core/api/sync/merger.js b/packages/core/api/sync/merger.js
index 9d29c9f25..32c2e376d 100644
--- a/packages/core/api/sync/merger.js
+++ b/packages/core/api/sync/merger.js
@@ -46,6 +46,10 @@ class Merger {
get: (id) => this._db.shortcuts.shortcut(id),
set: (item) => this._db.shortcuts.merge(item)
},
+ reminder: {
+ get: (id) => this._db.reminders.reminder(id),
+ set: (item) => this._db.reminders.merge(item)
+ },
notebook: {
threshold: 1000,
get: (id) => this._db.notebooks.notebook(id),
diff --git a/packages/core/collections/reminders.js b/packages/core/collections/reminders.js
new file mode 100644
index 000000000..df94e9a7c
--- /dev/null
+++ b/packages/core/collections/reminders.js
@@ -0,0 +1,106 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2022 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+import getId from "../utils/id";
+import Collection from "./collection";
+
+/**
+ * @typedef {{
+ * id: string;
+ * type: string;
+ * title: string;
+ * description?: string;
+ * priority: "silent" | "vibrate" | "urgent";
+ * date: number;
+ * mode: "repeat" | "once" | "permanent";
+ * recurringMode?: "week" | "month" | "day";
+ * selectedDays?: number[];
+ * dateCreated: number;
+ * dateModified: number;
+ * }} Reminder
+ *
+ */
+
+export default class Reminders extends Collection {
+ async merge(reminder) {
+ if (!reminder) return;
+ await this._collection.addItem(reminder);
+ }
+
+ /**
+ *
+ * @param {Partial} reminder
+ * @returns
+ */
+ async add(reminder) {
+ if (!reminder) return;
+ if (reminder.remote)
+ throw new Error("Please use db.reminders.merge to merge reminders.");
+
+ const id = reminder.id || getId();
+ let oldReminder = this._collection.getItem(id);
+
+ reminder = {
+ ...oldReminder,
+ ...reminder
+ };
+
+ reminder = {
+ id,
+ type: "reminder",
+ dateCreated: reminder.dateCreated,
+ dateModified: reminder.dateModified,
+ date: reminder.date,
+ description: reminder.description,
+ mode: reminder.mode || "once",
+ priority: reminder.priority || "vibrate",
+ recurringMode: reminder.recurringMode,
+ selectedDays: reminder.selectedDays || [],
+ title: reminder.title
+ };
+
+ await this._collection.addItem(reminder);
+ return reminder.id;
+ }
+
+ get raw() {
+ return this._collection.getRaw();
+ }
+
+ /**
+ * @return {Reminder[]}
+ */
+ get all() {
+ return this._collection.getItems();
+ }
+
+ exists(itemId) {
+ return !!this.shortcut(itemId);
+ }
+
+ reminder(id) {
+ return this.all.find((reminder) => reminder.id === id);
+ }
+
+ async remove(...reminderIds) {
+ for (const id of reminderIds) {
+ await this._collection.removeItem(id);
+ }
+ }
+}
diff --git a/packages/core/database/backup.js b/packages/core/database/backup.js
index 58cfdc017..01b2b8292 100644
--- a/packages/core/database/backup.js
+++ b/packages/core/database/backup.js
@@ -175,6 +175,10 @@ export default class Backup {
index: () => data["shortcuts"],
dbCollection: this._db.shortcuts
},
+ {
+ index: () => data["reminders"],
+ dbCollection: this._db.reminders
+ },
{
index: () => data["notehistory"],
dbCollection: this._db.noteHistory,