mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-22 19:15:08 +03:00
Fix infinite loop
This commit is contained in:
+11
-4
@@ -12,6 +12,7 @@ import type { Message, Messages, WebSocketMessage } from "./types";
|
|||||||
import { formatTime } from "./utils/utils";
|
import { formatTime } from "./utils/utils";
|
||||||
import { show as showContextMenu } from "./message-context-menu";
|
import { show as showContextMenu } from "./message-context-menu";
|
||||||
import { show as showUserProfileDialog } from "./user-profile-dialog";
|
import { show as showUserProfileDialog } from "./user-profile-dialog";
|
||||||
|
import defaultAvatar from "./images/default-avatar.png";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new message to the chat interface
|
* 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');
|
profilePicDiv.classList.add('message-profile-pic');
|
||||||
|
|
||||||
const profileImg = document.createElement('img');
|
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.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
|
// Add click handler to profile picture
|
||||||
profileImg.style.cursor = 'pointer';
|
profileImg.style.cursor = 'pointer';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { API_BASE_URL } from "./config";
|
|||||||
import type { UserProfile } from "./types";
|
import type { UserProfile } from "./types";
|
||||||
import { showError, showSuccess } from "./utils/notification";
|
import { showError, showSuccess } from "./utils/notification";
|
||||||
import { formatTime } from "./utils/utils";
|
import { formatTime } from "./utils/utils";
|
||||||
|
import defaultAvatar from "./images/default-avatar.png";
|
||||||
|
|
||||||
|
|
||||||
let dialog = document.getElementById("user-profile-dialog")!;
|
let dialog = document.getElementById("user-profile-dialog")!;
|
||||||
@@ -80,9 +81,15 @@ function populateDialog(profile: UserProfile): void {
|
|||||||
|
|
||||||
// Profile picture
|
// Profile picture
|
||||||
const profilePic = dialog.querySelector('.profile-picture') as HTMLImageElement;
|
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.addEventListener("error", () => {
|
||||||
profilePic.src = './src/images/default-avatar.png';
|
if (!errorLock) {
|
||||||
|
profilePic.src = defaultAvatar;
|
||||||
|
errorLock = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Username
|
// Username
|
||||||
|
|||||||
Reference in New Issue
Block a user