From 29e06059d5c8f7136f96b8226af83571d2787210 Mon Sep 17 00:00:00 2001 From: yakovlevanton Date: Sat, 31 Aug 2024 17:53:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20http-=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20chatSettings.nytl.html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/HypertextPages/chatSettings.nytl.html | 17 ++- assets/css/chatSettings.css | 17 ++- assets/js/chatSettings.js | 144 +++++++++++++++++-- 3 files changed, 160 insertions(+), 18 deletions(-) diff --git a/assets/HypertextPages/chatSettings.nytl.html b/assets/HypertextPages/chatSettings.nytl.html index 6f05544..71269c7 100644 --- a/assets/HypertextPages/chatSettings.nytl.html +++ b/assets/HypertextPages/chatSettings.nytl.html @@ -10,20 +10,19 @@
- - + +
    -
  • Участник 1
  • -
  • Участник 2
  • -
  • Участник 3
  • + +
  • Участник 1
  • +
  • Участник 2
  • +
  • Участник 3
- +
@@ -37,7 +36,7 @@ diff --git a/assets/css/chatSettings.css b/assets/css/chatSettings.css index 31c56ba..ab8da39 100644 --- a/assets/css/chatSettings.css +++ b/assets/css/chatSettings.css @@ -41,6 +41,10 @@ body { color: white; border-radius: 20px; border: none; + cursor: pointer; +} +.changeName:hover { + background-color: #005f8c; } .chat-settings-container-body { padding: 15px; @@ -60,7 +64,18 @@ body { border-radius: 8px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); } - +.remove-member-button { + background-color: red; + color: white; + border: none; + padding: 5px 10px; + cursor: pointer; + margin-left: 10px; + border-radius: 4px; +} +.remove-member-button:hover { + background-color: darkred; +} .chat-settings-container-invite { padding: 15px; background-color: white; diff --git a/assets/js/chatSettings.js b/assets/js/chatSettings.js index aa174d5..337bc00 100644 --- a/assets/js/chatSettings.js +++ b/assets/js/chatSettings.js @@ -1,3 +1,31 @@ +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"; } @@ -6,13 +34,113 @@ function closeAdd() { document.getElementById("add_members").style.display = "none"; } -function addMember() { - const login = document.getElementById("newMemberLogin").value; - if (login) { - const list = document.getElementById("chat-settings-container-body"); - const listItem = document.createElement("li"); - listItem.textContent = login; - list.appendChild(listItem); - closeAdd(); +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); } } \ No newline at end of file