ChatServer/pages/js/sendmessage.js
NorbiPeti 1938a9f1db Added a lot of things
- Added "Add user to conversation"
-- Added a window to search for users to add
-- And made it all working
- Fixed the unread indicator
- Removed older TODOs
2016-08-18 22:35:23 +02:00

50 lines
1.6 KiB
JavaScript

var sendmsg = function sendmsg(msginputta) {
window.convid = document.getElementById("convidp").innerText * 1;
window.jsonobj = JSON.stringify({ "message": msginputta.value, "conversation": window.convid });
$.ajax({
url: "/sendmessage", data: window.jsonobj, method: "POST", success: respfunc, error: respfunc
});
};
var respfunc = function respfunc(result) {
var msginput = document.getElementById("msginput");
if (result != "Success") { //on success result is string
if (result.responseText.indexOf("JSONERROR") != -1) {
console.log("Got JSON error. Retrying...");
console.log(result.responseText);
sendmsg(msginput);
}
else {
showError(result.responseText);
msginput.disabled = false;
msginput.focus();
resetUnread();
}
}
else {
msginput.value = "";
msginput.disabled = false;
msginput.focus();
}
};
var sendmsgonenter = function sendmsgonenter(e) {
var code = e.keyCode || e.which;
if (code != 13 || e.shiftKey) { //Enter keycode
return;
}
e.preventDefault();
var textarea = e.target;
if (textarea.value.trim().length == 0)
return;
var convidp = document.getElementById("convidp");
if (convidp != null) {
textarea.disabled = true; //msginput
window.convid = convidp.innerText * 1;
sendmsg(textarea);
}
};
$(document).ready(function () {
$('#msginput').on("keydown", sendmsgonenter);
});