From ea92027a3cbb408aa404b14f76eeec1ad36747c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=BE=D1=82=D0=BA=D0=B8=D0=BD=20=D0=92=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=B8=D0=BC=D0=B8=D1=80?= Date: Thu, 29 Aug 2024 13:34:42 +0000 Subject: [PATCH] Add assets/js/all_apis.js add apis from manual --- assets/js/all_apis.js | 171 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 assets/js/all_apis.js diff --git a/assets/js/all_apis.js b/assets/js/all_apis.js new file mode 100644 index 0000000..95dbefd --- /dev/null +++ b/assets/js/all_apis.js @@ -0,0 +1,171 @@ +async function getChatEvents(chatId, localHistoryId) { + 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(); + return data.chatUpdResp; +} + + +async function getChatListEvents(localHistoryId) { + const response = await fetch('/api/chatListPollEvents', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + chatListUpdReq: { + LocalHistoryId: localHistoryId + } + }) + }); + const data = await response.json(); + return data.chatListUpdResp; +} + + +async function getMessageNeighbours(chatId, msgId, direction, amount, localHistoryId) { + const response = await fetch('/api/getMessageNeighbours', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + chatUpdReq: { + chatId: chatId, + LocalHistoryId: localHistoryId + }, + msgId: msgId, + direction: direction, + amount: amount + }) + }); + const data = await response.json(); + return data.chatUpdResp; +} + + +async function sendMessage(chatId, localHistoryId, text) { + const response = await fetch('/api/sendMessage', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + chatUpdReq: { + chatId: chatId, + LocalHistoryId: localHistoryId + }, + content: { + text: text + } + }) + }); + const data = await response.json(); + return data.chatUpdResp; +} + + +async function deleteMessage(chatId, localHistoryId, messageId) { + const response = await fetch('/api/deleteMessage', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + chatUpdReq: { + chatId: chatId, + LocalHistoryId: localHistoryId + }, + id: messageId + }) + }); + const data = await response.json(); + return data.chatUpdResp; +} + + +async function addMemberToChat(chatId, localHistoryId, nickname) { + 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(); + return data.chatUpdResp; +} + + +async function removeMemberFromChat(chatId, localHistoryId, userId) { + 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(); + return data.chatUpdResp; +} + + +async function createChat(localHistoryId, name, nickname) { + const response = await fetch('/api/createChat', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + chatListUpdReq: { + LocalHistoryId: localHistoryId + }, + content: { + name: name, + nickname: nickname + } + }) + }); + const data = await response.json(); + return data.chatListUpdResp; +} + + +async function leaveChat(localHistoryId, chatId) { + const response = await fetch('/api/leaveChat', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + chatListUpdReq: { + LocalHistoryId: localHistoryId + }, + chatId: chatId + }) + }); + const data = await response.json(); + return data.chatListUpdResp; +} \ No newline at end of file