Fix everything

This commit is contained in:
2025-08-18 19:44:33 +03:00
Unverified
parent 06d183d6e4
commit a5a501e364
6 changed files with 38 additions and 28 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ document.getElementById('login-form-element')!.addEventListener('submit', async
const data: LoginResponse = await response.json();
// Store the JWT token
authToken = data.token;
currentUser = { username: data.username };
currentUser = data.user;
showChat();
loadMessages(); // Start loading messages
} else {
+3 -3
View File
@@ -1,5 +1,5 @@
import './css/style.scss';
import { showLogin, getAuthHeaders, authToken } from './auth';
import { showLogin, getAuthHeaders, authToken, currentUser } from './auth';
import { API_BASE_URL, API_FULL_BASE_URL } from './config';
import type { Message, Messages, WebSocketMessage } from './types';
import "./links";
@@ -80,7 +80,7 @@ export function loadMessages() {
// Добавляем только новые сообщения
data.messages.forEach(msg => {
if (msg.id > lastMessageId) {
addMessage(msg, msg.is_author);
addMessage(msg, msg.username == currentUser!.username);
}
});
}
@@ -125,7 +125,7 @@ websocket.addEventListener("message", (e) => {
switch (message.type) {
case "newMessage": {
const newMessage: Message = message.data;
addMessage(newMessage, newMessage.is_author);
addMessage(newMessage, newMessage.username == currentUser!.username);
break;
}
}
+5 -2
View File
@@ -11,7 +11,6 @@ export interface Message {
username: string;
content: string;
is_read: boolean;
is_author: boolean;
timestamp: string;
}
@@ -20,6 +19,10 @@ export interface Messages {
}
export interface User {
id: number;
created_at: string;
last_seen: string;
online: boolean;
username: string;
}
@@ -42,7 +45,7 @@ export interface RegisterRequest {
// Responses
export interface LoginResponse {
username: string;
user: User;
token: string;
}