mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 14:39:34 +01:00
refactor: sendCheckUserStatusEvent -> checkIsUserPremium
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'.");
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user