Skip to content

Instantly share code, notes, and snippets.

@emrekizildas
Last active February 17, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrekizildas/f56ce703436b1f6d637f5923078eaf9c to your computer and use it in GitHub Desktop.
Save emrekizildas/f56ce703436b1f6d637f5923078eaf9c to your computer and use it in GitHub Desktop.
Chat yükleme fonksiyonu
function chatYukle() {
var query = firebase.database().ref("chats");
var kadi = $("#kadi").val();
query.on('value', function (snapshot) {
$("#mesajAlani").html("");
snapshot.forEach(function (childSnapshot) {
var data = childSnapshot.val();
if (data.from == kadi) {
//Mesaj bizim tarafımızdan gönderilmişse bu alan çalışacak
var mesaj = `<div class="d-flex justify-content-end">
<div class="alert alert-info" role="alert">
`+ data.message + ` <b>@` + data.from + `</b>
</div>
</div>`;
$("#mesajAlani").append(mesaj);
} else {
//Mesaj başkası tarafından gönderilmişse bu alan çalışacak
var mesaj = `<div class="d-flex">
<div class="alert alert-dark" role="alert">
<b>@`+ data.from + `</b> ` + data.message + `
</div>
</div>`;
$("#mesajAlani").append(mesaj);
}
$(".card-body").scrollTop($('.card-body')[0].scrollHeight - $('.card-body')[0].clientHeight);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment