iu9-ca-web-chat/assets/js/all_apis.js

171 lines
4.4 KiB
JavaScript
Raw Normal View History

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;
}