This repository has been archived on 2023-12-20. You can view files and clone it, but cannot push or open issues/pull-requests.
PartyApp/src/components/chat/initChatDatabase.ts

29 lines
943 B
TypeScript

import {appNonSaveVarActions} from '@configs/appNonSaveVarReducer';
import {initDatabase} from '@helper/storage/bdm/init';
import DBSchemas from '@helper/storage/bdm/schemas';
import BigDataManager from '@helper/storage/BigDataManager';
import {store} from '@redux/store';
import {chatEntity} from '@configs/chat/types';
async function initChatDatabase(chat: chatEntity) {
const keys = BigDataManager.databases.chatRoomInfos.keys;
await initDatabase(DBSchemas.chat, chat.roomId);
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,
[keys.timestamp]: chat.timestamp,
});
addChatEntity(chat);
}
export function addChatEntity(chat: chatEntity) {
store.dispatch(appNonSaveVarActions.setChatEntity(chat));
}
export default initChatDatabase;