Skip to content
Snippets Groups Projects
Commit 151122f5 authored by Albertus Djauhari Djohan's avatar Albertus Djauhari Djohan
Browse files

fix chat bug

parent f36019ec
Branches
1 merge request!2Message System
......@@ -21,7 +21,7 @@
<div>
<input id="sender" type="hidden" value="<?= $email ?>">
<input id="receiver" type="hidden" value="<?= $_GET['email'] ?>">
<input id="message" type="text" name="chattext" class="message-content">
<input id="message" type="text" name="chattext" class="message-content" onkeypress="send2(event)">
<input id="send" type="submit" class="send-button" onclick="send()">
</div>
</div>
......@@ -33,13 +33,15 @@
$(document).ready(function() {
myFirebase.on('child_added', function(snapshot) {
var msg = snapshot.val();
if (((msg.sender=="person1")&&(msg.receiver=="person2"))||((msg.sender=="person2")&&(msg.receiver=="person1"))) {
var sender = document.getElementById("sender").value;
var receiver = document.getElementById("receiver").value;
if (((msg.sender==sender)&&(msg.receiver==receiver))||((msg.sender==receiver)&&(msg.receiver==sender))) {
var msgTextElement = document.createElement("p");
msgTextElement.textContent = msg.message;
if (msg.sender=="person1"){
if (msg.sender==sender){
msgTextElement.classList.add('sendermessage');
} else if (msg.sender=="person2") {
} else if (msg.sender==receiver) {
msgTextElement.classList.add('receivemessage');
} else {
......@@ -53,15 +55,29 @@
});
});
function send() {
console.log("masuk");
var sender = document.getElementById("sender").value;
var receiver = document.getElementById("receiver").value;
var message = document.getElementById("message").value;
myFirebase.push({
sender: sender,
receiver: receiver,
message: message
});
if (message != "") {
myFirebase.push({
sender: sender,
receiver: receiver,
message: message
});
}
document.getElementById("message").value = "";
}
}
function send2(e) {
if (e.keyCode == 13) {
var message = document.getElementById("message").value;
if (message != "") {
myFirebase.push({
sender: sender,
receiver: receiver,
message: message
});
}
document.getElementById("message").value = "";
}
}
</script>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment