Show More
@@ -29,6 +29,7 b" var wsUser = '';" | |||||
29 | var loading = false; |
|
29 | var loading = false; | |
30 | var lastUpdateTime = null; |
|
30 | var lastUpdateTime = null; | |
31 | var unreadPosts = 0; |
|
31 | var unreadPosts = 0; | |
|
32 | var documentOriginalTitle = ''; | |||
32 |
|
33 | |||
33 | // Thread ID does not change, can be stored one time |
|
34 | // Thread ID does not change, can be stored one time | |
34 | var threadId = $('div.thread').children('.post').first().attr('id'); |
|
35 | var threadId = $('div.thread').children('.post').first().attr('id'); | |
@@ -65,6 +66,8 b' function connectWebsocket() {' | |||||
65 | } |
|
66 | } | |
66 | }); |
|
67 | }); | |
67 |
|
68 | |||
|
69 | // For the case we closed the browser and missed some updates | |||
|
70 | getThreadDiff(); | |||
68 | $('#autoupdate').text('[+]'); |
|
71 | $('#autoupdate').text('[+]'); | |
69 | }); |
|
72 | }); | |
70 |
|
73 | |||
@@ -73,6 +76,51 b' function connectWebsocket() {' | |||||
73 | return true; |
|
76 | return true; | |
74 | } |
|
77 | } | |
75 |
|
78 | |||
|
79 | /** | |||
|
80 | * Get diff of the posts from the current thread timestamp. | |||
|
81 | * This is required if the browser was closed and some post updates were | |||
|
82 | * missed. | |||
|
83 | */ | |||
|
84 | function getThreadDiff() { | |||
|
85 | var lastPost = threadPosts.last(); | |||
|
86 | var threadId = threadPosts.first().attr('id'); | |||
|
87 | ||||
|
88 | var diffUrl = '/api/diff_thread/' + threadId + '/' + lastUpdateTime + '/'; | |||
|
89 | ||||
|
90 | lastUpdateTime = $('.metapanel').attr('data-last-update'); | |||
|
91 | ||||
|
92 | $.getJSON(diffUrl) | |||
|
93 | .success(function(data) { | |||
|
94 | var bottom = isPageBottom(); | |||
|
95 | var addedPosts = data.added; | |||
|
96 | ||||
|
97 | for (var i = 0; i < addedPosts.length; i++) { | |||
|
98 | var postText = addedPosts[i]; | |||
|
99 | var post = $(postText); | |||
|
100 | ||||
|
101 | updatePost(post, true) | |||
|
102 | ||||
|
103 | lastPost = post; | |||
|
104 | } | |||
|
105 | ||||
|
106 | var updatedPosts = data.updated; | |||
|
107 | ||||
|
108 | for (var i = 0; i < updatedPosts.length; i++) { | |||
|
109 | var postText = updatedPosts[i]; | |||
|
110 | var post = $(postText); | |||
|
111 | ||||
|
112 | updatePost(post, false) | |||
|
113 | } | |||
|
114 | ||||
|
115 | // TODO Process removed posts if any | |||
|
116 | ||||
|
117 | lastUpdateTime = data.last_update; | |||
|
118 | }) | |||
|
119 | } | |||
|
120 | ||||
|
121 | /** | |||
|
122 | * Add or update the post on thml page. | |||
|
123 | */ | |||
76 | function updatePost(postHtml, isAdded) { |
|
124 | function updatePost(postHtml, isAdded) { | |
77 | // This needs to be set on start because the page is scrolled after posts |
|
125 | // This needs to be set on start because the page is scrolled after posts | |
78 | // are added or updated |
|
126 | // are added or updated | |
@@ -110,6 +158,9 b' function updatePost(postHtml, isAdded) {' | |||||
110 | updateMetadataPanel(lastUpdate) |
|
158 | updateMetadataPanel(lastUpdate) | |
111 | } |
|
159 | } | |
112 |
|
160 | |||
|
161 | /** | |||
|
162 | * Initiate a blinking animation on a node to show it was updated. | |||
|
163 | */ | |||
113 | function blink(node) { |
|
164 | function blink(node) { | |
114 | var blinkCount = 2; |
|
165 | var blinkCount = 2; | |
115 |
|
166 | |||
@@ -138,6 +189,10 b' function getImageCount() {' | |||||
138 | return $('.thread').find('img').length |
|
189 | return $('.thread').find('img').length | |
139 | } |
|
190 | } | |
140 |
|
191 | |||
|
192 | /** | |||
|
193 | * Update post count, images count and last update time in the metadata | |||
|
194 | * panel. | |||
|
195 | */ | |||
141 | function updateMetadataPanel(lastUpdate) { |
|
196 | function updateMetadataPanel(lastUpdate) { | |
142 | var replyCountField = $('#reply-count'); |
|
197 | var replyCountField = $('#reply-count'); | |
143 | var imageCountField = $('#image-count'); |
|
198 | var imageCountField = $('#image-count'); | |
@@ -178,7 +233,6 b' function updateBumplimitProgress(postDel' | |||||
178 | } |
|
233 | } | |
179 | } |
|
234 | } | |
180 |
|
235 | |||
181 | var documentOriginalTitle = ''; |
|
|||
182 | /** |
|
236 | /** | |
183 | * Show 'new posts' text in the title if the document is not visible to a user |
|
237 | * Show 'new posts' text in the title if the document is not visible to a user | |
184 | */ |
|
238 | */ |
@@ -2,7 +2,6 b' from django.core.urlresolvers import rev' | |||||
2 | from django.db import transaction |
|
2 | from django.db import transaction | |
3 | from django.http import Http404 |
|
3 | from django.http import Http404 | |
4 | from django.shortcuts import get_object_or_404, render, redirect |
|
4 | from django.shortcuts import get_object_or_404, render, redirect | |
5 | from django.views.decorators.cache import never_cache, cache_control |
|
|||
6 | from django.views.generic.edit import FormMixin |
|
5 | from django.views.generic.edit import FormMixin | |
7 |
|
6 | |||
8 | from boards import utils, settings |
|
7 | from boards import utils, settings | |
@@ -39,7 +38,6 b" MODE_NORMAL = 'normal'" | |||||
39 |
|
38 | |||
40 | class ThreadView(BaseBoardView, PostMixin, FormMixin): |
|
39 | class ThreadView(BaseBoardView, PostMixin, FormMixin): | |
41 |
|
40 | |||
42 | @cache_control(no_cache=True) |
|
|||
43 | def get(self, request, post_id, mode=MODE_NORMAL, form=None): |
|
41 | def get(self, request, post_id, mode=MODE_NORMAL, form=None): | |
44 | try: |
|
42 | try: | |
45 | opening_post = Post.objects.filter(id=post_id).only('thread_new')[0] |
|
43 | opening_post = Post.objects.filter(id=post_id).only('thread_new')[0] |
General Comments 0
You need to be logged in to leave comments.
Login now