Files
notesnook/packages/core/common.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-11-02 09:50:27 +05:00
import EventManager from "./utils/event-manager";
export const EV = new EventManager();
export async function sendCheckUserStatusEvent(type) {
if (process.env.NODE_ENV === "test") return true;
2021-07-12 10:32:35 +05:00
const results = await EV.publishWithResult(EVENTS.userCheckStatus, type);
if (typeof results === "boolean") return results;
return results.some((r) => r.type === type && r.result === true);
}
2020-12-05 13:19:41 +05:00
export function sendAttachmentsProgressEvent(type, groupId, total, current) {
EV.publish(EVENTS.attachmentsLoading, {
type,
groupId,
total,
current: current === undefined ? total : current,
});
}
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",
databaseSync: "database:sync",
2020-12-05 13:19:41 +05:00
};
export const EVENTS = {
userCheckStatus: "user:checkStatus",
userSubscriptionUpdated: "user:subscriptionUpdated",
userEmailConfirmed: "user:emailConfirmed",
userLoggedIn: "user:loggedIn",
userLoggedOut: "user:loggedOut",
userFetched: "user:fetched",
userSignedUp: "user:signedUp",
2021-05-25 16:19:58 +05:00
userSessionExpired: "user:sessionExpired",
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",
attachmentsLoading: "attachments:loading",
attachmentDeleted: "attachment:deleted",
mediaAttachmentDownloaded: "attachments:mediaDownloaded",
};
export const CURRENT_DATABASE_VERSION = 5.2;
export function setUserPersonalizationBytes(userSalt) {
USER_PERSONALIZATION_HASH = new Uint8Array(
2021-06-04 09:47:56 +05:00
Buffer.from(userSalt, "base64")
).slice(0, 8);
if (
!USER_PERSONALIZATION_HASH.length ||
!USER_PERSONALIZATION_HASH.byteLength
)
USER_PERSONALIZATION_HASH = undefined;
}
export var USER_PERSONALIZATION_HASH = null;