mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix everything
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user