alpha
Jan Umbach 2023-03-14 22:26:02 +01:00
parent 17399c518c
commit 014246a78b
8 changed files with 110 additions and 70 deletions

View File

@ -26,75 +26,72 @@ import {initDatabase} from '@caj/helper/storage/bdm/init';
const AnimationView = animated(View); const AnimationView = animated(View);
function onAppStart() { export async function onAppStart() {
initAppData().then(async () => { await initAppData();
await initKey();
BigDataManager.initDatabase() await initKey();
.then(async () => {
const keys = BigDataManager.databases.chatRoomInfos.keys;
const entries =
(await BigDataManager.databases.chatRoomInfos.getAllEntries()) || [];
entries.sort((a, b) => BigDataManager.initDatabase()
a[keys.timestamp] > b[keys.timestamp] .then(async () => {
? 1 const keys = BigDataManager.databases.chatRoomInfos.keys;
: b[keys.timestamp] > a[keys.timestamp] const entries =
? -1 (await BigDataManager.databases.chatRoomInfos.getAllEntries()) || [];
: 0,
);
for (let i = 0; i < entries.length; i++) { entries.sort((a, b) =>
console.log(entries[i]); a[keys.timestamp] > b[keys.timestamp]
const chat = convertDatabaseChat(entries[i]); ? 1
if (chat === undefined) continue; : b[keys.timestamp] > a[keys.timestamp]
? -1
: 0,
);
await initDatabase(DBSchemas.chat, chat.roomId); for (let i = 0; i < entries.length; i++) {
console.log(entries[i]);
const chat = convertDatabaseChat(entries[i]);
if (chat === undefined) continue;
addChatEntity(chat); await initDatabase(DBSchemas.chat, chat.roomId);
if (chat.roomId === 'test') { addChatEntity(chat);
const chatDBKeys = BigDataManager.databases.chat.keys;
for (let i = 0; i < 10; i++) { if (chat.roomId === 'test') {
await BigDataManager.databases.chat.setEntry( const chatDBKeys = BigDataManager.databases.chat.keys;
{ for (let i = 0; i < 10; i++) {
[chatDBKeys.UserId]: MyUserManager.getSelectedUserId(), await BigDataManager.databases.chat.setEntry(
[chatDBKeys.msg]: 'heyho', {
}, [chatDBKeys.UserId]: MyUserManager.getSelectedUserId(),
chat.roomId, [chatDBKeys.data]: 'heyho',
); },
} chat.roomId,
);
} }
} }
}
console.log('finish'); console.log('finish');
const usrDBKeys = BigDataManager.databases.users.keys; const usrDBKeys = BigDataManager.databases.users.keys;
await BigDataManager.databases.users.setEntry({ await BigDataManager.databases.users.setEntry({
[usrDBKeys.UserId]: 'test', [usrDBKeys.UserId]: 'test',
[usrDBKeys.AccountName]: '#845613', [usrDBKeys.AccountName]: '#845613',
[usrDBKeys.Username]: 'TestGroupVirtual', [usrDBKeys.Username]: 'TestGroupVirtual',
[usrDBKeys.Description]: [usrDBKeys.Description]: 'This is a test account that is not real. ^^',
'This is a test account that is not real. ^^', [usrDBKeys.FollowersCount]: 2,
[usrDBKeys.FollowersCount]: 2, [usrDBKeys.FollowingCount]: 24,
[usrDBKeys.FollowingCount]: 24, [usrDBKeys.lastUpdateTimestamp]: 412341234,
[usrDBKeys.lastUpdateTimestamp]: 412341234, [usrDBKeys.ProfilePicture]: '',
[usrDBKeys.ProfilePicture]: '', [usrDBKeys.ProfilePictureBinaryHQ]: new ArrayBuffer(0),
[usrDBKeys.ProfilePictureBinaryHQ]: new ArrayBuffer(0), [usrDBKeys.ProfilePictureBinaryLQ]: new ArrayBuffer(0),
[usrDBKeys.ProfilePictureBinaryLQ]: new ArrayBuffer(0), [usrDBKeys.XpLevel]: 0,
[usrDBKeys.XpLevel]: 0, [usrDBKeys.XpPoints]: 0,
[usrDBKeys.XpPoints]: 0,
});
store.dispatch(
appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING),
);
})
.catch(err => {
console.error("Database Error! Can't start App :(", err);
}); });
//store.dispatch(actions.loadPreferences(appVar)); store.dispatch(appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING));
}); })
.catch(err => {
console.error("Database Error! Can't start App :(", err);
});
//store.dispatch(actions.loadPreferences(appVar));
} }
function StartHelper() { function StartHelper() {
@ -136,7 +133,11 @@ function StartHelper() {
}); });
}, []); }, []);
useEffect(onAppStart, []); useEffect(() => {
(async () => {
await onAppStart();
})();
}, []);
if (currentAppStatus === appStatus.APP_RUNNING) return null; if (currentAppStatus === appStatus.APP_RUNNING) return null;

