##// END OF EJS Templates
Fixed getting precise and synced last update time. Added autoscroll to bottom after updating if user is at the page bottom
neko259 -
r373:2f30e48c thread_autoupdate
parent child Browse files
Show More
@@ -51,7 +51,7 b' class PostManager(models.Manager):'
51
51
52 post = self.create(title=title,
52 post = self.create(title=title,
53 text=text,
53 text=text,
54 pub_time=timezone.now(),
54 pub_time=posting_time,
55 thread=thread,
55 thread=thread,
56 image=image,
56 image=image,
57 poster_ip=ip,
57 poster_ip=ip,
@@ -183,7 +183,7 b' class PostManager(models.Manager):'
183 if ref_post.count() > 0:
183 if ref_post.count() > 0:
184 referenced_post = ref_post[0]
184 referenced_post = ref_post[0]
185 referenced_post.referenced_posts.add(post)
185 referenced_post.referenced_posts.add(post)
186 referenced_post.last_edit_time = timezone.now()
186 referenced_post.last_edit_time = post.pub_time
187 referenced_post.save()
187 referenced_post.save()
188
188
189 def _get_page_count(self, thread_count):
189 def _get_page_count(self, thread_count):
@@ -53,6 +53,8 b' function updateThread() {'
53 var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/';
53 var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/';
54 $.getJSON(diffUrl)
54 $.getJSON(diffUrl)
55 .success(function(data) {
55 .success(function(data) {
56 var bottom = isPageBottom();
57
56 var addedPosts = data.added;
58 var addedPosts = data.added;
57
59
58 for (var i = 0; i < addedPosts.length; i++) {
60 for (var i = 0; i < addedPosts.length; i++) {
@@ -81,10 +83,15 b' function updateThread() {'
81 blink(post);
83 blink(post);
82 }
84 }
83
85
84 // TODO Process updated and deleted posts
86 // TODO Process deleted posts
85
87
86 lastUpdateTime = data.last_update;
88 lastUpdateTime = data.last_update;
87 loading = false;
89 loading = false;
90
91 if (bottom) {
92 var $target = $('html,body');
93 $target.animate({scrollTop: $target.height()}, 1000);
94 }
88 })
95 })
89 .error(function(data) {
96 .error(function(data) {
90 // TODO Show error message that server is unavailable?
97 // TODO Show error message that server is unavailable?
@@ -93,6 +100,13 b' function updateThread() {'
93 });
100 });
94 }
101 }
95
102
103 function isPageBottom() {
104 var scroll = $(window).scrollTop() / ($(document).height()
105 - $(window).height())
106
107 return scroll == 1
108 }
109
96 function initAutoupdate() {
110 function initAutoupdate() {
97 loading = false;
111 loading = false;
98
112
@@ -14,6 +14,7 b' from django.template import RequestConte'
14 from django.shortcuts import render, redirect, get_object_or_404
14 from django.shortcuts import render, redirect, get_object_or_404
15 from django.utils import timezone
15 from django.utils import timezone
16 from django.db import transaction
16 from django.db import transaction
17 import math
17
18
18 from boards import forms
19 from boards import forms
19 import boards
20 import boards
@@ -420,7 +421,7 b' def api_get_threaddiff(request, thread_i'
420
421
421 thread = get_object_or_404(Post, id=thread_id)
422 thread = get_object_or_404(Post, id=thread_id)
422
423
423 filter_time = datetime.fromtimestamp(float(last_update_time) / 1000,
424 filter_time = datetime.fromtimestamp(float(last_update_time) / 1000000,
424 timezone.get_current_timezone())
425 timezone.get_current_timezone())
425
426
426 json_data = {
427 json_data = {
@@ -560,4 +561,4 b' def _remove_invalid_links(text):'
560 def _datetime_to_epoch(datetime):
561 def _datetime_to_epoch(datetime):
561 return int(time.mktime(timezone.localtime(
562 return int(time.mktime(timezone.localtime(
562 datetime,timezone.get_current_timezone()).timetuple())
563 datetime,timezone.get_current_timezone()).timetuple())
563 * 1000 + datetime.microsecond) No newline at end of file
564 * 1000000 + datetime.microsecond) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now