Skip to content

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

refactor: sendCheckUserStatusEvent -> checkIsUserPremium

thecodrr888481b85891
diff --git a/packages/core/api/index.js b/packages/core/api/index.js
index 782adb97b..628e5182e 100644
--- a/packages/core/api/index.js
+++ b/packages/core/api/index.js
@@ -12,7 +12,7 @@ import Backup from "../database/backup";
import Conflicts from "./sync/conflicts";
import Session from "./session";
import Constants from "../utils/constants";
-import { CHECK_IDS, EV, EVENTS, sendCheckUserStatusEvent } from "../common";
+import { CHECK_IDS, EV, EVENTS, checkIsUserPremium } from "../common";
import Settings from "./settings";
import Migrations from "./migrations";
import Outbox from "./outbox";
@@ -165,8 +165,7 @@ class Database {
EV.publish(EVENTS.userEmailConfirmed);
break;
case "sync":
- if (await sendCheckUserStatusEvent(CHECK_IDS.databaseSync))
- await this.syncer.eventMerge(data);
+ if (!(await checkIsUserPremium(CHECK_IDS.databaseSync))) break;
break;
}
};
diff --git a/packages/core/api/vault.js b/packages/core/api/vault.js
index 3b52e70c0..00ef8fddd 100644
--- a/packages/core/api/vault.js
+++ b/packages/core/api/vault.js
@@ -1,4 +1,4 @@
-import { CHECK_IDS, EV, EVENTS, sendCheckUserStatusEvent } from "../common";
+import { CHECK_IDS, EV, EVENTS, checkIsUserPremium } from "../common";
const ERASE_TIME = 1000 * 60 * 30;
var ERASER_TIMEOUT = null;
@@ -46,7 +46,7 @@ export default class Vault {
* @returns {Promise<Boolean>}
*/
async create(password) {
- if (!(await sendCheckUserStatusEvent(CHECK_IDS.vaultAdd))) return;
+ if (!(await checkIsUserPremium(CHECK_IDS.vaultAdd))) return;
const vaultKey = await this._storage.read("vaultKey");
if (!vaultKey || !vaultKey.cipher || !vaultKey.iv) {
@@ -115,7 +115,7 @@ export default class Vault {
* @param {string} noteId The id of the note to lock
*/
async add(noteId) {
- if (!(await sendCheckUserStatusEvent(CHECK_IDS.vaultAdd))) return;
+ if (!(await checkIsUserPremium(CHECK_IDS.vaultAdd))) return;
await this._check();
await this._lockNote({ id: noteId }, this._password);
diff --git a/packages/core/collections/notebooks.js b/packages/core/collections/notebooks.js
index 3b54cca90..de5e76e11 100644
--- a/packages/core/collections/notebooks.js
+++ b/packages/core/collections/notebooks.js
@@ -2,7 +2,7 @@ import Collection from "./collection";
import Notebook from "../models/notebook";
import sort from "fast-sort";
import getId from "../utils/id";
-import { CHECK_IDS, sendCheckUserStatusEvent } from "../common";
+import { CHECK_IDS, checkIsUserPremium } from "../common";
import { qclone } from "qclone";
import setManipulator from "../utils/set";
@@ -65,7 +65,7 @@ export default class Notebooks extends Collection {
if (
!oldNotebook &&
this.all.length >= 3 &&
- !(await sendCheckUserStatusEvent(CHECK_IDS.notebookAdd))
+ !(await checkIsUserPremium(CHECK_IDS.notebookAdd))
)
return;
diff --git a/packages/core/common.js b/packages/core/common.js
index eb24f75f5..46fb33023 100644
--- a/packages/core/common.js
+++ b/packages/core/common.js
@@ -2,7 +2,7 @@ import EventManager from "./utils/event-manager";
export const EV = new EventManager();
-export async function sendCheckUserStatusEvent(type) {
+export async function checkIsUserPremium(type) {
if (process.env.NODE_ENV === "test") return true;
const results = await EV.publishWithResult(EVENTS.userCheckStatus, type);
diff --git a/packages/core/database/backup.js b/packages/core/database/backup.js
index f1ec5acf1..27ad1abfe 100644
--- a/packages/core/database/backup.js
+++ b/packages/core/database/backup.js
@@ -1,7 +1,7 @@
import Migrator from "./migrator.js";
import {
CHECK_IDS,
- sendCheckUserStatusEvent,
+ checkIsUserPremium,
CURRENT_DATABASE_VERSION,
} from "../common.js";
import SparkMD5 from "spark-md5";
@@ -29,8 +29,7 @@ export default class Backup {
* @param {boolean} encrypt
*/
async export(type, encrypt = false) {
- if (encrypt && !(await sendCheckUserStatusEvent(CHECK_IDS.backupEncrypt)))
- return;
+ if (encrypt && !(await checkIsUserPremium(CHECK_IDS.backupEncrypt))) return;
if (!validTypes.some((t) => t === type))
throw new Error("Invalid type. It must be one of 'mobile' or 'web'.");
diff --git a/packages/core/models/note.js b/packages/core/models/note.js
index 84d449e57..7b4157d4f 100644
--- a/packages/core/models/note.js
+++ b/packages/core/models/note.js
@@ -2,7 +2,7 @@ import MarkdownBuilder from "../utils/templates/markdown/builder";
import HTMLBuilder from "../utils/templates/html/builder";
import TextBuilder from "../utils/templates/text/builder";
import { getContentFromData } from "../content-types";
-import { CHECK_IDS, sendCheckUserStatusEvent } from "../common";
+import { CHECK_IDS, checkIsUserPremium } from "../common";
import { addItem, deleteItem } from "../utils/array";
export default class Note {
@@ -58,7 +58,7 @@ export default class Note {
* @param {string?} rawContent - Use this raw content instead of generating itself
*/
async export(to = "html", rawContent) {
- if (to !== "txt" && !(await sendCheckUserStatusEvent(CHECK_IDS.noteExport)))
+ if (to !== "txt" && !(await checkIsUserPremium(CHECK_IDS.noteExport)))
return false;
const templateData = {
@@ -98,7 +98,7 @@ export default class Note {
}
async color(color) {
- if (!(await sendCheckUserStatusEvent(CHECK_IDS.noteColor))) return;
+ if (!(await checkIsUserPremium(CHECK_IDS.noteColor))) return;
await this.uncolor();
let tag = await this._db.colors.add(color, this._note.id);
await this._db.notes._collection.addItem({
@@ -119,7 +119,7 @@ export default class Note {
async tag(tag) {
if (
this._db.tags.all.length >= 5 &&
- !(await sendCheckUserStatusEvent(CHECK_IDS.noteTag))
+ !(await checkIsUserPremium(CHECK_IDS.noteTag))
)
return;