mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +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 Conflicts from "./sync/conflicts";
|
||||||
import Session from "./session";
|
import Session from "./session";
|
||||||
import Constants from "../utils/constants";
|
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 Settings from "./settings";
|
||||||
import Migrations from "./migrations";
|
import Migrations from "./migrations";
|
||||||
import Outbox from "./outbox";
|
import Outbox from "./outbox";
|
||||||
@@ -165,8 +165,7 @@ class Database {
|
|||||||
EV.publish(EVENTS.userEmailConfirmed);
|
EV.publish(EVENTS.userEmailConfirmed);
|
||||||
break;
|
break;
|
||||||
case "sync":
|
case "sync":
|
||||||
if (await sendCheckUserStatusEvent(CHECK_IDS.databaseSync))
|
if (!(await checkIsUserPremium(CHECK_IDS.databaseSync))) break;
|
||||||
await this.syncer.eventMerge(data);
|
|
||||||
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;
|
const ERASE_TIME = 1000 * 60 * 30;
|
||||||
var ERASER_TIMEOUT = null;
|
var ERASER_TIMEOUT = null;
|
||||||
@@ -46,7 +46,7 @@ export default class Vault {
|
|||||||
* @returns {Promise<Boolean>}
|
* @returns {Promise<Boolean>}
|
||||||
*/
|
*/
|
||||||
async create(password) {
|
async create(password) {
|
||||||
if (!(await sendCheckUserStatusEvent(CHECK_IDS.vaultAdd))) return;
|
if (!(await checkIsUserPremium(CHECK_IDS.vaultAdd))) return;
|
||||||
|
|
||||||
const vaultKey = await this._storage.read("vaultKey");
|
const vaultKey = await this._storage.read("vaultKey");
|
||||||
if (!vaultKey || !vaultKey.cipher || !vaultKey.iv) {
|
if (!vaultKey || !vaultKey.cipher || !vaultKey.iv) {
|
||||||
@@ -115,7 +115,7 @@ export default class Vault {
|
|||||||
* @param {string} noteId The id of the note to lock
|
* @param {string} noteId The id of the note to lock
|
||||||
*/
|
*/
|
||||||
async add(noteId) {
|
async add(noteId) {
|
||||||
if (!(await sendCheckUserStatusEvent(CHECK_IDS.vaultAdd))) return;
|
if (!(await checkIsUserPremium(CHECK_IDS.vaultAdd))) return;
|
||||||
|
|
||||||
await this._check();
|
await this._check();
|
||||||
await this._lockNote({ id: noteId }, this._password);
|
await this._lockNote({ id: noteId }, this._password);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import Collection from "./collection";
|
|||||||
import Notebook from "../models/notebook";
|
import Notebook from "../models/notebook";
|
||||||
import sort from "fast-sort";
|
import sort from "fast-sort";
|
||||||
import getId from "../utils/id";
|
import getId from "../utils/id";
|
||||||
import { CHECK_IDS, sendCheckUserStatusEvent } from "../common";
|
import { CHECK_IDS, checkIsUserPremium } from "../common";
|
||||||
import { qclone } from "qclone";
|
import { qclone } from "qclone";
|
||||||
import setManipulator from "../utils/set";
|
import setManipulator from "../utils/set";
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ export default class Notebooks extends Collection {
|
|||||||
if (
|
if (
|
||||||
!oldNotebook &&
|
!oldNotebook &&
|
||||||
this.all.length >= 3 &&
|
this.all.length >= 3 &&
|
||||||
!(await sendCheckUserStatusEvent(CHECK_IDS.notebookAdd))
|
!(await checkIsUserPremium(CHECK_IDS.notebookAdd))
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import EventManager from "./utils/event-manager";
|
|||||||
|
|
||||||
export const EV = new EventManager();
|
export const EV = new EventManager();
|
||||||
|
|
||||||
export async function sendCheckUserStatusEvent(type) {
|
export async function checkIsUserPremium(type) {
|
||||||
if (process.env.NODE_ENV === "test") return true;
|
if (process.env.NODE_ENV === "test") return true;
|
||||||
|
|
||||||
const results = await EV.publishWithResult(EVENTS.userCheckStatus, type);
|
const results = await EV.publishWithResult(EVENTS.userCheckStatus, type);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Migrator from "./migrator.js";
|
import Migrator from "./migrator.js";
|
||||||
import {
|
import {
|
||||||
CHECK_IDS,
|
CHECK_IDS,
|
||||||
sendCheckUserStatusEvent,
|
checkIsUserPremium,
|
||||||
CURRENT_DATABASE_VERSION,
|
CURRENT_DATABASE_VERSION,
|
||||||
} from "../common.js";
|
} from "../common.js";
|
||||||
import SparkMD5 from "spark-md5";
|
import SparkMD5 from "spark-md5";
|
||||||
@@ -29,8 +29,7 @@ export default class Backup {
|
|||||||
* @param {boolean} encrypt
|
* @param {boolean} encrypt
|
||||||
*/
|
*/
|
||||||
async export(type, encrypt = false) {
|
async export(type, encrypt = false) {
|
||||||
if (encrypt && !(await sendCheckUserStatusEvent(CHECK_IDS.backupEncrypt)))
|
if (encrypt && !(await checkIsUserPremium(CHECK_IDS.backupEncrypt))) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (!validTypes.some((t) => t === type))
|
if (!validTypes.some((t) => t === type))
|
||||||
throw new Error("Invalid type. It must be one of 'mobile' or 'web'.");
|
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 HTMLBuilder from "../utils/templates/html/builder";
|
||||||
import TextBuilder from "../utils/templates/text/builder";
|
import TextBuilder from "../utils/templates/text/builder";
|
||||||
import { getContentFromData } from "../content-types";
|
import { getContentFromData } from "../content-types";
|
||||||
import { CHECK_IDS, sendCheckUserStatusEvent } from "../common";
|
import { CHECK_IDS, checkIsUserPremium } from "../common";
|
||||||
import { addItem, deleteItem } from "../utils/array";
|
import { addItem, deleteItem } from "../utils/array";
|
||||||
|
|
||||||
export default class Note {
|
export default class Note {
|
||||||
@@ -58,7 +58,7 @@ export default class Note {
|
|||||||
* @param {string?} rawContent - Use this raw content instead of generating itself
|
* @param {string?} rawContent - Use this raw content instead of generating itself
|
||||||
*/
|
*/
|
||||||
async export(to = "html", rawContent) {
|
async export(to = "html", rawContent) {
|
||||||
if (to !== "txt" && !(await sendCheckUserStatusEvent(CHECK_IDS.noteExport)))
|
if (to !== "txt" && !(await checkIsUserPremium(CHECK_IDS.noteExport)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const templateData = {
|
const templateData = {
|
||||||
@@ -98,7 +98,7 @@ export default class Note {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async color(color) {
|
async color(color) {
|
||||||
if (!(await sendCheckUserStatusEvent(CHECK_IDS.noteColor))) return;
|
if (!(await checkIsUserPremium(CHECK_IDS.noteColor))) return;
|
||||||
await this.uncolor();
|
await this.uncolor();
|
||||||
let tag = await this._db.colors.add(color, this._note.id);
|
let tag = await this._db.colors.add(color, this._note.id);
|
||||||
await this._db.notes._collection.addItem({
|
await this._db.notes._collection.addItem({
|
||||||
@@ -119,7 +119,7 @@ export default class Note {
|
|||||||
async tag(tag) {
|
async tag(tag) {
|
||||||
if (
|
if (
|
||||||
this._db.tags.all.length >= 5 &&
|
this._db.tags.all.length >= 5 &&
|
||||||
!(await sendCheckUserStatusEvent(CHECK_IDS.noteTag))
|
!(await checkIsUserPremium(CHECK_IDS.noteTag))
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user