update user

This commit is contained in:
ammarahm-ed
2020-12-16 14:57:58 +05:00
parent 6565b0d39b
commit b23cd26a29
17 changed files with 154 additions and 108 deletions

View File

@@ -1,33 +1,37 @@
import * as NetInfo from '@react-native-community/netinfo'; import * as NetInfo from '@react-native-community/netinfo';
import { CHECK_IDS, EV } from 'notes-core/common'; import {CHECK_IDS, EV} from 'notes-core/common';
import React, { useEffect, useState } from 'react'; import React, {useEffect, useState} from 'react';
import { import {
Appearance, Appearance,
AppState, AppState,
Linking, Linking,
NativeModules, NativeModules,
Platform, Platform,
StatusBar StatusBar,
} from 'react-native'; } from 'react-native';
import * as RNIap from 'react-native-iap'; import * as RNIap from 'react-native-iap';
import { enabled } from 'react-native-privacy-snapshot'; import {enabled} from 'react-native-privacy-snapshot';
import { SafeAreaProvider } from 'react-native-safe-area-context'; import {SafeAreaProvider} from 'react-native-safe-area-context';
import SplashScreen from 'react-native-splash-screen'; import SplashScreen from 'react-native-splash-screen';
import { useTracked } from './src/provider'; import {useTracked} from './src/provider';
import { Actions } from './src/provider/Actions'; import {Actions} from './src/provider/Actions';
import { DDS } from './src/services/DeviceDetection'; import {DDS} from './src/services/DeviceDetection';
import { import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent eUnSubscribeEvent,
} from './src/services/EventManager'; } from './src/services/EventManager';
import IntentService from './src/services/IntentService'; import IntentService from './src/services/IntentService';
import { clearMessage, setLoginMessage } from './src/services/Message'; import {
clearMessage,
setEmailVerifyMessage,
setLoginMessage,
} from './src/services/Message';
import Navigation from './src/services/Navigation'; import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService'; import PremiumService from './src/services/PremiumService';
import { editing } from './src/utils'; import {editing} from './src/utils';
import { COLOR_SCHEME } from './src/utils/Colors'; import {COLOR_SCHEME} from './src/utils/Colors';
import { db } from './src/utils/DB'; import {db} from './src/utils/DB';
import { import {
eClosePremiumDialog, eClosePremiumDialog,
eDispatchAction, eDispatchAction,
@@ -36,12 +40,12 @@ import {
eOpenPremiumDialog, eOpenPremiumDialog,
eOpenSideMenu, eOpenSideMenu,
eShowGetPremium, eShowGetPremium,
eStartSyncer eStartSyncer,
} from './src/utils/Events'; } from './src/utils/Events';
import { MMKV } from './src/utils/mmkv'; import {MMKV} from './src/utils/mmkv';
import { tabBarRef } from './src/utils/Refs'; import {tabBarRef} from './src/utils/Refs';
import { sleep } from './src/utils/TimeUtils'; import {sleep} from './src/utils/TimeUtils';
import { getNote } from './src/views/Editor/Functions'; import {getNote} from './src/views/Editor/Functions';
const {ReceiveSharingIntent} = NativeModules; const {ReceiveSharingIntent} = NativeModules;
let AppRootView = require('./initializer.root').RootView; let AppRootView = require('./initializer.root').RootView;
@@ -134,7 +138,7 @@ const App = () => {
}; };
const startSyncer = async () => { const startSyncer = async () => {
try { try {
let user = await db.user.get(); let user = await db.user.getUser();
if (user) { if (user) {
EV.subscribe('db:refresh', syncChanges); EV.subscribe('db:refresh', syncChanges);
} }
@@ -152,18 +156,24 @@ const App = () => {
let url = res ? res.url : ''; let url = res ? res.url : '';
try { try {
if (url.startsWith('ShareMedia://dataUrl')) { if (Platform.OS === 'ios' && url.startsWith('ShareMedia://dataUrl')) {
console.log(url);
_data = await ReceiveSharingIntent.getFileNames(url); _data = await ReceiveSharingIntent.getFileNames(url);
_data = IntentService.iosSortedData(_data); _data = IntentService.iosSortedData(_data);
}
if (_data) { if (_data) {
IntentService.setIntent(_data); IntentService.setIntent(_data);
IntentService.check((event) => { IntentService.check((event) => {
eSendEvent(eOnLoadNote, event); eSendEvent(eOnLoadNote, event);
tabBarRef.current?.goToPage(1); tabBarRef.current?.goToPage(1);
Navigation.closeDrawer(); Navigation.closeDrawer();
}); });
}
} else if (url.startsWith('https://notesnook.com/verify')) {
let user = await db.user.fetchUser();
dispatch({type: Actions.USER, user: user});
if (user.isEmailConfirmed) {
clearMessage(dispatch);
}
} }
} catch (e) { } catch (e) {
console.log(e, 'ERROR HERE'); console.log(e, 'ERROR HERE');
@@ -252,6 +262,7 @@ const App = () => {
try { try {
dispatch({type: Actions.SYNCING, syncing: true}); dispatch({type: Actions.SYNCING, syncing: true});
await db.sync(false); await db.sync(false);
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
} catch (e) { } catch (e) {
} finally { } finally {
dispatch({type: Actions.SYNCING, syncing: false}); dispatch({type: Actions.SYNCING, syncing: false});
@@ -270,9 +281,7 @@ const App = () => {
eSubscribeEvent('nointent', loadMainApp); eSubscribeEvent('nointent', loadMainApp);
Appearance.addChangeListener(onSystemThemeChanged); Appearance.addChangeListener(onSystemThemeChanged);
let unsub = NetInfo.addEventListener(onNetworkStateChanged); let unsub = NetInfo.addEventListener(onNetworkStateChanged);
if (Platform.OS === 'ios') { Linking.addEventListener('url', _handleIntent);
Linking.addEventListener('url', _handleIntent);
}
EV.subscribe('db:sync', dbSync); EV.subscribe('db:sync', dbSync);
EV.subscribe('user:checkStatus', handlePremiumAccess); EV.subscribe('user:checkStatus', handlePremiumAccess);
return () => { return () => {
@@ -285,9 +294,7 @@ const App = () => {
eUnSubscribeEvent('nointent', loadMainApp); eUnSubscribeEvent('nointent', loadMainApp);
AppState.removeEventListener('change', onAppStateChanged); AppState.removeEventListener('change', onAppStateChanged);
Appearance.removeChangeListener(onSystemThemeChanged); Appearance.removeChangeListener(onSystemThemeChanged);
if (Platform.OS === 'ios') { Linking.removeEventListener('url', _handleIntent);
Linking.removeEventListener('url', _handleIntent);
}
unsub(); unsub();
unsubIAP(); unsubIAP();
}; };
@@ -326,14 +333,19 @@ const App = () => {
const getUser = async () => { const getUser = async () => {
try { try {
let user = await db.user.get(); let user = await db.user.fetchUser();
if (user) { if (user) {
clearMessage(dispatch);
if (!user.isEmailConfirmed) {
setEmailVerifyMessage(dispatch);
}
dispatch({type: Actions.SYNCING, syncing: true}); dispatch({type: Actions.SYNCING, syncing: true});
dispatch({type: Actions.USER, user: user}); dispatch({type: Actions.USER, user: user});
await db.sync(); await db.sync();
dispatch({type: Actions.LAST_SYNC, lastSync: await db.lastSynced()});
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
await startSyncer(); await startSyncer();
clearMessage(dispatch);
} else { } else {
setLoginMessage(dispatch); setLoginMessage(dispatch);
} }

View File

@@ -27,9 +27,18 @@
android:windowSoftInputMode="adjustResize"> android:windowSoftInputMode="adjustResize">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
<intent-filter android:label="Notesnook">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https"
android:host="notesnook.com"
android:pathPrefix="/verify"></data>
</intent-filter>
</activity> </activity>
<activity <activity
android:name=".IntentActivity" android:name=".IntentActivity"
@@ -38,16 +47,12 @@
android:noHistory="true"> android:noHistory="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" /> <data android:mimeType="text/*" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" /> <action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/*" /> <data android:mimeType="text/*" />
</intent-filter> </intent-filter>
</activity> </activity>

View File

@@ -475,8 +475,7 @@ export const ActionSheetComponent = ({
ToastEvent.show(e.message, 'error', 'local', 5000); ToastEvent.show(e.message, 'error', 'local', 5000);
} }
} finally { } finally {
let user = await db.user.get(); dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
setRefreshing(false); setRefreshing(false);
} }

View File

@@ -1,19 +1,18 @@
import React, {useEffect, useState} from 'react'; import React, { useEffect, useState } from 'react';
import {Platform, StyleSheet, View} from 'react-native'; import { Platform, StyleSheet, View } from 'react-native';
import Animated from 'react-native-reanimated'; import { useSafeAreaInsets } from 'react-native-safe-area-context';
import {useSafeAreaInsets} from 'react-native-safe-area-context'; import { useTracked } from '../../provider';
import {useTracked} from '../../provider'; import { eSubscribeEvent, eUnSubscribeEvent } from '../../services/EventManager';
import {eSubscribeEvent, eUnSubscribeEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation'; import Navigation from '../../services/Navigation';
import { dWidth } from '../../utils';
import { eScrollEvent } from '../../utils/Events';
import { SIZE } from '../../utils/SizeUtils';
import { ActionIcon } from '../ActionIcon';
import { SearchInput } from '../SearchInput';
import { HeaderLeftMenu } from './HeaderLeftMenu';
import { HeaderRightMenu } from './HeaderRightMenu';
import { HeaderTitle } from './HeaderTitle';
import {dWidth} from '../../utils';
import {eScrollEvent} from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils';
import {ActionIcon} from '../ActionIcon';
import {SearchInput} from '../SearchInput';
import {HeaderLeftMenu} from './HeaderLeftMenu';
import {HeaderRightMenu} from './HeaderRightMenu';
import {HeaderTitle} from './HeaderTitle';
export const Header = ({root}) => { export const Header = ({root}) => {
const [state] = useTracked(); const [state] = useTracked();

View File

@@ -188,11 +188,12 @@ const LoginDialog = () => {
} }
try { try {
let user = await db.user.get(); let user = await db.user.getUser()
if (!user) throw new Error('Email or passoword incorrect!'); if (!user) throw new Error('Email or passoword incorrect!');
setStatus('Syncing Data'); setStatus('Syncing Data');
dispatch({type: Actions.USER, user: user}); dispatch({type: Actions.USER, user: user});
await db.sync(); await db.sync();
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
eSendEvent(eStartSyncer); eSendEvent(eStartSyncer);
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
eSendEvent(refreshNotesPage); eSendEvent(refreshNotesPage);
@@ -257,9 +258,10 @@ const LoginDialog = () => {
let user; let user;
try { try {
user = await db.user.get(); user = await db.user.getUser()
setStatus('Setting up crenditials'); setStatus('Setting up crenditials');
dispatch({type: Actions.USER, user: user}); dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
eSendEvent(eStartSyncer); eSendEvent(eStartSyncer);
clearMessage(dispatch); clearMessage(dispatch);
close(); close();

View File

@@ -57,8 +57,7 @@ export const UserSection = ({noTextMode}) => {
} catch (e) { } catch (e) {
ToastEvent.show(e.message, 'error'); ToastEvent.show(e.message, 'error');
} finally { } finally {
let user = await db.user.get(); dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
dispatch({ dispatch({
type: Actions.SYNCING, type: Actions.SYNCING,

View File

@@ -24,7 +24,7 @@ class PendingDialog extends React.Component {
async open() { async open() {
actionSheet.current?._setModalVisible(true); actionSheet.current?._setModalVisible(true);
let u = await db.user.get(); let u = await db.user.fetchUser();
this.setState({ this.setState({
user: u && u.Id ? u : null, user: u && u.Id ? u : null,
}); });

View File

@@ -48,7 +48,7 @@ class PremiumDialog extends React.Component {
async getSkus() { async getSkus() {
try { try {
let u = await db.user.get(); let u = await db.user.getUser()
this.setState({ this.setState({
user: u, user: u,
}); });

View File

@@ -126,7 +126,7 @@ class RecoveryKeyDialog extends React.Component {
onOpen = async () => { onOpen = async () => {
let k = await db.user.key(); let k = await db.user.key();
this.user = await db.user.get(); this.user = await db.user.getUser();
if (k) { if (k) {
this.setState({ this.setState({

View File

@@ -1,21 +1,20 @@
import React, {useEffect} from 'react'; import React, { useEffect } from 'react';
import {TouchableOpacity, View} from 'react-native'; import { View } from 'react-native';
import Animated, {Easing, useValue} from 'react-native-reanimated'; import Animated, { Easing, useValue } from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context'; import { useSafeAreaInsets } from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import { useTracked } from '../../provider';
import {useTracked} from '../../provider'; import { Actions } from '../../provider/Actions';
import {Actions} from '../../provider/Actions'; import { eSendEvent, ToastEvent } from '../../services/EventManager';
import {eSendEvent, ToastEvent} from '../../services/EventManager'; import { db } from '../../utils/DB';
import {db} from '../../utils/DB';
import { import {
eOpenMoveNoteDialog, eOpenMoveNoteDialog,
eOpenSimpleDialog, eOpenSimpleDialog,
refreshNotesPage, refreshNotesPage
} from '../../utils/Events'; } from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils'; import { SIZE } from '../../utils/SizeUtils';
import {sleep} from '../../utils/TimeUtils'; import { sleep } from '../../utils/TimeUtils';
import {ActionIcon} from '../ActionIcon'; import { ActionIcon } from '../ActionIcon';
import {TEMPLATE_DELETE} from '../DialogManager/Templates'; import { TEMPLATE_DELETE } from '../DialogManager/Templates';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
export const SelectionHeader = () => { export const SelectionHeader = () => {

View File

@@ -156,8 +156,7 @@ const SimpleList = ({
if (refreshCallback) { if (refreshCallback) {
refreshCallback(); refreshCallback();
} }
let user = await db.user.get(); dispatch({type: Actions.LAST_SYNC,lastSync: await db.lastSynced()});
dispatch({type: Actions.USER, user: user});
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
} }
}, []); }, []);

View File

@@ -31,5 +31,6 @@ export const Actions = {
LOADING:"loading", LOADING:"loading",
FULLSCREEN:"fullscreen", FULLSCREEN:"fullscreen",
DEVICE_MODE:"deviceMode", DEVICE_MODE:"deviceMode",
MENU_PINS:"menuPins" MENU_PINS:"menuPins",
LAST_SYNC:"lastSynced"
}; };

View File

@@ -81,5 +81,6 @@ export const defaultState = {
icon: 'account-outline', icon: 'account-outline',
}, },
keyword: [], keyword: [],
menuPins:[] menuPins:[],
lastSynced:"Never"
}; };

View File

@@ -259,6 +259,13 @@ export const reducer = (state, action) => {
menuPins: db.settings.pins, menuPins: db.settings.pins,
}; };
} }
case Actions.LAST_SYNC: {
return {
...state,
menuPins: action.lastSync,
};
}
default: default:
throw new Error('unknown action type'); throw new Error('unknown action type');
} }

View File

@@ -1,27 +1,50 @@
import { Actions } from "../provider/Actions"; import {Actions} from '../provider/Actions';
import { eOpenLoginDialog } from "../utils/Events"; import {eOpenLoginDialog} from '../utils/Events';
import { eSendEvent } from "./EventManager"; import {eSendEvent} from './EventManager';
export function setLoginMessage(dispatch) { export function setLoginMessage(dispatch) {
dispatch({type:Actions.MESSAGE_BOARD_STATE,state:{ dispatch({
visible:true, type: Actions.MESSAGE_BOARD_STATE,
message:'You are not logged in', state: {
actionText:"Login to sync your notes", visible: true,
onPress: () => { message: 'You are not logged in',
eSendEvent(eOpenLoginDialog); actionText: 'Login to sync your notes',
}, onPress: () => {
data:{}, eSendEvent(eOpenLoginDialog);
icon:'account-outline' },
}}); data: {},
icon: 'account-outline',
},
});
}
export function setEmailVerifyMessage(dispatch) {
dispatch({
type: Actions.MESSAGE_BOARD_STATE,
state: {
visible: true,
message: 'Email not verified',
actionText: 'Please verify your email to sync notes',
onPress: () => {
// Handle this
//eSendEvent(eOpen)
},
data: {},
icon: 'account-outline',
},
});
} }
export function clearMessage(dispatch) { export function clearMessage(dispatch) {
dispatch({type:Actions.MESSAGE_BOARD_STATE,state:{ dispatch({
visible:false, type: Actions.MESSAGE_BOARD_STATE,
message:'', state: {
actionText:"", visible: false,
onPress: null, message: '',
data:{}, actionText: '',
icon:'account-outline' onPress: null,
}}); data: {},
} icon: 'account-outline',
},
});
}

View File

@@ -7,7 +7,7 @@ let premiumStatus = true;
async function setPremiumStatus() { async function setPremiumStatus() {
try { try {
let user = await db.user.get(); let user = await db.user.getUser();
if (!user || !user.id) { if (!user || !user.id) {
premiumStatus = null; premiumStatus = null;
} else { } else {
@@ -30,7 +30,7 @@ async function verify(callback,error) {
return; */ return; */
try { try {
let user = await db.user.get(); let user = await db.user.getUser();
if (!user || !user.id || premiumStatus) { if (!user || !user.id || premiumStatus) {
if (error) { if (error) {

View File

@@ -31,6 +31,6 @@ export function validateUsername(username) {
} }
export async function checkPremiumUser() { export async function checkPremiumUser() {
let user = await db.user.get(); //let user = await db.user.get();
return false; return false;
} }