mirror of
https://github.com/Discreetly/frontend.git
synced 2026-01-08 20:38:04 -05:00
Fixed ephemeral room wiping messages
This commit is contained in:
@@ -86,7 +86,7 @@ async function genProof(
|
||||
admin = false
|
||||
): Promise<MessageI> {
|
||||
const roomId = typeof room.roomId === 'bigint' ? room.roomId.toString() : String(room.roomId);
|
||||
await updateRooms(get(selectedServer), [roomId]);
|
||||
const updated = await updateRooms(get(selectedServer), [roomId]);
|
||||
room = get(roomsStore)[roomId];
|
||||
const RLN_IDENTIFIER = BigInt(roomId);
|
||||
const userMessageLimit = BigInt(messageLimit);
|
||||
@@ -97,6 +97,7 @@ async function genProof(
|
||||
const commitment = admin ? identityCommitment : rateCommitment;
|
||||
|
||||
let merkleProof: MerkleProof;
|
||||
|
||||
switch (room.membershipType) {
|
||||
case 'IDENTITY_LIST':
|
||||
merkleProof = await merkleProofFromRoom(roomId, RLN_IDENTIFIER, commitment);
|
||||
@@ -129,7 +130,8 @@ async function genProof(
|
||||
console.info(
|
||||
`Generating proof: epoch ${epoch}, message ID ${messageId}, message hash ${messageHash}`
|
||||
);
|
||||
return prover.generateProof(proofInputs).then((proof: RLNFullProof) => {
|
||||
|
||||
const proof = prover.generateProof(proofInputs).then((proof: RLNFullProof) => {
|
||||
console.log('Proof generated!');
|
||||
const msg: MessageI = {
|
||||
messageId: proof.snarkProof.publicSignals.nullifier.toString(),
|
||||
@@ -140,6 +142,7 @@ async function genProof(
|
||||
};
|
||||
return msg;
|
||||
});
|
||||
return proof;
|
||||
}
|
||||
|
||||
export { genProof };
|
||||
|
||||
@@ -92,6 +92,7 @@ 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[]>;
|
||||
}
|
||||
|
||||
@@ -155,6 +156,22 @@ export async function createInvite(
|
||||
return postAuth([serverUrl, `admin/addcode`], data, username, password) as Promise<Invites>;
|
||||
}
|
||||
|
||||
interface AddAdminData {
|
||||
idc: string;
|
||||
}
|
||||
|
||||
export async function addAdmin(
|
||||
serverUrl: string,
|
||||
username: string,
|
||||
password: string,
|
||||
roomId: string,
|
||||
adminIdc: string
|
||||
) {
|
||||
const data: AddAdminData = { idc: adminIdc };
|
||||
|
||||
return postAuth([serverUrl, `admin/${roomId}/addAdmin`], data, username, password);
|
||||
}
|
||||
|
||||
export async function getAllRooms(serverUrl: string, username: string, password: string) {
|
||||
return getAuth([serverUrl, `admin/rooms`], username, password) as Promise<RoomI[]>;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ export const roomPasswordSet = derived(
|
||||
([$currentSelectedRoom, $roomPassStore]) => {
|
||||
if ($currentSelectedRoom.encrypted == 'AES') {
|
||||
if ($roomPassStore[$currentSelectedRoom.roomId.toString()]) {
|
||||
if ($roomPassStore[$currentSelectedRoom.roomId.toString()].length > 0) {
|
||||
if ($roomPassStore[$currentSelectedRoom.roomId.toString()].password.length > 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -108,19 +108,23 @@ export async function updateRooms(
|
||||
}
|
||||
|
||||
export function updateMessages(server: string, roomId: string) {
|
||||
let ephemeral: 'PERSISTENT' | 'EPHEMERAL' | undefined;
|
||||
try {
|
||||
const rooms = get(roomsStore);
|
||||
const name = rooms[roomId].name;
|
||||
ephemeral = rooms[roomId].ephemeral;
|
||||
console.debug('Updating messages for', name);
|
||||
} catch (e) {
|
||||
console.debug('RoomsStore not ready yet');
|
||||
}
|
||||
getMessages(server, roomId).then((messages) => {
|
||||
messageStore.update((store) => {
|
||||
store[roomId] = messages;
|
||||
return store;
|
||||
if (ephemeral == 'PERSISTENT') {
|
||||
getMessages(server, roomId).then((messages) => {
|
||||
messageStore.update((store) => {
|
||||
store[roomId] = messages;
|
||||
return store;
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function addMessageToRoom(roomId: string, data: MessageI) {
|
||||
|
||||
@@ -9,29 +9,35 @@
|
||||
<input
|
||||
type="text"
|
||||
class="input"
|
||||
bind:value={$configStore.apiUsername}
|
||||
/>
|
||||
bind:value={$configStore.apiUsername} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Password</span>
|
||||
<input
|
||||
type="password"
|
||||
class="input"
|
||||
bind:value={$configStore.apiPassword}
|
||||
/>
|
||||
bind:value={$configStore.apiPassword} />
|
||||
</label>
|
||||
</Card>
|
||||
<div class="flex gap-1 justify-around">
|
||||
<div
|
||||
class="flex flex-col gap-3 justify-around"
|
||||
id="buttons">
|
||||
<a
|
||||
class="btn variant-filled-primary"
|
||||
href="/admin/newroom">Create Room</a
|
||||
>
|
||||
href="/admin/newroom">Create Room</a>
|
||||
<a
|
||||
class="btn variant-filled-primary"
|
||||
href="/admin/join">Join Room</a
|
||||
>
|
||||
href="/admin/join">Join Room</a>
|
||||
<a
|
||||
class="btn variant-filled-primary"
|
||||
href="/admin/invite">Create Invites</a
|
||||
>
|
||||
href="/admin/invite">Create Invites</a>
|
||||
<a
|
||||
class="btn variant-filled-primary"
|
||||
href="/admin/addAdmin">Add Room Admin</a>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#buttons a {
|
||||
max-width: 300px;
|
||||
}
|
||||
</style>
|
||||
|
||||
95
src/routes/admin/addAdmin/+page.svelte
Normal file
95
src/routes/admin/addAdmin/+page.svelte
Normal file
@@ -0,0 +1,95 @@
|
||||
<script lang="ts">
|
||||
import { addAdmin } from '$lib/services/server';
|
||||
import { selectedServer, configStore, currentRoomsStore } from '$lib/stores';
|
||||
import { getCommitment } from '$lib/utils';
|
||||
import { Accordion, AccordionItem } from '@skeletonlabs/skeleton';
|
||||
|
||||
let selectedRoomId: string;
|
||||
let idc: string;
|
||||
let ownIdc: boolean = true;
|
||||
let result: object;
|
||||
|
||||
function updateRoom(e: Event) {
|
||||
const target = e.target as HTMLInputElement;
|
||||
selectedRoomId = target.value;
|
||||
}
|
||||
|
||||
async function addAdminToRoom() {
|
||||
const _idc = ownIdc ? getCommitment() : idc;
|
||||
if (_idc == null) {
|
||||
return;
|
||||
}
|
||||
const resp = await addAdmin(
|
||||
$selectedServer,
|
||||
$configStore.apiUsername as string,
|
||||
$configStore.apiPassword as string,
|
||||
selectedRoomId,
|
||||
_idc
|
||||
);
|
||||
result = resp;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="flex flex-col place-content-center max-w-sm m-auto pt-5">
|
||||
<div class="border-b border-spacing-3 pb-5 mb-5">
|
||||
<h4 class="h4 my-5">Select Room</h4>
|
||||
<select
|
||||
class="select"
|
||||
on:change={updateRoom}>
|
||||
{#each $currentRoomsStore as room}
|
||||
<option value={room.roomId}>{room.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<div class="border-b border-spacing-3 pb-5 mb-5">
|
||||
<h4 class="h4 my-5">Enter someone elses IDC or use your own</h4>
|
||||
<input
|
||||
type="text"
|
||||
class="input"
|
||||
bind:value={idc}
|
||||
disabled={ownIdc} />
|
||||
<label class="my-2 flex flex-row items-center space-x-2"
|
||||
><span>Use your own Identity:</span><input
|
||||
class="checkbox"
|
||||
type="checkbox"
|
||||
title="Use Your Identity"
|
||||
bind:value={ownIdc} /></label>
|
||||
</div>
|
||||
<div
|
||||
class="btn variant-ghost-primary"
|
||||
on:click={addAdminToRoom}>
|
||||
Add Admin to Room
|
||||
</div>
|
||||
<div>{JSON.stringify(result)}</div>
|
||||
<Accordion>
|
||||
<AccordionItem>
|
||||
<svelte:fragment slot="summary">API</svelte:fragment>
|
||||
<svelte:fragment slot="content">
|
||||
<label class="label">
|
||||
<span>Api Username</span>
|
||||
<input
|
||||
type="text"
|
||||
class="input"
|
||||
bind:value={$configStore.apiUsername} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Api Password</span>
|
||||
<input
|
||||
type="password"
|
||||
class="input"
|
||||
bind:value={$configStore.apiPassword} />
|
||||
</label></svelte:fragment>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#qr > div > canvas {
|
||||
margin: 0 auto;
|
||||
height: 250px;
|
||||
width: 250px;
|
||||
}
|
||||
#qr > div > p {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -1,9 +1,8 @@
|
||||
<script lang="ts">
|
||||
import { getAllRooms, createInvite } from '$lib/services/server';
|
||||
import { inviteCode } from '$lib/gateways/inviteCode';
|
||||
import { selectedServer, configStore, currentRoomsStore } from '$lib/stores';
|
||||
import { selectedServer, configStore } from '$lib/stores';
|
||||
import { Accordion, AccordionItem } from '@skeletonlabs/skeleton';
|
||||
import { formatRelative } from 'date-fns';
|
||||
import type { RoomI } from '$lib/types';
|
||||
|
||||
let rooms: RoomI[] = [];
|
||||
@@ -48,13 +47,11 @@
|
||||
<div class="border-b border-spacing-3 pb-5 mb-5">
|
||||
<button
|
||||
on:click={getRooms}
|
||||
class="btn variant-outline-primary">Get Rooms</button
|
||||
>
|
||||
class="btn variant-outline-primary">Get Rooms</button>
|
||||
<button
|
||||
on:click={joinRooms}
|
||||
class="btn variant-outline-primary"
|
||||
disabled={selectedRoomIds.length == 1}>Join Rooms</button
|
||||
>
|
||||
disabled={selectedRoomIds.length == 1}>Join Rooms</button>
|
||||
|
||||
<h4 class="h4 my-5">Rooms:</h4>
|
||||
{#each rooms as room}
|
||||
@@ -63,8 +60,7 @@
|
||||
type="checkbox"
|
||||
value={room.roomId}
|
||||
on:change={updateRoomList}
|
||||
checked={selectedRoomIds.includes(String(room.roomId))}
|
||||
/>
|
||||
checked={selectedRoomIds.includes(String(room.roomId))} />
|
||||
<span title={String(room.roomId)}>{room.name}</span>
|
||||
</label>
|
||||
{/each}
|
||||
@@ -78,18 +74,15 @@
|
||||
<input
|
||||
type="text"
|
||||
class="input"
|
||||
bind:value={$configStore.apiUsername}
|
||||
/>
|
||||
bind:value={$configStore.apiUsername} />
|
||||
</label>
|
||||
<label class="label">
|
||||
<span>Api Password</span>
|
||||
<input
|
||||
type="password"
|
||||
class="input"
|
||||
bind:value={$configStore.apiPassword}
|
||||
/>
|
||||
</label></svelte:fragment
|
||||
>
|
||||
bind:value={$configStore.apiPassword} />
|
||||
</label></svelte:fragment>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
}
|
||||
return 'Write a message...';
|
||||
};
|
||||
|
||||
$: canSendMessage =
|
||||
connected && !sendingMessage && ($identityExists == 'safe' || $identityExists == 'unsafe');
|
||||
|
||||
@@ -182,6 +183,7 @@
|
||||
|
||||
handleRateLimiting(currentEpoch, room.roomId!.toString());
|
||||
msg.messageType = 'TEXT';
|
||||
|
||||
socket.emit('validateMessage', msg);
|
||||
console.debug('Sending message: ', msg);
|
||||
messageText = '';
|
||||
|
||||
Reference in New Issue
Block a user