Permalink
Browse files

Use cookie to tie in conversations.

  • Loading branch information...
1 parent 77a4173 commit 88af7832f82f3987b473cfac88c42312715921f9 @jmhobbs jmhobbs committed May 15, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 static/chat.js
View
15 static/chat.js
@@ -2,15 +2,26 @@ jQuery(document).ready( function ( $ ) {
var $body = $("#body"),
$send = $("#send"),
$mesg = $("#messages");
-
+
+ var conversation = document.cookie;
+ if( conversation.length == 0 ) {
+ conversation = navigator.appVersion + Math.random() + new Date();
+ conversation = conversation.replace( /\W+/g, '' );
+ document.cookie = "conversation=" + escape( conversation ) + "; path=/";
+ }
+ else {
+ conversation = conversation.split( '=' );
+ conversation = conversation[1];
+ }
+
$send.click( function () {
var val = $body.val().replace( /^\s+|\s+$/g, '' );
if( val.length <= 0 ) { return; }
$body.val('');
$mesg.append( $('<div/>').addClass('me').text(val) );
$.get(
'/chat.txt',
- { conversation: 'lol', body: val }
+ { conversation: conversation, body: val }
).success( function ( data ) {
$mesg.append( $('<div/>').addClass('don').text(data) );
} ).error( function ( xhr ) {

0 comments on commit 88af783

Please sign in to comment.