Save last session date on background
This commit is contained in:
parent
dc59232305
commit
ff64cbd5a1
|
@ -18,7 +18,7 @@ import {
|
||||||
import { isIOS } from '../utils/deviceInfo';
|
import { isIOS } from '../utils/deviceInfo';
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
import protectedFunction from '../lib/methods/helpers/protectedFunction';
|
import protectedFunction from '../lib/methods/helpers/protectedFunction';
|
||||||
import localAuthenticate from '../utils/localAuthentication';
|
import { localAuthenticate } from '../utils/localAuthentication';
|
||||||
|
|
||||||
export const initLocalSettings = function* initLocalSettings() {
|
export const initLocalSettings = function* initLocalSettings() {
|
||||||
const sortPreferences = yield RocketChat.getSortPreferences();
|
const sortPreferences = yield RocketChat.getSortPreferences();
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { FOREGROUND, BACKGROUND } from 'redux-enhancer-react-native-appstate';
|
||||||
import RocketChat from '../lib/rocketchat';
|
import RocketChat from '../lib/rocketchat';
|
||||||
import { setBadgeCount } from '../notifications/push';
|
import { setBadgeCount } from '../notifications/push';
|
||||||
import log from '../utils/log';
|
import log from '../utils/log';
|
||||||
import localAuthenticate from '../utils/localAuthentication';
|
import { localAuthenticate, saveLastLocalAuthenticationSession } from '../utils/localAuthentication';
|
||||||
import * as actions from '../actions';
|
import * as actions from '../actions';
|
||||||
|
|
||||||
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
const appHasComeBackToForeground = function* appHasComeBackToForeground() {
|
||||||
|
@ -39,7 +39,10 @@ const appHasComeBackToBackground = function* appHasComeBackToBackground() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return yield RocketChat.setUserPresenceAway();
|
yield RocketChat.setUserPresenceAway();
|
||||||
|
|
||||||
|
const server = yield select(state => state.server.server);
|
||||||
|
yield saveLastLocalAuthenticationSession(server);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,26 @@
|
||||||
import * as LocalAuthentication from 'expo-local-authentication';
|
import * as LocalAuthentication from 'expo-local-authentication';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
import database from '../lib/database';
|
import database from '../lib/database';
|
||||||
|
|
||||||
const localAuthenticate = async(server) => {
|
export const saveLastLocalAuthenticationSession = async(server) => {
|
||||||
|
console.log('saveLastLocalAuthenticationSession -> server', server);
|
||||||
|
const serversDB = database.servers;
|
||||||
|
const serversCollection = serversDB.collections.get('servers');
|
||||||
|
await serversDB.action(async() => {
|
||||||
|
try {
|
||||||
|
const serverRecord = await serversCollection.find(server);
|
||||||
|
console.log('saveLastLocalAuthenticationSession -> serverRecord', serverRecord);
|
||||||
|
await serverRecord.update((record) => {
|
||||||
|
record.lastLocalAuthenticatedSession = new Date();
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const localAuthenticate = async(server) => {
|
||||||
const serversDB = database.servers;
|
const serversDB = database.servers;
|
||||||
const serversCollection = serversDB.collections.get('servers');
|
const serversCollection = serversDB.collections.get('servers');
|
||||||
|
|
||||||
|
@ -14,12 +32,16 @@ const localAuthenticate = async(server) => {
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (serverRecord?.lastLocalAuthenticatedSession) {
|
const diffToLastSession = moment().diff(serverRecord?.lastLocalAuthenticatedSession, 'seconds');
|
||||||
|
console.log('localAuthenticate -> diffToLastSession', diffToLastSession);
|
||||||
// }
|
if (diffToLastSession >= 5) {
|
||||||
|
const authResult = await LocalAuthentication.authenticateAsync();
|
||||||
const authResult = await LocalAuthentication.authenticateAsync();
|
if (authResult?.success) {
|
||||||
return Promise.resolve(authResult?.success);
|
await saveLastLocalAuthenticationSession(server);
|
||||||
|
}
|
||||||
|
return Promise.resolve(authResult?.success);
|
||||||
|
} else {
|
||||||
|
await saveLastLocalAuthenticationSession(server);
|
||||||
|
}
|
||||||
|
return Promise.resolve(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default localAuthenticate;
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import { connect } from 'react-redux';
|
||||||
import equal from 'deep-equal';
|
import equal from 'deep-equal';
|
||||||
import { withNavigation } from 'react-navigation';
|
import { withNavigation } from 'react-navigation';
|
||||||
import RNUserDefaults from 'rn-user-defaults';
|
import RNUserDefaults from 'rn-user-defaults';
|
||||||
import * as LocalAuthentication from 'expo-local-authentication';
|
|
||||||
|
|
||||||
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
import { toggleServerDropdown as toggleServerDropdownAction } from '../../actions/rooms';
|
||||||
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
import { selectServerRequest as selectServerRequestAction } from '../../actions/server';
|
||||||
|
@ -23,7 +22,7 @@ import { withTheme } from '../../theme';
|
||||||
import { KEY_COMMAND, handleCommandSelectServer } from '../../commands';
|
import { KEY_COMMAND, handleCommandSelectServer } from '../../commands';
|
||||||
import { isTablet } from '../../utils/deviceInfo';
|
import { isTablet } from '../../utils/deviceInfo';
|
||||||
import { withSplit } from '../../split';
|
import { withSplit } from '../../split';
|
||||||
import localAuthenticate from '../../utils/localAuthentication';
|
import { localAuthenticate } from '../../utils/localAuthentication';
|
||||||
|
|
||||||
const ROW_HEIGHT = 68;
|
const ROW_HEIGHT = 68;
|
||||||
const ANIMATION_DURATION = 200;
|
const ANIMATION_DURATION = 200;
|
||||||
|
|
Loading…
Reference in New Issue