1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 08:38:59 +00:00

basic chat functionality

This commit is contained in:
Lynne Megido 2020-01-20 13:18:59 +10:00
parent 60728c0b35
commit 5f089f4040
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 23 additions and 2 deletions

21
app/static/script.js Normal file
View file

@ -0,0 +1,21 @@
function sendMessage() {
let id = window.location.href.split("/").slice(-1)[0]
message = document.getElementById("chatbox-input-box").value
document.getElementById("chatbox-input-box").value = ''
document.getElementById("chatbox").innerHTML += `<div class="message-container user"><div class="message user">${message}</div></div>`;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
message = this.responseText.replace("\n", "<br>");
} else {
message = "Encountered an error while trying to get a response.";
}
document.getElementById("chatbox").innerHTML += `<div class="message-container bot"><div class="bot-icon"></div><div class="message bot">${this.responseText}</div></div>`;
}
};
xhttp.open("GET", `/bot/chat/${id}/message`, true);
xhttp.send();
return false;
}

View file

@ -29,13 +29,13 @@
<div class="container"> <div class="container">
<div id="chatbox"> <div id="chatbox">
<div class="message-container user"> <!-- <div class="message-container user">
<div class="message user">Henlo</div> <div class="message user">Henlo</div>
</div> </div>
<div class="message-container bot"> <div class="message-container bot">
<div class="bot-icon"></div> <div class="bot-icon"></div>
<div class="message bot">Henlo human uwu<br>How are you</div> <div class="message bot">Henlo human uwu<br>How are you</div>
</div> </div> -->
</div> </div>
<form id="chatbox-input"> <form id="chatbox-input">