diff options
| author | sostler <sbostler@gmail.com> | 2010-01-07 23:54:07 -0500 |
|---|---|---|
| committer | sostler <sbostler@gmail.com> | 2010-01-07 23:54:07 -0500 |
| commit | 4e837788114e07330be2dfb869efd70e525b2bc4 (patch) | |
| tree | c4a644a6e0981c302d3f997d61bf5619eedf728c /static/pichat.js | |
| parent | ca746303a8fc20f304bb3ccbeb74f8ae4631a37e (diff) | |
| parent | cce37b4db8a981ef00db0ebb75f7c98f1c336543 (diff) | |
Added multiple-window posting, removed posting delay
Diffstat (limited to 'static/pichat.js')
| -rwxr-xr-x | static/pichat.js | 31 |
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, |
