Skip to content

Commit

Permalink
transition_id 도입 #13 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0629 committed May 6, 2012
1 parent 6c0c358 commit 1c8cfa8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion render/result.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<result channel="{{ channel }}">
<result transition_id="{{ transition_id }}">
{% for log in logs %}
<log>
<datetime><![CDATA[{{ log.datetime }}]]></datetime>
Expand Down
36 changes: 20 additions & 16 deletions static/js/sirc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
var channel = '';
var last_update = '';
var last_downdate = '';
var transition_id = 0;

// Utility

var add_process = function(xml, flag) {
if($('result', xml).attr('channel') != channel) return;
$('log', xml).each(function(i) {
var datetime = $(this).find('datetime').text();
var source = $(this).find('source').text();
Expand Down Expand Up @@ -63,12 +63,14 @@ var sirc_update = function() {
$.ajax({
type: 'GET',
url: '/update/',
data: 'channel=' + encodeURIComponent(channel) + '&last_update=' + encodeURIComponent(last_update),
data: 'channel=' + encodeURIComponent(channel) + '&last_update=' + encodeURIComponent(last_update) + '&transition_id=' + transition_id,
dataType: 'xml',
success: function(xml) {
add_process(xml, 'update');
$('ul#log > li[flag="send"]').remove();
setTimeout("sirc_update();", 500);
if($('result', xml).attr('transition_id') == transition_id) {
add_process(xml, 'update');
$('ul#log > li[flag="send"]').remove();
setTimeout("sirc_update();", 500);
}
},
error: function(xhr) {
//alert('update: ' + xhr.responseText);
Expand All @@ -84,15 +86,17 @@ var sirc_downdate = function(callback) {
$.ajax({
type: 'GET',
url: '/downdate/',
data: 'channel=' + encodeURIComponent(channel) + '&last_downdate=' + encodeURIComponent(last_downdate),
data: 'channel=' + encodeURIComponent(channel) + '&last_downdate=' + encodeURIComponent(last_downdate) + '&transition_id=' + transition_id,
dataType: 'xml',
success: function(xml) {
add_process(xml, 'downdate');
if($('log', xml).length > 0)
$('<li><a>more</a></li>').click(function() { $(this).remove(); return sirc_downdate(); }).prependTo($('ul#log'));
$('ul#log').listview('refresh');
if(callback) callback();
$.mobile.hidePageLoadingMsg();
if($('result', xml).attr('transition_id') == transition_id) {
add_process(xml, 'downdate');
if($('log', xml).length > 0)
$('<li><a>more</a></li>').click(function() { $(this).remove(); return sirc_downdate(); }).prependTo($('ul#log'));
$('ul#log').listview('refresh');
if(callback) callback();
$.mobile.hidePageLoadingMsg();
}
},
error: function(xhr) {
//alert('downdate: ' + xhr.responseText);
Expand Down Expand Up @@ -125,7 +129,7 @@ var sirc_send = function() {
return false;
};

var sirc_join = function(init) {
var sirc_join = function() {
if(!window.location.hash) return;
channel = window.location.hash;
$('a#dummy').attr('name', channel.substr(1))
Expand All @@ -134,7 +138,7 @@ var sirc_join = function(init) {
$('ul#log').empty();
last_update = last_downdate = datetime_now();
sirc_downdate(function() { scroll(SCROLL_END, 1000); });
if(init) setTimeout("sirc_update();", 500);
setTimeout("sirc_update();", 500);
return false;
};

Expand All @@ -144,6 +148,6 @@ $(document).ready(function() {
$('a#setting').click(function() { $('div#menu').toggle(); return false; });
$('form#send').submit(function() { return sirc_send(); });
$('input#message').keydown(function (e) { if(e.keyCode == 13) return sirc_send(); });
$(window).hashchange(function() { return sirc_join(false); });
sirc_join(true);
$(window).hashchange(function() { transition_id++; return sirc_join(); });
sirc_join();
});
8 changes: 8 additions & 0 deletions wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def update(environ, start_response, session, parameters):
last_update = datetime.datetime.now()
if 'last_update' in parameters:
last_update = parse_datetime(parameters['last_update'][0].decode('utf-8'))
if 'transition_id' not in parameters:
return error(start_response, message = 'no transition_id')
channel = parameters['channel'][0].decode('utf-8').lower()
transition_id = parameters['transition_id'][0].decode('utf-8')
context['channel'] = channel
context['transition_id'] = transition_id
logs = []
for i in xrange(30):
logs = list(db[channel].find({
Expand All @@ -134,8 +138,12 @@ def downdate(environ, start_response, session, parameters):
last_downdate = datetime.datetime.now()
if 'last_downdate' in parameters:
last_downdate = parse_datetime(parameters['last_downdate'][0].decode('utf-8'))
if 'transition_id' not in parameters:
return error(start_response, message = 'no transition_id')
channel = parameters['channel'][0].decode('utf-8').lower()
transition_id = parameters['transition_id'][0].decode('utf-8')
context['channel'] = channel
context['transition_id'] = transition_id
logs = db[channel].find({
'datetime': {"$lt": last_downdate},
}, limit = config.N_LINES, sort = [
Expand Down

0 comments on commit 1c8cfa8

Please sign in to comment.