summaryrefslogtreecommitdiff
path: root/static/pichat.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/pichat.js')
-rwxr-xr-xstatic/pichat.js31
1 files changed, 20 insertions, 11 deletions
diff --git a/static/pichat.js b/static/pichat.js
index 51489a4..3267b49 100755
--- a/static/pichat.js
+++ b/static/pichat.js
@@ -57,15 +57,12 @@ function handleMsgError(resp) {
}
function submitMessage() {
- var content = $('#msgInput').val();
+ var content = $.trim($('#msgInput').val());
if (content == '') { return; }
-
- $('#msgInput, #msgSubmit').attr('disabled', 'disabled');
- var onSuccess = function(json) {
- $('#msgInput, #msgSubmit').removeAttr('disabled');
- $('#msgInput').val('');
- };
-
+ PostedMessages.push(content);
+ $('#msgInput').val('');
+
+ var onSuccess = function(json) {};
var onError = function(resp, textStatus, errorThrown) {
$('#msgInput, #msgSubmit').removeAttr('disabled');
handleMsgError(resp);
@@ -120,12 +117,24 @@ function updateUI(msgs, users) {
}
}
+// A duplicate message is a message that was likely to have
+// originated from this browser.
+function isDuplicateMessage(m) {
+ if (m.nick != Nick || $.inArray(m.content, PostedMessages) == -1) {
+ return false;
+ }
+ var now = new Date().getTime();
+ console.log(now, m.created_on);
+ return m.created_on - now < 5000;
+}
+
function refresh() {
var onSuccess = function(json) {
+ Timestamp = json.timestamp;
var messages = $.grep(
json.messages,
- function(m) { return m.nick != Nick });
- updateUI(messages, json.users);
+ function(m) { return !isDuplicateMessage(m) });
+ updateUI(messages, json.users);
setTimeout(refresh, 1000);
};
var onError = function(resp, textStatus, errorThrown) {
@@ -136,7 +145,7 @@ function refresh() {
type: 'GET',
timeout: 5000,
url: '/refresh',
- data: { 'room': Room },
+ data: { 'room': Room, 'since': Timestamp },
cache: false,
dataType: 'json',
success: onSuccess,