Fix infinite loop

This commit is contained in:
2025-08-23 17:16:44 +03:00
Unverified
parent 3d7a48014b
commit 5b7ba90628
2 changed files with 20 additions and 6 deletions
+11 -4
View File
@@ -12,6 +12,7 @@ import type { Message, Messages, WebSocketMessage } from "./types";
import { formatTime } from "./utils/utils";
import { show as showContextMenu } from "./message-context-menu";
import { show as showUserProfileDialog } from "./user-profile-dialog";
import defaultAvatar from "./images/default-avatar.png";
/**
* Adds a new message to the chat interface
@@ -41,11 +42,17 @@ export function addMessage(message: Message, isAuthor: boolean): void {
profilePicDiv.classList.add('message-profile-pic');
const profileImg = document.createElement('img');
profileImg.src = message.profile_picture || './src/images/default-avatar.png';
profileImg.src = message.profile_picture || defaultAvatar;
profileImg.alt = message.username;
profileImg.onerror = () => {
profileImg.src = './src/images/default-avatar.png';
};
let errorLock = false
profileImg.addEventListener("error", () => {
if (!errorLock) {
profileImg.src = defaultAvatar;
errorLock = true
}
});
// Add click handler to profile picture
profileImg.style.cursor = 'pointer';
+9 -2
View File
@@ -10,6 +10,7 @@ import { API_BASE_URL } from "./config";
import type { UserProfile } from "./types";
import { showError, showSuccess } from "./utils/notification";
import { formatTime } from "./utils/utils";
import defaultAvatar from "./images/default-avatar.png";
let dialog = document.getElementById("user-profile-dialog")!;
@@ -80,9 +81,15 @@ function populateDialog(profile: UserProfile): void {
// Profile picture
const profilePic = dialog.querySelector('.profile-picture') as HTMLImageElement;
profilePic.src = profile.profile_picture || './src/images/default-avatar.png';
profilePic.src = profile.profile_picture || defaultAvatar;
let errorLock = false
profilePic.addEventListener("error", () => {
profilePic.src = './src/images/default-avatar.png';
if (!errorLock) {
profilePic.src = defaultAvatar;
errorLock = true;
}
});
// Username