Update thread stats to make better use of the API, as it actually gives us the number of replies/files and if we're past the bump limit/file limit.

This commit is contained in:
Nicolas Stepien 2013-03-02 01:00:25 +01:00
parent 166aaf7dcb
commit 0be7b3bb29
3 changed files with 48 additions and 60 deletions

View File

@ -5187,51 +5187,38 @@
this.dialog = UI.dialog('thread-stats', 'bottom: 0; left: 0;', "<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>"); this.dialog = UI.dialog('thread-stats', 'bottom: 0; left: 0;', "<div class=move><span id=post-count>0</span> / <span id=file-count>0</span></div>");
this.postCountEl = $('#post-count', this.dialog); this.postCountEl = $('#post-count', this.dialog);
this.fileCountEl = $('#file-count', this.dialog); this.fileCountEl = $('#file-count', this.dialog);
this.fileLimit = (function() {
switch (g.BOARD.ID) {
case 'a':
case 'b':
case 'v':
case 'co':
case 'mlp':
return 251;
case 'vg':
return 376;
default:
return 151;
}
})();
return Thread.prototype.callbacks.push({ return Thread.prototype.callbacks.push({
name: 'Thread Stats', name: 'Thread Stats',
cb: this.node cb: this.node
}); });
}, },
node: function() { node: function() {
ThreadStats.thread = this; var ID, fileCount, post, postCount, _ref;
ThreadStats.update();
$.on(d, 'ThreadUpdate', ThreadStats.update);
return $.add(d.body, ThreadStats.dialog);
},
update: function() {
var ID, fileCount, funk, post, postCount, _ref;
postCount = 0; postCount = 0;
fileCount = 0; fileCount = 0;
_ref = ThreadStats.thread.posts; _ref = this.posts;
for (ID in _ref) { for (ID in _ref) {
post = _ref[ID]; post = _ref[ID];
if (post.isDead) {
continue;
}
postCount++; postCount++;
if (!post.file || post.file.isDead) { if (post.file) {
continue; fileCount++;
} }
fileCount++;
} }
ThreadStats.update(postCount, fileCount);
ThreadStats.thread = this;
$.on(d, 'ThreadUpdate', ThreadStats.onUpdate);
return $.add(d.body, ThreadStats.dialog);
},
onUpdate: function(e) {
var fileCount, fileLimit, postCount, postLimit, _ref;
_ref = e.detail, postCount = _ref.postCount, fileCount = _ref.fileCount, postLimit = _ref.postLimit, fileLimit = _ref.fileLimit;
return ThreadStats.update(postCount, fileCount, postLimit, fileLimit);
},
update: function(postCount, fileCount, postLimit, fileLimit) {
ThreadStats.postCountEl.textContent = postCount; ThreadStats.postCountEl.textContent = postCount;
ThreadStats.fileCountEl.textContent = fileCount; ThreadStats.fileCountEl.textContent = fileCount;
funk = ThreadStats.isSticky || fileCount <= ThreadStats.fileLimit ? $.rmClass : $.addClass; (postLimit && !ThreadStats.thread.isSticky ? $.addClass : $.rmClass)(ThreadStats.postCountEl, 'warning');
return funk(ThreadStats.fileCountEl, 'warning'); return (fileLimit && !ThreadStats.thread.isSticky ? $.addClass : $.rmClass)(ThreadStats.fileCountEl, 'warning');
} }
}; };
@ -5469,10 +5456,11 @@
return $.after(root, [$.tn(' '), icon]); return $.after(root, [$.tn(' '), icon]);
}, },
parse: function(postObjects) { parse: function(postObjects) {
var ID, count, deletedFiles, deletedPosts, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref; var ID, OP, count, deletedFiles, deletedPosts, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref;
Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler; OP = postObjects[0];
ThreadUpdater.updateThreadStatus('Sticky', postObjects[0]); Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler;
ThreadUpdater.updateThreadStatus('Closed', postObjects[0]); ThreadUpdater.updateThreadStatus('Sticky', OP);
ThreadUpdater.updateThreadStatus('Closed', OP);
nodes = []; nodes = [];
posts = []; posts = [];
index = []; index = [];
@ -5551,7 +5539,11 @@
thread: ThreadUpdater.thread, thread: ThreadUpdater.thread,
newPosts: posts, newPosts: posts,
deletedPosts: deletedPosts, deletedPosts: deletedPosts,
deletedFiles: deletedFiles deletedFiles: deletedFiles,
postCount: OP.replies + 1,
fileCount: OP.images + (!!ThreadUpdater.thread.OP.file && !ThreadUpdater.thread.OP.file.isDead),
postLimit: !!OP.bumplimit,
fileLimit: !!OP.imagelimit
}); });
} }
}; };

View File

@ -42,6 +42,7 @@ beta
Thread Stats changes: Thread Stats changes:
Post and file count will now adjust with deleted posts. Post and file count will now adjust with deleted posts.
The post count will now go red past the bump limit.
The file count will not go red anymore when the thread is a sticky. The file count will not go red anymore when the thread is a sticky.
Thread/Post Hiding changes: Thread/Post Hiding changes:

View File

@ -3488,38 +3488,28 @@ ThreadStats =
@postCountEl = $ '#post-count', @dialog @postCountEl = $ '#post-count', @dialog
@fileCountEl = $ '#file-count', @dialog @fileCountEl = $ '#file-count', @dialog
@fileLimit = # XXX boards config, need up to date data on this, check browser
switch g.BOARD.ID
when 'a', 'b', 'v', 'co', 'mlp'
251
when 'vg'
376
else
151
Thread::callbacks.push Thread::callbacks.push
name: 'Thread Stats' name: 'Thread Stats'
cb: @node cb: @node
node: -> node: ->
ThreadStats.thread = @
ThreadStats.update()
$.on d, 'ThreadUpdate', ThreadStats.update
$.add d.body, ThreadStats.dialog
update: ->
postCount = 0 postCount = 0
fileCount = 0 fileCount = 0
for ID, post of ThreadStats.thread.posts for ID, post of @posts
continue if post.isDead
postCount++ postCount++
continue if !post.file or post.file.isDead fileCount++ if post.file
fileCount++ ThreadStats.update postCount, fileCount
ThreadStats.thread = @
$.on d, 'ThreadUpdate', ThreadStats.onUpdate
$.add d.body, ThreadStats.dialog
onUpdate: (e) ->
{postCount, fileCount, postLimit, fileLimit} = e.detail
ThreadStats.update postCount, fileCount, postLimit, fileLimit
update: (postCount, fileCount, postLimit, fileLimit) ->
ThreadStats.postCountEl.textContent = postCount ThreadStats.postCountEl.textContent = postCount
ThreadStats.fileCountEl.textContent = fileCount ThreadStats.fileCountEl.textContent = fileCount
funk = if ThreadStats.isSticky or fileCount <= ThreadStats.fileLimit (if postLimit and !ThreadStats.thread.isSticky then $.addClass else $.rmClass) ThreadStats.postCountEl, 'warning'
$.rmClass (if fileLimit and !ThreadStats.thread.isSticky then $.addClass else $.rmClass) ThreadStats.fileCountEl, 'warning'
else
$.addClass
funk ThreadStats.fileCountEl, 'warning'
ThreadUpdater = ThreadUpdater =
init: -> init: ->
@ -3718,10 +3708,11 @@ ThreadUpdater =
$.after root, [$.tn(' '), icon] $.after root, [$.tn(' '), icon]
parse: (postObjects) -> parse: (postObjects) ->
Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler OP = postObjects[0]
Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler
ThreadUpdater.updateThreadStatus 'Sticky', postObjects[0] ThreadUpdater.updateThreadStatus 'Sticky', OP
ThreadUpdater.updateThreadStatus 'Closed', postObjects[0] ThreadUpdater.updateThreadStatus 'Closed', OP
nodes = [] # post container elements nodes = [] # post container elements
posts = [] # post objects posts = [] # post objects
@ -3791,6 +3782,10 @@ ThreadUpdater =
newPosts: posts newPosts: posts
deletedPosts: deletedPosts deletedPosts: deletedPosts
deletedFiles: deletedFiles deletedFiles: deletedFiles
postCount: OP.replies + 1
fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead)
postLimit: !!OP.bumplimit
fileLimit: !!OP.imagelimit
ThreadWatcher = ThreadWatcher =
init: -> init: ->