2020-11-02 09:50:27 +05:00
|
|
|
import EventManager from "./utils/event-manager";
|
|
|
|
|
|
|
|
|
|
export const EV = new EventManager();
|
2020-11-11 15:43:09 +05:00
|
|
|
|
2021-10-26 23:05:47 +05:00
|
|
|
export async function checkIsUserPremium(type) {
|
2021-08-08 12:20:07 +05:00
|
|
|
if (process.env.NODE_ENV === "test") return true;
|
2021-07-12 10:32:35 +05:00
|
|
|
|
2021-01-23 10:48:21 +05:00
|
|
|
const results = await EV.publishWithResult(EVENTS.userCheckStatus, type);
|
2020-11-11 15:43:09 +05:00
|
|
|
if (typeof results === "boolean") return results;
|
|
|
|
|
return results.some((r) => r.type === type && r.result === true);
|
|
|
|
|
}
|
2020-12-05 13:19:41 +05:00
|
|
|
|
2021-10-21 10:16:24 +05:00
|
|
|
export function sendAttachmentsProgressEvent(type, groupId, total, current) {
|
2021-09-30 09:42:32 +05:00
|
|
|
EV.publish(EVENTS.attachmentsLoading, {
|
|
|
|
|
type,
|
2021-10-21 10:16:24 +05:00
|
|
|
groupId,
|
2021-09-30 09:42:32 +05:00
|
|
|
total,
|
2021-10-01 11:16:08 +05:00
|
|
|
current: current === undefined ? total : current,
|
2021-09-30 09:42:32 +05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-24 11:13:41 +05:00
|
|
|
export const CLIENT_ID = "notesnook";
|
|
|
|
|
|
2020-12-05 13:19:41 +05:00
|
|
|
export const CHECK_IDS = {
|
|
|
|
|
noteColor: "note:color",
|
|
|
|
|
noteTag: "note:tag",
|
|
|
|
|
noteExport: "note:export",
|
|
|
|
|
vaultAdd: "vault:add",
|
|
|
|
|
notebookAdd: "notebook:add",
|
|
|
|
|
backupEncrypt: "backup:encrypt",
|
2021-02-15 21:07:46 +05:00
|
|
|
databaseSync: "database:sync",
|
2020-12-05 13:19:41 +05:00
|
|
|
};
|
2020-12-05 15:28:54 +05:00
|
|
|
|
2021-01-23 10:48:21 +05:00
|
|
|
export const EVENTS = {
|
|
|
|
|
userCheckStatus: "user:checkStatus",
|
|
|
|
|
userSubscriptionUpdated: "user:subscriptionUpdated",
|
|
|
|
|
userEmailConfirmed: "user:emailConfirmed",
|
|
|
|
|
userLoggedIn: "user:loggedIn",
|
|
|
|
|
userLoggedOut: "user:loggedOut",
|
|
|
|
|
userFetched: "user:fetched",
|
2021-02-26 17:33:46 +05:00
|
|
|
userSignedUp: "user:signedUp",
|
2021-05-25 16:19:58 +05:00
|
|
|
userSessionExpired: "user:sessionExpired",
|
2021-01-23 10:48:21 +05:00
|
|
|
databaseSyncRequested: "db:syncRequested",
|
|
|
|
|
databaseMigrated: "db:migrated",
|
|
|
|
|
databaseUpdated: "db:updated",
|
|
|
|
|
appRefreshRequested: "app:refreshRequested",
|
|
|
|
|
noteRemoved: "note:removed",
|
2021-08-31 12:11:46 +05:00
|
|
|
tokenRefreshed: "token:refreshed",
|
2021-09-26 11:47:13 +05:00
|
|
|
attachmentsLoading: "attachments:loading",
|
2021-09-29 09:53:50 +05:00
|
|
|
attachmentDeleted: "attachment:deleted",
|
2021-09-26 11:47:13 +05:00
|
|
|
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
|
2021-01-23 10:48:21 +05:00
|
|
|
};
|
|
|
|
|
|
2021-02-20 11:31:44 +05:00
|
|
|
export const CURRENT_DATABASE_VERSION = 5.2;
|
2021-06-04 09:32:13 +05:00
|
|
|
|
|
|
|
|
export function setUserPersonalizationBytes(userSalt) {
|
|
|
|
|
USER_PERSONALIZATION_HASH = new Uint8Array(
|
2021-06-04 09:47:56 +05:00
|
|
|
Buffer.from(userSalt, "base64")
|
|
|
|
|
).slice(0, 8);
|
2021-06-04 09:32:13 +05:00
|
|
|
if (
|
|
|
|
|
!USER_PERSONALIZATION_HASH.length ||
|
|
|
|
|
!USER_PERSONALIZATION_HASH.byteLength
|
|
|
|
|
)
|
|
|
|
|
USER_PERSONALIZATION_HASH = undefined;
|
|
|
|
|
}
|
|
|
|
|
export var USER_PERSONALIZATION_HASH = null;
|