##// END OF EJS Templates
Loading updated posts in thread autoupdate
neko259 -
r364:e8323022 thread_autoupdate
parent child Browse files
Show More
@@ -179,7 +179,10 b' class PostManager(models.Manager):'
179 179 id = reply_number.group(1)
180 180 ref_post = self.filter(id=id)
181 181 if ref_post.count() > 0:
182 ref_post[0].referenced_posts.add(post)
182 referenced_post = ref_post[0]
183 referenced_post.referenced_posts.add(post)
184 referenced_post.last_edit_time = timezone.now()
185 referenced_post.save()
183 186
184 187 def _get_page_count(self, thread_count):
185 188 return int(math.ceil(thread_count / float(settings.THREADS_PER_PAGE)))
@@ -39,9 +39,23 b' function updateThread() {'
39 39
40 40 lastPost = post;
41 41 blink(post);
42
43 42 }
44 43
44 var updatedPosts = data.updated;
45 for (var i = 0; i < updatedPosts.length; i++) {
46 var postText = updatedPosts[i];
47
48 var post = $(postText);
49 var postId = post.attr('id');
50
51 var oldPost = $('div.thread').children('.post[id=' + postId + ']');
52
53 oldPost.replaceWith(post);
54 addRefLinkPreview(post[0]);
55
56 blink(post);
57 }
58
45 59 // TODO Process updated and deleted posts
46 60
47 61 lastUpdateTime = data.last_update;
@@ -418,14 +418,19 b' def api_get_threaddiff(request, thread_i'
418 418 thread = get_object_or_404(Post, id=thread_id)
419 419
420 420 filter_time = datetime.fromtimestamp(float(last_update_time) / 1000)
421 added_posts = Post.objects.filter(thread=thread, pub_time__gt=filter_time)
422 421
423 422 json_data = {
424 423 'added': [],
424 'updated': [],
425 425 'last_update' : int(time.time() * 1000),
426 426 }
427 added_posts = Post.objects.filter(thread=thread, pub_time__gt=filter_time)
428 updated_posts = Post.objects.filter(thread=thread,
429 pub_time__lt=filter_time, last_edit_time__gt=filter_time)
427 430 for post in added_posts:
428 431 json_data['added'].append(get_post(request, post.id).content.strip())
432 for post in updated_posts:
433 json_data['updated'].append(get_post(request, post.id).content.strip())
429 434
430 435 return HttpResponse(content=json.dumps(json_data))
431 436
General Comments 0
You need to be logged in to leave comments. Login now