From b5ab8e5d3ec91efc9116acb60c5e63d98f2bcece Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 12 Oct 2022 15:38:35 +0500 Subject: [PATCH] core: allow free users to assign same 5 tags without limits --- packages/core/collections/tags.js | 8 ++++++++ packages/core/models/note.js | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/core/collections/tags.js b/packages/core/collections/tags.js index 826980e4d..65eb164b4 100644 --- a/packages/core/collections/tags.js +++ b/packages/core/collections/tags.js @@ -22,6 +22,7 @@ import { makeId } from "../utils/id"; import { deleteItems, hasItem } from "../utils/array"; import setManipulator from "../utils/set"; import { Mutex } from "async-mutex"; +import { checkIsUserPremium, CHECK_IDS } from "../common"; export default class Tags extends Collection { constructor(db, name, cached) { @@ -50,6 +51,13 @@ export default class Tags extends Collection { if (tag && !noteIds.length) throw new Error("A tag with this id already exists."); + if ( + !tag && + this.all.length >= 5 && + !(await checkIsUserPremium(CHECK_IDS.noteTag)) + ) + return; + tag = tag || { title: tagId }; diff --git a/packages/core/models/note.js b/packages/core/models/note.js index 4da999920..9169c7065 100644 --- a/packages/core/models/note.js +++ b/packages/core/models/note.js @@ -160,12 +160,6 @@ export default class Note { } async tag(tag) { - if ( - this._db.tags.all.length >= 5 && - !(await checkIsUserPremium(CHECK_IDS.noteTag)) - ) - return; - let tagItem = await this._db.tags.add(tag, this._note.id); if (addItem(this._note.tags, tagItem.title)) await this._db.notes.add(this._note);