const chatId = 123; let localHistoryId = 0; function handleChangeName() { const newName = document.getElementById('room-name').value; changeChatName(chatId, localHistoryId, newName).then(() => { }); } function handleAddMember() { const login = document.getElementById('newMemberLogin').value; if (login) { addMemberToChat(chatId, localHistoryId, login).then(() => { const list = document.getElementById("chat-settings-container-body"); const listItem = document.createElement("li"); listItem.textContent = login; list.appendChild(listItem); closeAdd(); }); } } function handleRemoveMember(userId) { removeMemberFromChat(chatId, localHistoryId, userId).then(() => { const listItem = document.getElementById(`member-${userId}`); if (listItem) { listItem.remove(); } }); } function openInvite() { document.getElementById("add_members").style.display = "flex"; } function closeAdd() { document.getElementById("add_members").style.display = "none"; } function updateChat() { pollChatEvents(chatId, localHistoryId).then(() => { }); } document.addEventListener('DOMContentLoaded', () => { updateChat(); }); async function changeChatName(chatId, localHistoryId, newName) { try { const response = await fetch('/api/changeChatName', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ chatUpdReq: { chatId: chatId, LocalHistoryId: localHistoryId }, content: { name: newName } }) }); const data = await response.json(); if (data.status === 0) { console.log('Название комнаты успешно изменено'); } else { console.error('Ошибка при изменении названия комнаты:', data.error); } } catch (error) { console.error('Ошибка сети при изменении названия комнаты:', error); } } async function addMemberToChat(chatId, localHistoryId, nickname) { try { const response = await fetch('/api/addMemberToChat', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ chatUpdReq: { chatId: chatId, LocalHistoryId: localHistoryId }, nickname: nickname }) }); const data = await response.json(); if (data.status === 0) { console.log('Участник успешно добавлен'); } else { console.error('Ошибка при добавлении участника:', data.error); } } catch (error) { console.error('Ошибка сети при добавлении участника:', error); } } async function removeMemberFromChat(chatId, localHistoryId, userId) { try { const response = await fetch('/api/removeMemberFromChat', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ chatUpdReq: { chatId: chatId, LocalHistoryId: localHistoryId }, userId: userId }) }); const data = await response.json(); if (data.status === 0) { console.log('Участник успешно удален'); } else { console.error('Ошибка при удалении участника:', data.error); } } catch (error) { console.error('Ошибка сети при удалении участника:', error); } } async function pollChatEvents(chatId, localHistoryId) { try { const response = await fetch('/api/chatPollEvents', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ chatUpdReq: { chatId: chatId, LocalHistoryId: localHistoryId } }) }); const data = await response.json(); if (data.status === 0) { console.log('События чата успешно обновлены'); } else { console.error('Ошибка при обновлении событий чата:', data.error); } } catch (error) { console.error('Ошибка сети при обновлении событий чата:', error); } }