mirror of
https://github.com/Discreetly/frontend.git
synced 2026-01-09 12:58:03 -05:00
minor fixes
This commit is contained in:
@@ -41,9 +41,9 @@ function updateRoomStore(rooms: RoomI[], serverURL: string = get(selectedServer)
|
||||
});
|
||||
}
|
||||
|
||||
async function getRoomIdsIfEmpty(server: string, roomIds: string[]): Promise<string[]> {
|
||||
async function getRoomIdsByIdentity(server: string, roomIds: string[]): Promise<string[]> {
|
||||
const idc = getCommitment();
|
||||
if (roomIds.length < 1 && idc) {
|
||||
if (idc) {
|
||||
return await getRoomIdsByIdentityCommitment(server);
|
||||
}
|
||||
return roomIds;
|
||||
@@ -66,7 +66,7 @@ export async function updateRooms(
|
||||
server: string = get(selectedServer),
|
||||
roomIds: string[] = []
|
||||
): Promise<string[]> {
|
||||
roomIds = await getRoomIdsIfEmpty(server, roomIds);
|
||||
roomIds = await getRoomIdsByIdentity(server, roomIds);
|
||||
if (roomIds.length > 0) {
|
||||
const rooms = await fetchRoomsByIds(server, roomIds);
|
||||
const acceptedRoomNames = extractRoomNames(rooms);
|
||||
@@ -85,6 +85,7 @@ export async function updateRooms(
|
||||
}
|
||||
|
||||
export function updateMessages(server: string, roomId: string) {
|
||||
console.debug('updating messages');
|
||||
getMessages(server, roomId).then((messages) => {
|
||||
messageStore.update((store) => {
|
||||
store[roomId] = messages;
|
||||
@@ -112,14 +113,20 @@ export function addMessageToRoom(roomId: string, data: MessageI) {
|
||||
}
|
||||
|
||||
// Add the new message
|
||||
const test = [...currentStore[roomId]];
|
||||
console.log('oldmsgs', test);
|
||||
console.log('newmsg', data);
|
||||
|
||||
currentStore[roomId] = [...currentStore[roomId], data];
|
||||
console.log('allmsgs', currentStore[roomId]);
|
||||
|
||||
// Trim messages to the last 500
|
||||
if (currentStore[roomId].length > 500) {
|
||||
currentStore[roomId] = currentStore[roomId].slice(-500);
|
||||
}
|
||||
|
||||
return { ...currentStore };
|
||||
const result = { ...currentStore };
|
||||
console.log(result);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
import { getIdentity, clearMessageHistory } from '$lib/utils';
|
||||
import Send from 'svelte-material-icons/Send.svelte';
|
||||
import { decrypt, encrypt } from '$lib/crypto/crypto';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
export let socket: Socket;
|
||||
export let connected: boolean;
|
||||
@@ -198,7 +197,7 @@
|
||||
}
|
||||
|
||||
function onPromptKeydown(event: KeyboardEvent): void {
|
||||
if (['Enter'].includes(event.key)) {
|
||||
if (['Enter'].includes(event.key) && !event.shiftKey) {
|
||||
const value = (event.currentTarget as HTMLInputElement).value;
|
||||
event.preventDefault();
|
||||
if (value.startsWith('/')) {
|
||||
@@ -223,16 +222,14 @@
|
||||
placeholder={placeholderText()}
|
||||
rows="1"
|
||||
on:keydown={onPromptKeydown}
|
||||
disabled={!canSendMessage}
|
||||
/>
|
||||
disabled={!canSendMessage} />
|
||||
<button
|
||||
class:hidden={!canSendMessage}
|
||||
class={canSendMessage && messageText
|
||||
? 'border-none text-xs md:text-base variant-soft-success'
|
||||
: 'border-none text-xs md:text-base variant-soft-secondary'}
|
||||
disabled={!canSendMessage}
|
||||
on:click={sendMessage}
|
||||
>
|
||||
on:click={sendMessage}>
|
||||
<Send />
|
||||
{#if $configStore.beta}
|
||||
<span class="ps-1">{messagesLeft()}</span>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
import Conversation from './Conversation.svelte';
|
||||
import Draw from './Draw.svelte';
|
||||
import InputPrompt from './ChatInputPrompt.svelte';
|
||||
import { randomInt } from 'crypto';
|
||||
|
||||
const toastStore = getToastStore();
|
||||
|
||||
@@ -78,8 +77,9 @@
|
||||
socket.on('connect', () => {
|
||||
connected = true;
|
||||
const engine = socket.io.engine;
|
||||
|
||||
updateMessages($selectedServer, $currentSelectedRoom?.roomId.toString());
|
||||
if ($currentSelectedRoom?.ephemeral == 'PERSISTENT') {
|
||||
updateMessages($selectedServer, $currentSelectedRoom?.roomId.toString());
|
||||
}
|
||||
if ($configStore.experience == Experiences.Chat) {
|
||||
scrollChatToBottom();
|
||||
}
|
||||
@@ -112,6 +112,19 @@
|
||||
console.debug('chat websocket error', err.message);
|
||||
});
|
||||
|
||||
socket.on('Members', (data: string) => {
|
||||
const numVal = Number(data);
|
||||
// rand is for you + noise to stop people from knowing exactly how many people are online, in case someone wants to refresh their session and get a new Session ID
|
||||
const rand = Math.floor(Math.random() * 2);
|
||||
const val = numVal + rand;
|
||||
onlineMembers = String('~' + val);
|
||||
});
|
||||
|
||||
socket.on('systemBroadcast', (data: string) => {
|
||||
toastStore.trigger({ message: data, timeout: 3000 });
|
||||
console.debug('Received System Message: ', data);
|
||||
});
|
||||
|
||||
socket.on('messageBroadcast', (data: MessageI) => {
|
||||
console.debug('Received Message: ', data);
|
||||
const roomId = data.roomId?.toString();
|
||||
@@ -119,19 +132,6 @@
|
||||
addMessageToRoom(roomId, data);
|
||||
scrollChatToBottom();
|
||||
}
|
||||
socket.on('Members', (data: string) => {
|
||||
console.debug(`Members Online: ${data}`);
|
||||
const numVal = Number(data);
|
||||
// rand is for you + noise to stop people from knowing exactly how many people are online, in case someone wants to refresh their session and get a new Session ID
|
||||
onlineMembers = String('~' + numVal + randomInt(1, 3));
|
||||
});
|
||||
|
||||
socket.on('systemBroadcast', (data: string) => {
|
||||
toastStore.trigger({ message: data, timeout: 3000 });
|
||||
console.debug('Received System Message: ', data);
|
||||
});
|
||||
|
||||
scrollChatToBottom();
|
||||
});
|
||||
|
||||
epochUpdater = setInterval(() => {
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
class="flex flex-row align-middle text-sm font-mono text-secondary-300-600-token"
|
||||
title="Online Users">
|
||||
<Person />
|
||||
~{onlineMembers}
|
||||
{onlineMembers}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user