|
@@ -61,23 +61,25 @@
|
|
|
|
|
|
async function jsonPost(url, data)
|
|
|
{
|
|
|
- const x = fetch(url, {
|
|
|
+ const x = await fetch(url, {
|
|
|
method: "POST",
|
|
|
body: JSON.stringify(data),
|
|
|
|
|
|
- }).then(c => c.json())
|
|
|
- return x;
|
|
|
+ })
|
|
|
+
|
|
|
+ return x.json();
|
|
|
+
|
|
|
|
|
|
}
|
|
|
let messagees = 0;
|
|
|
async function getMessage() {
|
|
|
|
|
|
- const getMess = jsonPost("http://students.a-level.com.ua:10012", {func: "getMessages", messageId: 0}).then(r => {
|
|
|
+ const r = await jsonPost("http://students.a-level.com.ua:10012", {func: "getMessages", messageId: 0})
|
|
|
|
|
|
for (let i = messagees; i < r.nextMessageId; i++) {
|
|
|
let message = document.createElement("p");
|
|
|
let time = r.data[i].timestamp;
|
|
|
- let data = new Date();
|
|
|
+ let data = new Date(time);
|
|
|
|
|
|
let dataString = `${data.getDate()}/ ${data.getMonth()}/ ${data.getFullYear()} ${data.getHours()}.${data.getMinutes()}.${data.getSeconds()}`
|
|
|
message.innerHTML = `${dataString} ${r.data[i].nick}: ${r.data[i].message}`
|
|
@@ -86,7 +88,7 @@ async function getMessage() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- });
|
|
|
+
|
|
|
};
|
|
|
|
|
|
getMessage();
|
|
@@ -133,6 +135,7 @@ async function sendMessage(nick, message) {
|
|
|
const msg = message.value;
|
|
|
|
|
|
message.value = "";
|
|
|
+ console.log("post new message");
|
|
|
|
|
|
return jsonPost("http://students.a-level.com.ua:10012", {func: 'addMessage', nick: `${nick.value}`, message: `${msg}`});
|
|
|
}
|