/* * Copyright (c) 2022. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ import {dropContactData, getAllContactData} from "~/domains/contact-data/api"; import {getters} from "~/modules/security/store"; import { createAndSaveContactSelfKeyPair, decodeContactMessage, saveContactRelatedKey, } from "~/domains/contact/encryption"; import { createAndShareRoomKeyToContacts, saveChatRoomKey, shareChatRoomKey } from "~/domains/chat-room/encryption"; import {getRoomMembers} from "~/domains/chat-room/api"; type ShareData = { id: string, content: any, encrypted: boolean, type: string, fromUserId: number, toUserId: number, contactId: string } export enum ContactDataSecretType { CONTACT = 'secretKey', ROOM = 'roomSecretKey', ROOM_REQUEST = 'requestRoomSecretKey' } export async function loadAndApplyContactData(userId: number) { const shareData : ShareData[] = await getAllContactData({ filter: { toUserId: userId } }); if(shareData.length === 0) { return; } for(let i=0; i