diff --git a/src/appStart/StartHelper.tsx b/src/appStart/StartHelper.tsx
index 38d5142..4483171 100644
--- a/src/appStart/StartHelper.tsx
+++ b/src/appStart/StartHelper.tsx
@@ -20,7 +20,7 @@ import {initKey} from '@caj/helper/storage/bdm/encryption';
import UserManager from '@caj/user/UserManager';
import MyUserManager from '@caj/user/MyUserManager';
import DBSchemas from '@caj/helper/storage/bdm/schemas';
-import {chatTags, chatType} from '@caj/components/chat/types';
+import {chatTags} from '@caj/components/chat/types';
const AnimationView = animated(View);
@@ -31,41 +31,26 @@ function onAppStart() {
BigDataManager.initDatabase()
.then(async () => {
console.log('finish');
+ const usrDBKeys = BigDataManager.databases.users.keys;
await BigDataManager.databases.users.setEntry({
- UserId: 'test',
- AccountName: '#845613',
- Username: 'TestGroupVirtual',
- Description: 'This is a test account that is not real. ^^',
- FollowersCount: 2,
- FollowingCount: 24,
- lastUpdateTimestamp: 412341234,
- ProfilePicture: '',
- ProfilePictureBinaryHQ: new ArrayBuffer(0),
- ProfilePictureBinaryLQ: new ArrayBuffer(0),
- XpLevel: 0,
- XpPoints: 0,
+ [usrDBKeys.UserId]: 'test',
+ [usrDBKeys.AccountName]: '#845613',
+ [usrDBKeys.Username]: 'TestGroupVirtual',
+ [usrDBKeys.Description]:
+ 'This is a test account that is not real. ^^',
+ [usrDBKeys.FollowersCount]: 2,
+ [usrDBKeys.FollowingCount]: 24,
+ [usrDBKeys.lastUpdateTimestamp]: 412341234,
+ [usrDBKeys.ProfilePicture]: '',
+ [usrDBKeys.ProfilePictureBinaryHQ]: new ArrayBuffer(0),
+ [usrDBKeys.ProfilePictureBinaryLQ]: new ArrayBuffer(0),
+ [usrDBKeys.XpLevel]: 0,
+ [usrDBKeys.XpPoints]: 0,
});
store.dispatch(
appNonSaveVarActions.setAppStatus(appStatus.APP_RUNNING),
);
-
- store.dispatch(
- appNonSaveVarActions.setChatEntity({
- id: MyUserManager.getSelectedUserId(),
- type: chatType.User,
- tags: [chatTags.GOOD_FRIEND],
- unreadMessages: 1234,
- }),
- );
- store.dispatch(
- appNonSaveVarActions.setChatEntity({
- id: 'test',
- type: chatType.User,
- tags: [chatTags.GROUP, chatTags.GOOD_FRIEND, chatTags.FRIEND],
- unreadMessages: 0,
- }),
- );
})
.catch(err => {
console.error("Database Error! Can't start App :(", err);
diff --git a/src/caj/components/NotLoggedIn.tsx b/src/caj/components/NotLoggedIn.tsx
index a907bc1..28cfccc 100644
--- a/src/caj/components/NotLoggedIn.tsx
+++ b/src/caj/components/NotLoggedIn.tsx
@@ -980,7 +980,7 @@ function StepFinal() {
icon={
}
@@ -1413,7 +1413,7 @@ function Login() {
icon={
}
diff --git a/src/caj/components/chat/initChatDatabase.ts b/src/caj/components/chat/initChatDatabase.ts
new file mode 100644
index 0000000..775f899
--- /dev/null
+++ b/src/caj/components/chat/initChatDatabase.ts
@@ -0,0 +1,18 @@
+import {appNonSaveVarActions} from '@caj/configs/appNonSaveVarReducer';
+import BigDataManager from '@caj/helper/storage/BigDataManager';
+import {store} from '@caj/redux/store';
+import {chatEntity} from './types';
+
+async function initChatDatabase(chat: chatEntity) {
+ const keys = BigDataManager.databases.chatRoomInfos.keys;
+ await BigDataManager.databases.chatRoomInfos.setEntry({
+ [keys.RoomId]: chat.roomId,
+ [keys.initSyncId]: chat.initSyncId,
+ [keys.syncId]: chat.syncId,
+ [keys.unreadMessages]: chat.unreadMessages,
+ [keys.users]: chat.users,
+ });
+ store.dispatch(appNonSaveVarActions.setChatEntity(chat));
+}
+
+export default initChatDatabase;
diff --git a/src/caj/components/chat/listChats.tsx b/src/caj/components/chat/listChats.tsx
index 515565f..8cd5cca 100644
--- a/src/caj/components/chat/listChats.tsx
+++ b/src/caj/components/chat/listChats.tsx
@@ -1,9 +1,11 @@
import {appNonSaveVarActions} from '@caj/configs/appNonSaveVarReducer';
+import {ThemeMode} from '@caj/configs/appVar';
import {
darkThemeStyle,
getBackgroundColor,
themeSelector,
} from '@caj/configs/colors';
+import LangFormat from '@caj/lang/default';
import {HomeScreenNavigationProp} from '@caj/Navigation';
import {RootState, store} from '@caj/redux/store';
import {ChatScreenNavigationProp} from '@caj/tabs/main/ChatTab';
@@ -14,7 +16,149 @@ import {useSelector} from 'react-redux';
import {start} from 'repl';
import {ProfilePicture} from '../ProfilePicture';
import {TextSkeleton} from '../simple/Skeleton';
-import {chatType, getTagUI} from './types';
+import {chatEntity, getTagUI} from './types';
+
+function ChatItem(props: {
+ chat: chatEntity;
+ navigation: HomeScreenNavigationProp;
+ theme: ThemeMode;
+ ppSize: number;
+ tagSize: number;
+ space: number;
+ lang: LangFormat;
+}) {
+ const chat = props.chat;
+ const navigation = props.navigation;
+ const theme = props.theme;
+ const ppSize = props.ppSize;
+ const tagSize = props.tagSize;
+ const space = props.space;
+ const lang = props.lang;
+
+ const roomId = chat.roomId;
+ const user = UserManager.getUserSelector(chat.users[0]);
+
+ return (
+ {
+ store.dispatch(appNonSaveVarActions.setSelectedChat(roomId));
+ navigation.navigate('ChatList', {screen: 'Chat'});
+ //navigation.navigate('Register', {screen: 'RegStepOne'});
+ }}>
+ {({isHovered, isFocused, isPressed}) => {
+ return (
+ 0 ? tagSize / 2 + 'px' : ppSize / 2 + 'px'
+ }
+ marginX={space + 'px'}
+ padding={space + 'px'}>
+
+
+
+ {user.AccountName.data}
+
+
+
+
+ {chat.unreadMessages}
+
+
+
+
+
+
+
+
+ {user.Username.data}
+
+
+ {'I love Chicken McNuggets von Burgerking'}
+
+
+
+ {chat.tags.length > 0 ? (
+
+ {chat.tags.map((tag, i) => {
+ const tagObj = getTagUI(tag, lang);
+
+ let tagName = tagObj.name;
+ return (
+
+
+ {tagName}
+
+
+ );
+ })}
+
+ ) : null}
+
+
+ );
+ }}
+
+ );
+}
export function ListChats() {
const theme = themeSelector();
@@ -42,139 +186,21 @@ export function ListChats() {
space={tagSize * 0.3 + space + 'px'}
width="100%"
marginY={space + 'px'}>
- {chatActivity.map((chatId, i) => {
- const chat = chats[chatId];
- if (chat.type === chatType.User) {
- const user = UserManager.getUserSelector(chatId);
+ {chatActivity.map((roomId, i) => {
+ const chat = chats[roomId];
- return (
- {
- store.dispatch(appNonSaveVarActions.setSelectedChat(chatId));
- navigation.navigate('ChatList', {screen: 'Chat'});
- //navigation.navigate('Register', {screen: 'RegStepOne'});
- }}>
- {({isHovered, isFocused, isPressed}) => {
- return (
- 0
- ? tagSize / 2 + 'px'
- : ppSize / 2 + 'px'
- }
- marginX={space + 'px'}
- padding={space + 'px'}>
-
-
-
- {user.AccountName.data}
-
-
-
-
- {chat.unreadMessages}
-
-
-
-
-
-
-
-
- {user.Username.data}
-
-
- {'I love Chicken McNuggets von Burgerking'}
-
-
-
- {chat.tags.length > 0 ? (
-
- {chat.tags.map((tag, i) => {
- const tagObj = getTagUI(tag, lang);
-
- let tagName = tagObj.name;
- return (
-
-
- {tagName}
-
-
- );
- })}
-
- ) : null}
-
-
- );
- }}
-
- );
- }
+ return (
+
+ );
})}
);
diff --git a/src/caj/components/chat/types.ts b/src/caj/components/chat/types.ts
index 7d6307c..ced17f8 100644
--- a/src/caj/components/chat/types.ts
+++ b/src/caj/components/chat/types.ts
@@ -1,13 +1,6 @@
import {UserId} from '@caj/configs/types';
import LangFormat from '@caj/lang/default';
-type GroupId = string;
-
-export enum chatType {
- User = 0,
- Group = 1,
-}
-
export enum chatTags {
GROUP = 0,
FRIEND = 1,
@@ -52,12 +45,20 @@ export function getTagUI(tagKey: chatTags, lang?: LangFormat): tagUITypeFinal {
return tag as tagUITypeFinal;
}
-export type chatId = UserId | GroupId;
+export type roomId = string;
+type syncId = number;
export interface chatEntity {
- type: chatType;
- id: chatId;
+ roomId: roomId;
+
+
+ syncId: syncId;
+ initSyncId: syncId;
+
+
+ users: [UserId, ...UserId[]];
title?: string;
unreadMessages: number;
+
tags: chatTags[];
-}
\ No newline at end of file
+}
diff --git a/src/caj/configs/appNonSaveVar.ts b/src/caj/configs/appNonSaveVar.ts
index 8a3a6a5..59d6927 100644
--- a/src/caj/configs/appNonSaveVar.ts
+++ b/src/caj/configs/appNonSaveVar.ts
@@ -1,6 +1,6 @@
//these variables should not changed by the user and will not be saved in storage
-import {chatEntity, chatId} from '@caj/components/chat/types';
+import {chatEntity, roomId} from '@caj/components/chat/types';
import {getVersionByNum, VersionType} from '@caj/helper/version';
import {User} from '@caj/user/types';
import {UserId} from './types';
@@ -26,9 +26,9 @@ export interface NON_SAVE_VARS {
appStatus: appStatus;
connectionStatus: connectionStatus;
cachedUsers: {[key: UserId]: User};
- chats: {[key: chatId]: chatEntity};
- chatActivity: chatId[];
- selectedChat: chatId | 'none';
+ chats: {[key: roomId]: chatEntity};
+ chatActivity: roomId[];
+ selectedChat: roomId | 'none';
}
export const non_save_vars: NON_SAVE_VARS = {
diff --git a/src/caj/configs/appNonSaveVarReducer.ts b/src/caj/configs/appNonSaveVarReducer.ts
index 019d057..3958662 100644
--- a/src/caj/configs/appNonSaveVarReducer.ts
+++ b/src/caj/configs/appNonSaveVarReducer.ts
@@ -4,7 +4,7 @@ import type {PayloadAction} from '@reduxjs/toolkit';
import {appStatus, non_save_vars} from './appNonSaveVar';
import {User} from '@caj/user/types';
import {UserId} from './types';
-import {chatEntity, chatId} from '@caj/components/chat/types';
+import {chatEntity, roomId} from '@caj/components/chat/types';
export const appNonSaveVariablesSlice = createSlice({
name: 'non_save_vars',
@@ -19,29 +19,29 @@ export const appNonSaveVariablesSlice = createSlice({
removeCachedUser: (state, action: PayloadAction) => {
delete state.cachedUsers[action.payload];
},
- setSelectedChat: (state, action: PayloadAction) => {
+ setSelectedChat: (state, action: PayloadAction) => {
state.selectedChat = action.payload;
},
setChatEntity: (state, action: PayloadAction) => {
- const chatId = action.payload.id;
+ const roomId = action.payload.roomId;
- state.chats[chatId] = action.payload;
+ state.chats[roomId] = action.payload;
- if (state.chatActivity.includes(chatId) === false)
- state.chatActivity.unshift(chatId);
+ if (state.chatActivity.includes(roomId) === false)
+ state.chatActivity.unshift(roomId);
},
changeChatEntity: (state, action: PayloadAction) => {
- const chatId = action.payload.id;
+ const roomId = action.payload.roomId;
- state.chats[chatId] = action.payload;
+ state.chats[roomId] = action.payload;
- if (state.chatActivity.includes(chatId) === false)
- state.chatActivity.unshift(chatId);
+ if (state.chatActivity.includes(roomId) === false)
+ state.chatActivity.unshift(roomId);
state.chatActivity.sort(function (x, y) {
- return x == chatId ? -1 : y == chatId ? 1 : 0;
+ return x == roomId ? -1 : y == roomId ? 1 : 0;
});
},
- removeChatEntity: (state, action: PayloadAction) => {
+ removeChatEntity: (state, action: PayloadAction) => {
delete state.chats[action.payload];
state.chatActivity = state.chatActivity.filter(function (ele) {
diff --git a/src/caj/helper/storage/bdm/get.ts b/src/caj/helper/storage/bdm/get.ts
index bc2271a..9489da6 100644
--- a/src/caj/helper/storage/bdm/get.ts
+++ b/src/caj/helper/storage/bdm/get.ts
@@ -1,7 +1,7 @@
import {getDatabase} from './getDB';
import {databaseConf, possibleDBKeys} from './types';
-export const getEntry = async , T>(
+export const getEntry = async , T>(
schema: T2,
key: possibleDBKeys,
): Promise => {
diff --git a/src/caj/helper/storage/bdm/get.web.ts b/src/caj/helper/storage/bdm/get.web.ts
index 1c52c1d..785c5f4 100644
--- a/src/caj/helper/storage/bdm/get.web.ts
+++ b/src/caj/helper/storage/bdm/get.web.ts
@@ -1,7 +1,7 @@
import {getDatabase} from './getDB.web';
import {databaseConf, possibleDBKeys} from './types';
-export const getEntry = async , T>(
+export const getEntry = async , T>(
schema: T2,
key: possibleDBKeys,
): Promise => {
diff --git a/src/caj/helper/storage/bdm/getDB.ts b/src/caj/helper/storage/bdm/getDB.ts
index a3b7a52..ed3b0ac 100644
--- a/src/caj/helper/storage/bdm/getDB.ts
+++ b/src/caj/helper/storage/bdm/getDB.ts
@@ -5,6 +5,7 @@ import {getKey} from './encryption';
import {databaseConf, databaseNames} from './types';
import RNFS from 'react-native-fs';
+import {databaseConfType} from './schemas';
const closeTimeout = 5; // in seconds // when DB read/writes is too long in idle it will be closed
@@ -12,7 +13,7 @@ type DBType = Realm;
export interface DBObject {
name: databaseNames;
- schema: databaseConf<{[key: string]: string}>;
+ schema: databaseConfType;
db: DBType | undefined;
lastUsedTimestamp?: timestamp; // when timeout is undefined then db is closed
}
@@ -53,7 +54,7 @@ export function closeAllDatabases() {
}
export async function openMyDatabase(
- schema: databaseConf<{[key: string]: string}>,
+ schema: databaseConfType,
): Promise {
const folderPath = MyUserManager.getSelectedUserId();
const path = folderPath + '/' + schema.filePath;
diff --git a/src/caj/helper/storage/bdm/getDB.web.ts b/src/caj/helper/storage/bdm/getDB.web.ts
index 245ce56..8337d93 100644
--- a/src/caj/helper/storage/bdm/getDB.web.ts
+++ b/src/caj/helper/storage/bdm/getDB.web.ts
@@ -1,6 +1,7 @@
import {timestamp} from '@caj/configs/types';
import MyUserManager from '@caj/user/MyUserManager';
import {IDBPDatabase, openDB} from 'idb';
+import {databaseConfType} from './schemas';
import {databaseConf, databaseNames} from './types';
const closeTimeout = 5; // in seconds // when DB read/writes is too long in idle it will be closed
@@ -9,7 +10,7 @@ type DBType = IDBPDatabase;
export interface DBObject {
name: databaseNames;
- schema: databaseConf<{[key: string]: string}>;
+ schema: databaseConfType;
db: DBType | undefined;
lastUsedTimestamp?: timestamp; // when timeout is undefined then db is closed
}
@@ -50,7 +51,7 @@ export function closeAllDatabases() {
}
export async function openMyDatabase(
- schema: databaseConf<{[key: string]: string}>,
+ schema: databaseConfType,
init?: boolean,
): Promise {
const db = await openDB(
diff --git a/src/caj/helper/storage/bdm/init.ts b/src/caj/helper/storage/bdm/init.ts
index 0e4cc44..0c2f3d3 100644
--- a/src/caj/helper/storage/bdm/init.ts
+++ b/src/caj/helper/storage/bdm/init.ts
@@ -1,6 +1,7 @@
import {openDB, deleteDB, wrap, unwrap} from 'idb';
import {closeAllDatabases, databases, DBObject, getDatabase} from './getDB';
import DBSchemas from './schemas';
+import {databaseConf} from './types';
export const initDatabase = (): Promise => {
return new Promise(async (resolve, reject) => {
diff --git a/src/caj/helper/storage/bdm/migration.ts b/src/caj/helper/storage/bdm/migration.ts
index 168f809..f0c9f13 100644
--- a/src/caj/helper/storage/bdm/migration.ts
+++ b/src/caj/helper/storage/bdm/migration.ts
@@ -3,7 +3,7 @@ import DBSchemas from './schemas';
import {databaseConf, databaseNames} from './types';
export const DBMigration: {[key in databaseNames]: any} = {
- users: (Schema: databaseConf) => {
+ users: (Schema: typeof DBSchemas.users) => {
const callback: MigrationCallback = (oldRealm, newRealm) => {
/*// only apply this change if upgrading to schemaVersion 2
if (oldRealm.schemaVersion < 2) {
@@ -20,7 +20,7 @@ export const DBMigration: {[key in databaseNames]: any} = {
return callback;
},
- chat: (Schema: databaseConf) => {
+ chat: (Schema: typeof DBSchemas.chat) => {
const callback: MigrationCallback = (oldRealm, newRealm) => {
/*// only apply this change if upgrading to schemaVersion 2
if (oldRealm.schemaVersion < 2) {
@@ -35,6 +35,11 @@ export const DBMigration: {[key in databaseNames]: any} = {
}*/
};
+ return callback;
+ },
+ chatRoomInfos: (Schema: typeof DBSchemas.chatRoomInfos) => {
+ const callback: MigrationCallback = (oldRealm, newRealm) => {};
+
return callback;
},
};
diff --git a/src/caj/helper/storage/bdm/migration.web.ts b/src/caj/helper/storage/bdm/migration.web.ts
index 7c6a9d9..410c1c1 100644
--- a/src/caj/helper/storage/bdm/migration.web.ts
+++ b/src/caj/helper/storage/bdm/migration.web.ts
@@ -21,7 +21,7 @@ type upgradeFunc = (
) => void;
export const DBMigration: {[key in databaseNames]: any} = {
- users: (Schema: databaseConf) => {
+ users: (Schema: typeof DBSchemas.users) => {
const callback: upgradeFunc = (
db,
oldVersion,
@@ -47,7 +47,33 @@ export const DBMigration: {[key in databaseNames]: any} = {
return callback;
},
- chat: (Schema: databaseConf) => {
+ chat: (Schema: typeof DBSchemas.chat) => {
+ const callback: upgradeFunc = (
+ db,
+ oldVersion,
+ newVersion,
+ transaction,
+ event,
+ ) => {
+ if (oldVersion == 0) {
+ // perform the initialization
+ db.createObjectStore(Schema.details.name, {
+ keyPath: Schema.details.primaryKey,
+ });
+ } else if (newVersion !== null) {
+ let ver = oldVersion;
+
+ while (ver < newVersion) {
+ console.log('upgrade from v', ver, ' to v', ver + 1);
+
+ ver++;
+ }
+ }
+ };
+
+ return callback;
+ },
+ chatRoomInfos: (Schema: typeof DBSchemas.chatRoomInfos) => {
const callback: upgradeFunc = (
db,
oldVersion,
diff --git a/src/caj/helper/storage/bdm/schemas.ts b/src/caj/helper/storage/bdm/schemas.ts
index 4032731..f8a1bc1 100644
--- a/src/caj/helper/storage/bdm/schemas.ts
+++ b/src/caj/helper/storage/bdm/schemas.ts
@@ -1,5 +1,7 @@
import chat from './schemas/chat';
import users from './schemas/users';
+import chatRoomInfos from './schemas/chatRoomInfos';
-const DBSchemas = {users, chat};
+const DBSchemas = {users, chat, chatRoomInfos};
export default DBSchemas;
+export type databaseConfType = typeof DBSchemas[keyof typeof DBSchemas];
diff --git a/src/caj/helper/storage/bdm/schemas/chat.ts b/src/caj/helper/storage/bdm/schemas/chat.ts
index babee26..df72411 100644
--- a/src/caj/helper/storage/bdm/schemas/chat.ts
+++ b/src/caj/helper/storage/bdm/schemas/chat.ts
@@ -4,22 +4,28 @@ import {setEntry} from '../set';
import {databaseConf, possibleDBKeys} from '../types';
+enum keys {
+ UserId = 'a',
+ msg = 'b',
+}
+
const name = 'chat';
-const primaryKey: keyof typeof propsDefault = 'UserId';
+const primaryKey: keyof typeof propsDefault = keys.UserId;
const propsType: {[key in keyof typeof propsDefault]: string} = {
- UserId: 'string',
- msg: 'string',
+ [keys.UserId]: 'string',
+ [keys.msg]: 'string',
};
const propsDefault = {
- UserId: 'test',
- msg: 'test',
+ [keys.UserId]: 'test',
+ [keys.msg]: 'test',
};
-const thisSchema: databaseConf = {
+const thisSchema: databaseConf = {
filePath: name,
version: 1,
+ keys,
migration: () => {
return DBMigration[name](thisSchema);
},
diff --git a/src/caj/helper/storage/bdm/schemas/chatRoomInfos.ts b/src/caj/helper/storage/bdm/schemas/chatRoomInfos.ts
new file mode 100644
index 0000000..3772ea0
--- /dev/null
+++ b/src/caj/helper/storage/bdm/schemas/chatRoomInfos.ts
@@ -0,0 +1,61 @@
+import {getEntry} from '../get';
+import {DBMigration} from '../migration';
+import {setEntry} from '../set';
+
+import {databaseConf, possibleDBKeys} from '../types';
+
+enum keys {
+ RoomId = 'a',
+ syncId = 'b',
+ initSyncId = 'c',
+ unreadMessages = 'd',
+ users = 'e',
+}
+
+const name = 'chatRoomInfos';
+const primaryKey: keyof typeof propsDefault = keys.RoomId;
+
+const propsType: {[key in keyof typeof propsDefault]: string} = {
+ [keys.RoomId]: 'string',
+ [keys.syncId]: 'int',
+ [keys.initSyncId]: 'int',
+ [keys.unreadMessages]: 'int',
+ [keys.users]: 'string[]',
+};
+
+const propsDefault = {
+ [keys.RoomId]: '',
+ [keys.syncId]: 0,
+ [keys.initSyncId]: 0,
+ [keys.unreadMessages]: 0,
+ [keys.users]: ['none'],
+};
+
+const thisSchema: databaseConf = {
+ filePath: name,
+ version: 1,
+ keys,
+ migration: () => {
+ return DBMigration[name](thisSchema);
+ },
+ setEntry: (val: typeof thisSchema.defaultProps) => {
+ return setEntry(
+ thisSchema,
+ val,
+ );
+ },
+ getEntry: (key: possibleDBKeys) => {
+ return getEntry(
+ thisSchema,
+ key,
+ );
+ },
+ defaultProps: propsDefault,
+ details: {
+ name,
+ properties: propsType,
+ primaryKey,
+ },
+};
+
+export default thisSchema;
diff --git a/src/caj/helper/storage/bdm/schemas/users.ts b/src/caj/helper/storage/bdm/schemas/users.ts
index 6ed463f..5ed081d 100644
--- a/src/caj/helper/storage/bdm/schemas/users.ts
+++ b/src/caj/helper/storage/bdm/schemas/users.ts
@@ -4,43 +4,60 @@ import {setEntry} from '../set';
import {databaseConf, possibleDBKeys} from '../types';
+enum keys {
+ UserId = 'a',
+ AccountName = 'b',
+ Username = 'c',
+ Description = 'd',
+ FollowersCount = 'e',
+ FollowingCount = 'f',
+ lastUpdateTimestamp = 'g',
+ ProfilePicture = 'h',
+ ProfilePictureBinaryLQ = 'i',
+ ProfilePictureBinaryHQ = 'j',
+
+ XpLevel = 'k',
+ XpPoints = 'l',
+}
+
const name = 'users';
-const primaryKey: keyof typeof propsDefault = 'UserId';
+const primaryKey: keyof typeof propsDefault = keys.UserId;
const propsType: {[key in keyof typeof propsDefault]: string} = {
- UserId: 'string',
- AccountName: 'string',
- Username: 'string',
- Description: 'string',
- FollowersCount: 'int',
- FollowingCount: 'int',
- lastUpdateTimestamp: 'int',
- ProfilePicture: 'string', //URL
- ProfilePictureBinaryLQ: 'data',
- ProfilePictureBinaryHQ: 'data',
+ [keys.UserId]: 'string',
+ [keys.AccountName]: 'string',
+ [keys.Username]: 'string',
+ [keys.Description]: 'string',
+ [keys.FollowersCount]: 'int',
+ [keys.FollowingCount]: 'int',
+ [keys.lastUpdateTimestamp]: 'int',
+ [keys.ProfilePicture]: 'string', //URL
+ [keys.ProfilePictureBinaryLQ]: 'data',
+ [keys.ProfilePictureBinaryHQ]: 'data',
- XpLevel: 'int',
- XpPoints: 'int',
+ [keys.XpLevel]: 'int',
+ [keys.XpPoints]: 'int',
};
const propsDefault = {
- UserId: '',
- AccountName: '',
- Username: '',
- Description: '',
- FollowersCount: 0,
- FollowingCount: 0,
- lastUpdateTimestamp: 0,
- ProfilePicture: '', //URL
- ProfilePictureBinaryLQ: new ArrayBuffer(0),
- ProfilePictureBinaryHQ: new ArrayBuffer(0),
- XpLevel: 0,
- XpPoints: 0,
+ [keys.UserId]: '',
+ [keys.AccountName]: '',
+ [keys.Username]: '',
+ [keys.Description]: '',
+ [keys.FollowersCount]: 0,
+ [keys.FollowingCount]: 0,
+ [keys.lastUpdateTimestamp]: 0,
+ [keys.ProfilePicture]: '', //URL
+ [keys.ProfilePictureBinaryLQ]: new ArrayBuffer(0),
+ [keys.ProfilePictureBinaryHQ]: new ArrayBuffer(0),
+ [keys.XpLevel]: 0,
+ [keys.XpPoints]: 0,
};
-const thisSchema: databaseConf = {
+const thisSchema: databaseConf = {
filePath: name,
version: 1,
+ keys,
migration: () => {
return DBMigration[name](thisSchema);
},
diff --git a/src/caj/helper/storage/bdm/set.ts b/src/caj/helper/storage/bdm/set.ts
index 2d7f0ec..f1ba8dd 100644
--- a/src/caj/helper/storage/bdm/set.ts
+++ b/src/caj/helper/storage/bdm/set.ts
@@ -1,7 +1,7 @@
import {getDatabase} from './getDB';
import {databaseConf} from './types';
-export const setEntry = async , T>(
+export const setEntry = async , T>(
schema: T2,
value: T,
) => {
diff --git a/src/caj/helper/storage/bdm/set.web.ts b/src/caj/helper/storage/bdm/set.web.ts
index 602e64e..b0c9373 100644
--- a/src/caj/helper/storage/bdm/set.web.ts
+++ b/src/caj/helper/storage/bdm/set.web.ts
@@ -1,7 +1,7 @@
import {getDatabase} from './getDB.web';
import {databaseConf} from './types';
-export const setEntry = async , T>(
+export const setEntry = async , T>(
schema: T2,
value: T,
) => {
diff --git a/src/caj/helper/storage/bdm/types.ts b/src/caj/helper/storage/bdm/types.ts
index 0af4655..75857f7 100644
--- a/src/caj/helper/storage/bdm/types.ts
+++ b/src/caj/helper/storage/bdm/types.ts
@@ -1,10 +1,11 @@
-export type databaseNames = 'users' | 'chat';
+export type databaseNames = 'users' | 'chat' | 'chatRoomInfos';
export type possibleDBKeys = string;
-export interface databaseConf {
+export interface databaseConf {
filePath: string;
version: number;
migration?: any;
+ keys: enums;
getEntry: (key: possibleDBKeys) => Promise;
setEntry: (val: props) => Promise;
defaultProps: props;
diff --git a/src/caj/tabs/main/AccountTab.tsx b/src/caj/tabs/main/AccountTab.tsx
index eca5629..d96405f 100644
--- a/src/caj/tabs/main/AccountTab.tsx
+++ b/src/caj/tabs/main/AccountTab.tsx
@@ -10,8 +10,11 @@ import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from '@react-navigation/native-stack';
-import {Box, Center, Container, Text} from 'native-base';
+import {Box, Button, Center, Container, Text} from 'native-base';
import {useSelector} from 'react-redux';
+import initChatDatabase from '@caj/components/chat/initChatDatabase';
+import MyUserManager from '@caj/user/MyUserManager';
+import {chatTags} from '@caj/components/chat/types';
export const AccountTabName = 'Account';
@@ -66,6 +69,35 @@ function AccountScreen() {
+
+
+
>
);
}
diff --git a/src/caj/user/UserManager.ts b/src/caj/user/UserManager.ts
index dd2dc98..6137442 100644
--- a/src/caj/user/UserManager.ts
+++ b/src/caj/user/UserManager.ts
@@ -57,37 +57,58 @@ async function getUser(
}
if (user === undefined) {
+ const usrDBKeys = BigDataManager.databases.users.keys;
const usr = await BigDataManager.databases.users.getEntry(UserId);
if (usr !== undefined && usr !== null) {
let ProfilePicture = {
lq:
- usr.ProfilePictureBinaryLQ.byteLength !== 0
+ usr[usrDBKeys.ProfilePictureBinaryLQ].byteLength !== 0
? createUserProp(
SourceProp.offline,
- new Blob([usr.ProfilePictureBinaryLQ]),
+ new Blob([usr[usrDBKeys.ProfilePictureBinaryLQ]]),
)
- : createUserProp(SourceProp.online, undefined, usr.ProfilePicture),
+ : createUserProp(
+ SourceProp.online,
+ undefined,
+ usr[usrDBKeys.ProfilePicture],
+ ),
hq:
- usr.ProfilePictureBinaryHQ.byteLength !== 0
+ usr[usrDBKeys.ProfilePictureBinaryHQ].byteLength !== 0
? createUserProp(
SourceProp.offline,
- new Blob([usr.ProfilePictureBinaryHQ]),
+ new Blob([usr[usrDBKeys.ProfilePictureBinaryHQ]]),
)
- : createUserProp(SourceProp.online, undefined, usr.ProfilePicture),
+ : createUserProp(
+ SourceProp.online,
+ undefined,
+ usr[usrDBKeys.ProfilePicture],
+ ),
};
user = {
- AccountName: createUserProp(SourceProp.offline, usr.AccountName),
- Description: createUserProp(SourceProp.offline, usr.Description),
- FollowersCount: createUserProp(SourceProp.offline, usr.FollowersCount),
- FollowingCount: createUserProp(SourceProp.offline, usr.FollowingCount),
- lastUpdateTimestamp: usr.lastUpdateTimestamp,
+ AccountName: createUserProp(
+ SourceProp.offline,
+ usr[usrDBKeys.AccountName],
+ ),
+ Description: createUserProp(
+ SourceProp.offline,
+ usr[usrDBKeys.Description],
+ ),
+ FollowersCount: createUserProp(
+ SourceProp.offline,
+ usr[usrDBKeys.FollowersCount],
+ ),
+ FollowingCount: createUserProp(
+ SourceProp.offline,
+ usr[usrDBKeys.FollowingCount],
+ ),
+ lastUpdateTimestamp: usr[usrDBKeys.lastUpdateTimestamp],
ProfilePicture,
UserId,
- Username: createUserProp(SourceProp.offline, usr.Username),
- XpLevel: createUserProp(SourceProp.offline, usr.XpLevel),
- XpPoints: createUserProp(SourceProp.offline, usr.XpPoints),
+ Username: createUserProp(SourceProp.offline, usr[usrDBKeys.Username]),
+ XpLevel: createUserProp(SourceProp.offline, usr[usrDBKeys.XpLevel]),
+ XpPoints: createUserProp(SourceProp.offline, usr[usrDBKeys.XpPoints]),
};
}
}
diff --git a/tsconfig.json b/tsconfig.json
index 7496621..d79a0c9 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,5 +1,6 @@
{
"compilerOptions": {
+ "outDir": "./dist",
"baseUrl": ".",
"paths" : {
"@caj/*": ["src/caj/*"]