View File

@ -54,6 +54,7 @@ import MostPopularPasswords from '@caj/helper/password-quality-calculator/MostPo
import MyUserManager from '@caj/user/MyUserManager'; import MyUserManager from '@caj/user/MyUserManager';
import {Buffer} from 'buffer'; import {Buffer} from 'buffer';
import {onAppStart} from '@caj/../appStart/StartHelper';
// Load the popular passwords list // Load the popular passwords list
PasswordQualityCalculator.PopularPasswords.load(MostPopularPasswords); PasswordQualityCalculator.PopularPasswords.load(MostPopularPasswords);
@ -1129,7 +1130,7 @@ function StepFinal() {
WebSocketSessionId: '', WebSocketSessionId: '',
}, },
}) })
.then(resp => { .then(async resp => {
if ( if (
resp.response.XAuthorization !== '' && resp.response.XAuthorization !== '' &&
resp.response.UserId !== '' && resp.response.UserId !== '' &&
@ -1151,6 +1152,7 @@ function StepFinal() {
resp.response.XAuthorization, resp.response.XAuthorization,
resp.response.WebSocketSessionId, resp.response.WebSocketSessionId,
); );
await onAppStart();
navigation.popToTop(); navigation.popToTop();
navigation.goBack(); navigation.goBack();
} }
@ -1284,7 +1286,7 @@ function Login() {
resp.response.XAuthorization, resp.response.XAuthorization,
resp.response.WebSocketSessionId, resp.response.WebSocketSessionId,
) )
.then(() => { .then(async () => {
showToast(toast, { showToast(toast, {
title: lang.account.login.success, title: lang.account.login.success,
variant: 'solid', variant: 'solid',
@ -1295,6 +1297,7 @@ function Login() {
}); });
setLoading(false); setLoading(false);
await onAppStart();
navigation.goBack(); navigation.goBack();
}) })
.catch(() => { .catch(() => {

View File

@ -1,10 +1,15 @@
import {appNonSaveVarActions} from '@caj/configs/appNonSaveVarReducer'; import {appNonSaveVarActions} from '@caj/configs/appNonSaveVarReducer';
import {initDatabase} from '@caj/helper/storage/bdm/init';
import DBSchemas from '@caj/helper/storage/bdm/schemas';
import BigDataManager from '@caj/helper/storage/BigDataManager'; import BigDataManager from '@caj/helper/storage/BigDataManager';
import {store} from '@caj/redux/store'; import {store} from '@caj/redux/store';
import {chatEntity} from './types'; import {chatEntity} from './types';
async function initChatDatabase(chat: chatEntity) { async function initChatDatabase(chat: chatEntity) {
const keys = BigDataManager.databases.chatRoomInfos.keys; const keys = BigDataManager.databases.chatRoomInfos.keys;
await initDatabase(DBSchemas.chat, chat.roomId);
await BigDataManager.databases.chatRoomInfos.setEntry({ await BigDataManager.databases.chatRoomInfos.setEntry({
[keys.RoomId]: chat.roomId, [keys.RoomId]: chat.roomId,
[keys.initSyncId]: chat.initSyncId, [keys.initSyncId]: chat.initSyncId,

View File

@ -16,7 +16,7 @@ export const getEntry = async <T2 extends databaseConf<T, any>, T>(
const realm = await getDatabase(nameObj); const realm = await getDatabase(nameObj);
const val = realm.objectForPrimaryKey<typeof schema.details.properties>( const val = realm.objectForPrimaryKey<typeof schema.details.properties>(
dbName, nameObj.name,
key, key,
); );
@ -33,7 +33,7 @@ export const getAllEntries = async <T2 extends databaseConf<T, any>, T>(
const realm = await getDatabase(nameObj); const realm = await getDatabase(nameObj);
const val = realm.objects<typeof schema.details.properties>(dbName); const val = realm.objects<typeof schema.details.properties>(nameObj.name);
return [...val] as T[]; return [...val] as T[];
}; };

View File

@ -77,12 +77,17 @@ export async function openMyDatabase(
await RNFS.mkdir(RNFS.DocumentDirectoryPath + '/' + folderPath); await RNFS.mkdir(RNFS.DocumentDirectoryPath + '/' + folderPath);
} }
return await Realm.open({ console.log('schema.details', schema.details);
const realm = await Realm.open({
schema: [schema.details as any], schema: [schema.details as any],
schemaVersion: schema.version, schemaVersion: schema.version,
path, path,
encryptionKey: getKey(), encryptionKey: getKey(),
}); });
console.log('path', path);
return realm;
} }
export async function getDatabase( export async function getDatabase(

View File

@ -27,6 +27,7 @@ export const initDatabase = async (
name: schema.details.name, name: schema.details.name,
suffix: fileSuffix, suffix: fileSuffix,
}; };
console.log('initDatabase', _nameObj);
const name = mergeDBName(_nameObj); const name = mergeDBName(_nameObj);
let dbObj: DBObject = { let dbObj: DBObject = {

View File

@ -5,21 +5,46 @@ import {setEntry} from '../set';
import {databaseConf, possibleDBKeys} from '../types'; import {databaseConf, possibleDBKeys} from '../types';
enum keys { enum keys {
UserId = 'a', syncID = "a",
msg = 'b', UserId = 'b',
data = 'c',
massageType = "d",
created_at = "e",
received_by_server = "f",
received_by_target_clients = "g",
reply = "h",
reactions = "i",
hasRead = "j",
} }
const name = 'chat'; const name = 'chat';
const primaryKey: keyof typeof propsDefault = keys.UserId; const primaryKey: keyof typeof propsDefault = keys.UserId;
const propsType: {[key in keyof typeof propsDefault]: string} = { const propsType: {[key in keyof typeof propsDefault]: string} = {
[keys.syncID]: "int",
[keys.UserId]: 'string', [keys.UserId]: 'string',
[keys.msg]: 'string', [keys.data]: 'data',
[keys.massageType]: "int",
[keys.created_at]: "int",
[keys.received_by_server]: "int",
[keys.received_by_target_clients]: "int",
[keys.reply]: "int",
[keys.reactions]: "i",
[keys.hasRead]: "j",
}; };
const propsDefault = { const propsDefault = {
[keys.UserId]: 'test', [keys.syncID]: "a",
[keys.msg]: 'test', [keys.UserId]: 'b',
[keys.data]: 'c',
[keys.massageType]: "d",
[keys.created_at]: "e",
[keys.received_by_server]: "f",
[keys.received_by_target_clients]: "g",
[keys.reply]: "h",
[keys.reactions]: "i",
[keys.hasRead]: "j",
}; };
const thisSchema: databaseConf<typeof propsDefault, typeof keys> = { const thisSchema: databaseConf<typeof propsDefault, typeof keys> = {

View File

@ -12,6 +12,6 @@ export const setEntry = async <T2 extends databaseConf<T, any>, T>(
const realm = await getDatabase(nameObj); const realm = await getDatabase(nameObj);
realm.write(() => { realm.write(() => {
realm.create(dbName, value as any, Realm.UpdateMode.Modified); realm.create(nameObj.name, value as any, Realm.UpdateMode.Modified);
}); });
}; };