# HG changeset patch # User neko259 # Date 2013-11-14 11:30:46 # Node ID e8323022d43f696880b88dd5dcd3854b1cb44d5b # Parent 69d0a4bfcf10dc835d3f4c44fc2bbada33e99c3b Loading updated posts in thread autoupdate diff --git a/boards/models.py b/boards/models.py --- a/boards/models.py +++ b/boards/models.py @@ -179,7 +179,10 @@ class PostManager(models.Manager): id = reply_number.group(1) ref_post = self.filter(id=id) if ref_post.count() > 0: - ref_post[0].referenced_posts.add(post) + referenced_post = ref_post[0] + referenced_post.referenced_posts.add(post) + referenced_post.last_edit_time = timezone.now() + referenced_post.save() def _get_page_count(self, thread_count): return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE))) 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 @@ -39,9 +39,23 @@ function updateThread() { lastPost = post; blink(post); - } + var updatedPosts = data.updated; + for (var i = 0; i < updatedPosts.length; i++) { + var postText = updatedPosts[i]; + + var post = $(postText); + var postId = post.attr('id'); + + var oldPost = $('div.thread').children('.post[id=' + postId + ']'); + + oldPost.replaceWith(post); + addRefLinkPreview(post[0]); + + blink(post); + } + // TODO Process updated and deleted posts lastUpdateTime = data.last_update; diff --git a/boards/views.py b/boards/views.py --- a/boards/views.py +++ b/boards/views.py @@ -418,14 +418,19 @@ 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) - added_posts = Post.objects.filter(thread=thread, pub_time__gt=filter_time) json_data = { 'added': [], + 'updated': [], 'last_update' : int(time.time() * 1000), } + added_posts = Post.objects.filter(thread=thread, pub_time__gt=filter_time) + updated_posts = Post.objects.filter(thread=thread, + pub_time__lt=filter_time, last_edit_time__gt=filter_time) for post in added_posts: json_data['added'].append(get_post(request, post.id).content.strip()) + for post in updated_posts: + json_data['updated'].append(get_post(request, post.id).content.strip()) return HttpResponse(content=json.dumps(json_data))