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