Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

refactor & fix premium status not set

ammarahm-ed744fbc1e21cb
diff --git a/apps/mobile/App.js b/apps/mobile/App.js
index b0df03d43..adfd377aa 100644
--- a/apps/mobile/App.js
+++ b/apps/mobile/App.js
@@ -14,6 +14,7 @@ import {enabled} from 'react-native-privacy-snapshot';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import SplashScreen from 'react-native-splash-screen';
import {RootView} from './initializer.root';
+import {updateEvent} from './src/components/DialogManager/recievers';
import {useTracked} from './src/provider';
import {Actions} from './src/provider/Actions';
import Backup from './src/services/Backup';
@@ -23,13 +24,11 @@ import {
eSubscribeEvent,
eUnSubscribeEvent,
} from './src/services/EventManager';
-import IntentService from './src/services/IntentService';
import {
clearMessage,
setEmailVerifyMessage,
setLoginMessage,
} from './src/services/Message';
-import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService';
import SettingsService from './src/services/SettingsService';
import Sync from './src/services/Sync';
@@ -37,7 +36,6 @@ import {
APP_VERSION,
editing,
getAppIsIntialized,
- getIntentOnAppLoadProcessed,
setAppIsInitialized,
setIntentOnAppLoadProcessed,
} from './src/utils';
@@ -47,7 +45,6 @@ import {
eClosePremiumDialog,
eCloseProgressDialog,
eDispatchAction,
- eOnLoadNote,
eOpenLoginDialog,
eOpenPendingDialog,
eOpenProgressDialog,
@@ -55,10 +52,9 @@ import {
refreshNotesPage,
} from './src/utils/Events';
import {MMKV} from './src/utils/mmkv';
-import {tabBarRef} from './src/utils/Refs';
import {sleep} from './src/utils/TimeUtils';
-import {getNote, setIntent} from './src/views/Editor/Functions';
-const {ReceiveSharingIntent} = NativeModules;
+import EditorRoot from './src/views/Editor/EditorRoot';
+import {getNote} from './src/views/Editor/Functions';
let Sentry = null;
let hasPurchased = false;
@@ -82,28 +78,26 @@ const onAppStateChanged = async (state) => {
}
if (getAppIsIntialized()) {
await MMKV.removeItem('appState');
- }
- try {
- if (getIntentOnAppLoadProcessed()) {
- if (Platform.OS === 'android') {
- console.log('calling intent from here too');
- let intent = await ReceiveSharingIntent.getFileNames();
- console.log("INTENT RECIEVED",intent);
- if (intent) {
- IntentService.setIntent(intent);
- IntentService.check(loadIntent);
+ let intent = await MMKV.getItem('notesAddedFromIntent');
+ if (intent) {
+ try {
+ if (Platform.OS === 'ios') {
+ await db.init();
+ await db.notes.init();
+ updateEvent({type: Actions.NOTES});
+ eSendEvent(refreshNotesPage);
+ } else {
+ updateEvent({type: Actions.NOTES});
+ eSendEvent(refreshNotesPage);
}
- ReceiveSharingIntent.clearFileNames();
- }
- } else {
- if (!db || !db.notes) return;
- if (!getNote()) {
- eSendEvent('nointent');
- } else {
- SplashScreen.hide();
+ } catch (e) {
+ console.log(e);
}
+ MMKV.removeItem('notesAddedFromIntent');
+ updateEvent({type: Actions.ALL});
+ eSendEvent(refreshNotesPage);
}
- } catch (e) {}
+ }
} else {
if (editing.currentlyEditing && getAppIsIntialized()) {
let state = JSON.stringify({
@@ -119,32 +113,7 @@ const onAppStateChanged = async (state) => {
}
};
-function loadIntent(event) {
- if (event) {
- setIntent();
- eSendEvent(eOnLoadNote, event);
- tabBarRef.current?.goToPage(1);
- Navigation.closeDrawer();
- } else {
- eSendEvent('nointent');
- SplashScreen.hide();
- sleep(300).then(() => eSendEvent(eOpenSideMenu));
- }
-}
-
-const onNetworkStateChanged = (netInfo) => {
- /* let message = 'Internet connection restored';
- let type = 'success';
- if (!netInfo.isConnected || !netInfo.isInternetReachable) {
- message = 'No internet connection';
- type = 'error';
- }
- db.user?.get().then((user) => {
- if (user && intentOnAppLoadProcessed) {
- ToastEvent.show(message, type);
- }
- }); */
-};
+//const onNetworkStateChanged = (netInfo) => {};
const App = () => {
const [, dispatch] = useTracked();
@@ -158,9 +127,8 @@ const App = () => {
});
attachIAPListeners();
AppState.addEventListener('change', onAppStateChanged);
- eSubscribeEvent('nointent', loadMainApp);
Appearance.addChangeListener(SettingsService.setTheme);
- let unsub = NetInfo.addEventListener(onNetworkStateChanged);
+ // let unsub = NetInfo.addEventListener(onNetworkStateChanged);
Linking.addEventListener('url', onUrlRecieved);
EV.subscribe('db:refresh', onSyncComplete);
EV.subscribe('db:sync', partialSync);
@@ -176,11 +144,10 @@ const App = () => {
eUnSubscribeEvent(eDispatchAction, (type) => {
dispatch(type);
});
- eUnSubscribeEvent('nointent', loadMainApp);
AppState.removeEventListener('change', onAppStateChanged);
Appearance.removeChangeListener(SettingsService.setTheme);
Linking.removeEventListener('url', onUrlRecieved);
- unsub();
+ //unsub();
unsubIAP();
};
}, []);
@@ -195,7 +162,7 @@ const App = () => {
? 'smallTablet'
: 'mobile',
});
- db.init().catch(console.log).finally(runAfterInit);
+ db.init().catch(console.log).finally(loadMainApp);
}, []);
const onSyncComplete = async () => {
@@ -204,32 +171,21 @@ const App = () => {
};
const onUrlRecieved = async (res) => {
- if (getIntentOnAppLoadProcessed()) {
- let url = res ? res.url : '';
- try {
- if (Platform.OS === 'ios' && url.startsWith('ShareMedia://dataUrl')) {
- let intent = await ReceiveSharingIntent.getFileNames(url);
- intent = IntentService.iosSortedData(intent);
-
- if (intent) {
- IntentService.setIntent(intent);
- IntentService.check(loadIntent);
- }
- } else if (
- url.startsWith('https://app.notesnook.com/account/verified')
- ) {
- await onEmailVerified();
- } else {
- return;
- }
- } catch (e) {}
- }
+ let url = res ? res.url : '';
+ try {
+ if (url.startsWith('https://app.notesnook.com/account/verified')) {
+ await onEmailVerified();
+ } else {
+ return;
+ }
+ } catch (e) {}
};
const onEmailVerified = async () => {
let user = await db.user.fetchUser(true);
dispatch({type: Actions.USER, user: user});
if (!user) return;
+ await PremiumService.setPremiumStatus();
let message =
user?.subscription?.type === 2
? 'Thank you for signing up for Notesnook Beta Program. Enjoy all premium features for free for the next 3 months.'
@@ -282,11 +238,12 @@ const App = () => {
}
};
- const onLogout = (reason) => {
+ const onLogout = async (reason) => {
dispatch({type: Actions.USER, user: null});
dispatch({type: Actions.CLEAR_ALL});
dispatch({type: Actions.SYNCING, syncing: false});
setLoginMessage(dispatch);
+ await PremiumService.setPremiumStatus();
eSendEvent(eOpenProgressDialog, {
title: reason ? reason : 'User Logged Out',
paragraph: `You have been logged out of your account.`,
@@ -313,11 +270,13 @@ const App = () => {
};
const loadMainApp = () => {
- dispatch({type: Actions.INTENT_MODE, state: false});
dispatch({type: Actions.ALL});
setCurrentUser().then(console.log).catch(console.log);
Backup.checkAndRun().then((r) => r);
- sleep(500).then(() => setAppIsInitialized(true));
+ sleep(500).then(() => {
+ setAppIsInitialized(true);
+ SplashScreen.hide();
+ });
db.notes.init().then(() => {
dispatch({type: Actions.NOTES});
dispatch({type: Actions.FAVORITES});
@@ -325,13 +284,11 @@ const App = () => {
dispatch({type: Actions.LOADING, loading: false});
SettingsService.setAppLoaded();
});
- SplashScreen.hide();
Linking.getInitialURL().then(async (url) => {
- if (url && url.startsWith('https://notesnook.com')) {
+ if (url && url.startsWith('https://app.notesnook.com/account/verified')) {
await onEmailVerified();
}
});
- setIntentOnAppLoadProcessed(true);
sleep(300).then(() => {
eSendEvent(eOpenSideMenu);
db.version()
@@ -352,46 +309,23 @@ const App = () => {
const setCurrentUser = async () => {
try {
- let user = await db.user.getUser(true);
+ let user = await db.user.fetchUser(true);
if (user) {
clearMessage(dispatch);
if (!user.isEmailConfirmed) {
setEmailVerifyMessage(dispatch);
}
dispatch({type: Actions.USER, user: user});
+ await PremiumService.setPremiumStatus();
await Sync.run();
await startSyncer();
} else {
+ await PremiumService.setPremiumStatus();
setLoginMessage(dispatch);
}
} catch (e) {}
};
- const runAfterInit = () => {
- let isIntent = false;
- IntentService.getIntent()
- .then(() => {
- IntentService.check((event) => {
- SplashScreen.hide();
- loadIntent(event);
- setIntentOnAppLoadProcessed(true);
- dispatch({type: Actions.ALL});
- isIntent = true;
- dispatch({type: Actions.INTENT_MODE, state: true});
- ReceiveSharingIntent.clearFileNames();
- });
- })
- .catch((e) => console.log)
- .finally(() => {
- if (!isIntent) {
- dispatch({type: Actions.INTENT_MODE, state: false});
- ReceiveSharingIntent.clearFileNames();
- setIntentOnAppLoadProcessed(true);
- loadMainApp();
- }
- });
- };
-
const onSuccessfulSubscription = (subscription) => {
if (hasPurchased) {
return;
@@ -433,6 +367,7 @@ const App = () => {
return (
<SafeAreaProvider>
<RootView />
+ <EditorRoot />
</SafeAreaProvider>
);
};
diff --git a/apps/mobile/initializer.root.js b/apps/mobile/initializer.root.js
index ecaaecdb5..00c374716 100644
--- a/apps/mobile/initializer.root.js
+++ b/apps/mobile/initializer.root.js
@@ -1,43 +1,45 @@
-import { activateKeepAwake, deactivateKeepAwake } from "@sayem314/react-native-keep-awake";
-import React, { useEffect, useState } from 'react';
-import { Dimensions, View } from 'react-native';
+import {
+ activateKeepAwake,
+ deactivateKeepAwake,
+} from '@sayem314/react-native-keep-awake';
+import React, {useEffect, useState} from 'react';
+import {Dimensions, View} from 'react-native';
import ScrollableTabView from 'react-native-scrollable-tab-view';
-import { notesnook } from './e2e/test.ids';
+import SplashScreen from 'react-native-splash-screen';
+import {notesnook} from './e2e/test.ids';
import ContextMenu from './src/components/ContextMenu';
-import { DialogManager } from './src/components/DialogManager';
-import { DummyText } from './src/components/DummyText';
-import { Menu } from './src/components/Menu';
-import { Toast } from './src/components/Toast';
-import { NavigationStack } from './src/navigation/Drawer';
-import { NavigatorStack } from './src/navigation/NavigatorStack';
-import { useTracked } from './src/provider';
-import { Actions } from './src/provider/Actions';
-import { DDS } from './src/services/DeviceDetection';
+import {DialogManager} from './src/components/DialogManager';
+import {DummyText} from './src/components/DummyText';
+import {Menu} from './src/components/Menu';
+import {Toast} from './src/components/Toast';
+import {NavigationStack} from './src/navigation/Drawer';
+import {NavigatorStack} from './src/navigation/NavigatorStack';
+import {useTracked} from './src/provider';
+import {Actions} from './src/provider/Actions';
+import {DDS} from './src/services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
- eUnSubscribeEvent
+ eUnSubscribeEvent,
} from './src/services/EventManager';
-import { editing, setWidthHeight } from './src/utils';
+import {editing, setWidthHeight} from './src/utils';
import {
eClearEditor,
eCloseFullscreenEditor,
eCloseSideMenu,
eOnLoadNote,
eOpenFullscreenEditor,
- eOpenSideMenu
+ eOpenSideMenu,
} from './src/utils/Events';
-import { editorRef, tabBarRef } from './src/utils/Refs';
-import { EditorWrapper } from './src/views/Editor/EditorWrapper';
-import {
- getIntent,
- getNote,
- post
-} from './src/views/Editor/Functions';
+import {editorRef, tabBarRef} from './src/utils/Refs';
+import {EditorWrapper} from './src/views/Editor/EditorWrapper';
+import {getIntent, getNote, post} from './src/views/Editor/Functions';
let {width, height} = Dimensions.get('window');
let movedAway = true;
let layoutTimer = null;
let currentTab = 0;
+
+
const onChangeTab = async (obj) => {
if (obj.i === 1) {
eSendEvent(eCloseSideMenu);
@@ -64,30 +66,20 @@ const onChangeTab = async (obj) => {
}
};
-export const RootView = React.memo(() => {
- const [state] = useTracked();
- const {colors, intentMode} = state;
-
-
- return (
- <>
- {intentMode ? (
- <EditorWrapper
- dimensions={{
- width: '100%',
- height: '100%',
- }}
- />
- ) : (
+export const RootView = React.memo(
+ () => {
+ return (
+ <>
<NavigationStack component={AppStack} />
- )}
- <Toast />
- <ContextMenu />
- <DummyText />
- <DialogManager colors={colors} />
- </>
- );
-}, () => true);
+ <Toast />
+ <ContextMenu />
+ <DummyText />
+ <DialogManager />
+ </>
+ );
+ },
+ () => true,
+);
let updatedDimensions = {
width: width,
@@ -137,7 +129,7 @@ const _onTouchEnd = (e) => {
const AppStack = React.memo(
() => {
const [state, dispatch] = useTracked();
- const {colors, intentMode} = state;
+ const {colors} = state;
const [mode, setMode] = useState(
DDS.isLargeTablet()
? 'tablet'
@@ -193,7 +185,7 @@ const AppStack = React.memo(
if (!size || (size.width === dimensions.width && mode !== null)) {
DDS.setSize(size);
dispatch({type: Actions.DEVICE_MODE, state: mode});
-
+
return;
}
updatedDimensions = size;
diff --git a/apps/mobile/src/components/LoginDialog/index.js b/apps/mobile/src/components/LoginDialog/index.js
index 12a87aaac..28caaa7cf 100644
--- a/apps/mobile/src/components/LoginDialog/index.js
+++ b/apps/mobile/src/components/LoginDialog/index.js
@@ -184,6 +184,7 @@ const LoginDialog = () => {
user = await db.user.getUser();
if (!user) throw new Error('Email or passoword incorrect!');
setStatus('Syncing Data');
+ PremiumService.setPremiumStatus();
dispatch({type: Actions.USER, user: user});
clearMessage(dispatch);
ToastEvent.show(`Logged in as ${user.email}`, 'success', 'local');