mirror of
https://github.com/Discreetly/frontend.git
synced 2026-01-08 20:38:04 -05:00
testing
This commit is contained in:
@@ -92,7 +92,6 @@ export async function postJubmojis(
|
||||
}
|
||||
|
||||
export async function getMessages(serverUrl: string, roomId: string) {
|
||||
console.debug('Fetching messages for', roomId);
|
||||
return get([serverUrl, `room/${roomId}/messages`]) as Promise<MessageI[]>;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,8 @@ export async function unlockPadlock(password: string) {
|
||||
return roomKeys;
|
||||
});
|
||||
});
|
||||
}, 50);
|
||||
console.debug('Unlocked rooms');
|
||||
}, 10);
|
||||
});
|
||||
} else {
|
||||
alertQueue.enqueue('Incorrect Password', 'warning');
|
||||
|
||||
@@ -11,15 +11,13 @@
|
||||
import { getIdentity, clearMessageHistory } from '$lib/utils';
|
||||
import Send from 'svelte-material-icons/Send.svelte';
|
||||
import { encrypt } from '$lib/crypto/crypto';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
export let socket: Socket;
|
||||
export let connected: boolean;
|
||||
export let currentEpoch: number;
|
||||
export let userMessageLimit: number;
|
||||
export let roomId: string;
|
||||
export let getKey: () => Promise<CryptoKey>;
|
||||
let key: CryptoKey;
|
||||
export let key: CryptoKey;
|
||||
|
||||
let scrollChatEvent = new CustomEvent('scrollChat', {
|
||||
detail: { behavior: 'smooth', delay: 20 }
|
||||
@@ -112,8 +110,11 @@
|
||||
}
|
||||
|
||||
// Helper function to handle encrypted room messages
|
||||
async function handleEncryptedMessage(messageText: string, roomId: string): Promise<string> {
|
||||
const encryptedMessage = await encrypt(messageText, key);
|
||||
async function handleEncryptedMessage(messageText: string): Promise<string> {
|
||||
if (!key) {
|
||||
throw new Error('NO KEY FOUND');
|
||||
}
|
||||
const encryptedMessage = await encrypt(messageText, await key);
|
||||
if (encryptedMessage == null) {
|
||||
throw new Error('ENCRYPTION FAILED');
|
||||
} else {
|
||||
@@ -150,7 +151,7 @@
|
||||
let messageToSend: string = messageText;
|
||||
|
||||
if (room.encrypted === 'AES') {
|
||||
messageToSend = await handleEncryptedMessage(messageText, room.roomId!.toString());
|
||||
messageToSend = await handleEncryptedMessage(messageText);
|
||||
}
|
||||
|
||||
const msg = await genProof(
|
||||
@@ -197,12 +198,6 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
getKey().then((k) => {
|
||||
key = k;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<section class="border-t border-surface-500/30 p-2 md:p-4 !border-dashed">
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
currentRoomsStore,
|
||||
roomPasswordSet,
|
||||
identityExists,
|
||||
roomKeyStore,
|
||||
roomPassStore
|
||||
} from '$lib/stores';
|
||||
import RoomPassword from './RoomPassword.svelte';
|
||||
@@ -37,7 +36,7 @@
|
||||
let onlineMembers = '?';
|
||||
let epochUpdater: NodeJS.Timeout;
|
||||
let currentEpoch = 0;
|
||||
let key: CryptoKey | undefined = undefined;
|
||||
let key: CryptoKey;
|
||||
$: timeLeftInEpoch = '0';
|
||||
$: roomId = $currentSelectedRoom?.roomId!.toString();
|
||||
$: userMessageLimit = $currentSelectedRoom?.userMessageLimit ?? 1;
|
||||
@@ -51,9 +50,9 @@
|
||||
|
||||
let unsubscribeStore = currentSelectedRoom.subscribe((currentValue) => {
|
||||
updateMessages($selectedServer, roomId);
|
||||
getKey().then((k) => {
|
||||
key = k;
|
||||
});
|
||||
if ($currentSelectedRoom.encrypted === 'AES' && $identityExists === 'safe') {
|
||||
getKey(roomId);
|
||||
}
|
||||
});
|
||||
|
||||
$: try {
|
||||
@@ -67,18 +66,15 @@
|
||||
|
||||
$: updateRooms($selectedServer, [roomId]);
|
||||
|
||||
async function getKey(): Promise<CryptoKey> {
|
||||
let key: CryptoKey;
|
||||
if (!$roomPassStore[roomId]) {
|
||||
throw new Error('ROOM IS ENCRYPTED BUT NO PASSWORD WAS FOUND');
|
||||
}
|
||||
if (!$roomKeyStore[roomId]) {
|
||||
$: if ($currentSelectedRoom.encrypted == 'AES' && $identityExists == 'safe') {
|
||||
getKey(roomId);
|
||||
}
|
||||
|
||||
async function getKey(roomId: string) {
|
||||
console.debug('Getting key for room', roomId);
|
||||
if ($roomPassStore[roomId]) {
|
||||
key = await deriveKey($roomPassStore[roomId].password, roomId);
|
||||
$roomKeyStore[roomId] = key;
|
||||
} else {
|
||||
key = $roomKeyStore[roomId];
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
function updateEpoch() {
|
||||
@@ -164,9 +160,6 @@
|
||||
epochUpdater = setInterval(() => {
|
||||
updateEpoch();
|
||||
}, 100);
|
||||
getKey().then((k) => {
|
||||
key = k;
|
||||
});
|
||||
});
|
||||
|
||||
onDestroy(() => {
|
||||
@@ -192,7 +185,8 @@
|
||||
{#key $currentSelectedRoom.roomId}
|
||||
<Conversation
|
||||
{roomRateLimit}
|
||||
{getKey} />
|
||||
{key}
|
||||
{roomId} />
|
||||
{/key}
|
||||
<InputPrompt
|
||||
{socket}
|
||||
@@ -200,14 +194,15 @@
|
||||
{currentEpoch}
|
||||
{userMessageLimit}
|
||||
{roomId}
|
||||
{getKey} />
|
||||
{key} />
|
||||
{:else if $configStore.experience == Experiences.Draw}
|
||||
<Draw />
|
||||
{:else}
|
||||
{#key $currentSelectedRoom.roomId}
|
||||
<Conversation
|
||||
{roomRateLimit}
|
||||
{getKey} />
|
||||
{key}
|
||||
{roomId} />
|
||||
{/key}
|
||||
<InputPrompt
|
||||
{socket}
|
||||
@@ -215,7 +210,7 @@
|
||||
{currentEpoch}
|
||||
{userMessageLimit}
|
||||
{roomId}
|
||||
{getKey} />
|
||||
{key} />
|
||||
{/if}
|
||||
<!-- Conversation -->
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { currentRoomMessages } from '$lib/stores';
|
||||
import { currentRoomMessages, currentSelectedRoom, identityExists } from '$lib/stores';
|
||||
import { getEpochFromTimestamp, getTimestampFromEpoch } from '$lib/utils/rateLimit';
|
||||
import type { MessageI } from 'discreetly-interfaces';
|
||||
import { onMount } from 'svelte';
|
||||
@@ -9,8 +9,8 @@
|
||||
import { decrypt } from '$lib/crypto/crypto';
|
||||
|
||||
export let roomRateLimit: number;
|
||||
export let getKey: () => Promise<CryptoKey>;
|
||||
let key: CryptoKey;
|
||||
export let key: CryptoKey;
|
||||
export let roomId: string;
|
||||
|
||||
let elemChat: HTMLElement;
|
||||
|
||||
@@ -26,16 +26,10 @@
|
||||
|
||||
async function decryptText(text: string): Promise<string> {
|
||||
if (!key) {
|
||||
return getKey().then(async (k) => {
|
||||
key = k;
|
||||
const result = await decrypt(text, key);
|
||||
return result ? result : text;
|
||||
});
|
||||
} else if (key) {
|
||||
throw new Error('Key Doesnt Exist');
|
||||
} else {
|
||||
const result = await decrypt(text, key);
|
||||
return result ? result : text;
|
||||
} else {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,9 +68,6 @@
|
||||
const delay = customEvent.detail.delay ? customEvent.detail.delay : 20;
|
||||
scrollChatBottom(behavior, delay);
|
||||
});
|
||||
getKey().then((k) => {
|
||||
key = k;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -100,7 +91,7 @@
|
||||
{/if}
|
||||
{#key msg}
|
||||
{#await decryptText(String(msg.message))}
|
||||
<p>Decrypting...</p>
|
||||
<BubbleText bubbleText={'Decrypting...'} />
|
||||
{:then decryptedText}
|
||||
<span
|
||||
title="Encrypted Message"
|
||||
|
||||
Reference in New Issue
Block a user