diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -51,7 +51,7 @@ class PostManager(models.Manager): post = self.create(title=title, text=text, - pub_time=timezone.now(), + pub_time=posting_time, thread=thread, image=image, poster_ip=ip, @@ -183,7 +183,7 @@ class PostManager(models.Manager): if ref_post.count() > 0: referenced_post = ref_post[0] referenced_post.referenced_posts.add(post) - referenced_post.last_edit_time = timezone.now() + referenced_post.last_edit_time = post.pub_time referenced_post.save() def _get_page_count(self, thread_count): diff --git a/boards/static/js/thread_update.js b/boards/static/js/thread_update.js --- a/boards/static/js/thread_update.js +++ b/boards/static/js/thread_update.js @@ -53,6 +53,8 @@ function updateThread() { var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/'; $.getJSON(diffUrl) .success(function(data) { + var bottom = isPageBottom(); + var addedPosts = data.added; for (var i = 0; i < addedPosts.length; i++) { @@ -81,10 +83,15 @@ function updateThread() { blink(post); } - // TODO Process updated and deleted posts + // TODO Process deleted posts lastUpdateTime = data.last_update; loading = false; + + if (bottom) { + var $target = $('html,body'); + $target.animate({scrollTop: $target.height()}, 1000); + } }) .error(function(data) { // TODO Show error message that server is unavailable? @@ -93,6 +100,13 @@ function updateThread() { }); } +function isPageBottom() { + var scroll = $(window).scrollTop() / ($(document).height() + - $(window).height()) + + return scroll == 1 +} + function initAutoupdate() { loading = false; diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -14,6 +14,7 @@ from django.template import RequestConte from django.shortcuts import render, redirect, get_object_or_404 from django.utils import timezone from django.db import transaction +import math from boards import forms import boards @@ -420,7 +421,7 @@ def api_get_threaddiff(request, thread_i thread = get_object_or_404(Post, id=thread_id) - filter_time = datetime.fromtimestamp(float(last_update_time) / 1000, + filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000, timezone.get_current_timezone()) json_data = { @@ -560,4 +561,4 @@ def _remove_invalid_links(text): def _datetime_to_epoch(datetime): return int(time.mktime(timezone.localtime( datetime,timezone.get_current_timezone()).timetuple()) - * 1000 + datetime.microsecond) \ No newline at end of file + * 1000000 + datetime.microsecond) \ No newline at end of file