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:
parent
166aaf7dcb
commit
0be7b3bb29
@ -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.postCountEl = $('#post-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({
|
||||
name: 'Thread Stats',
|
||||
cb: this.node
|
||||
});
|
||||
},
|
||||
node: function() {
|
||||
ThreadStats.thread = this;
|
||||
ThreadStats.update();
|
||||
$.on(d, 'ThreadUpdate', ThreadStats.update);
|
||||
return $.add(d.body, ThreadStats.dialog);
|
||||
},
|
||||
update: function() {
|
||||
var ID, fileCount, funk, post, postCount, _ref;
|
||||
var ID, fileCount, post, postCount, _ref;
|
||||
postCount = 0;
|
||||
fileCount = 0;
|
||||
_ref = ThreadStats.thread.posts;
|
||||
_ref = this.posts;
|
||||
for (ID in _ref) {
|
||||
post = _ref[ID];
|
||||
if (post.isDead) {
|
||||
continue;
|
||||
}
|
||||
postCount++;
|
||||
if (!post.file || post.file.isDead) {
|
||||
continue;
|
||||
if (post.file) {
|
||||
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.fileCountEl.textContent = fileCount;
|
||||
funk = ThreadStats.isSticky || fileCount <= ThreadStats.fileLimit ? $.rmClass : $.addClass;
|
||||
return funk(ThreadStats.fileCountEl, 'warning');
|
||||
(postLimit && !ThreadStats.thread.isSticky ? $.addClass : $.rmClass)(ThreadStats.postCountEl, 'warning');
|
||||
return (fileLimit && !ThreadStats.thread.isSticky ? $.addClass : $.rmClass)(ThreadStats.fileCountEl, 'warning');
|
||||
}
|
||||
};
|
||||
|
||||
@ -5469,10 +5456,11 @@
|
||||
return $.after(root, [$.tn(' '), icon]);
|
||||
},
|
||||
parse: function(postObjects) {
|
||||
var ID, count, deletedFiles, deletedPosts, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref;
|
||||
Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler;
|
||||
ThreadUpdater.updateThreadStatus('Sticky', postObjects[0]);
|
||||
ThreadUpdater.updateThreadStatus('Closed', postObjects[0]);
|
||||
var ID, OP, count, deletedFiles, deletedPosts, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref;
|
||||
OP = postObjects[0];
|
||||
Build.spoilerRange[ThreadUpdater.thread.board] = OP.custom_spoiler;
|
||||
ThreadUpdater.updateThreadStatus('Sticky', OP);
|
||||
ThreadUpdater.updateThreadStatus('Closed', OP);
|
||||
nodes = [];
|
||||
posts = [];
|
||||
index = [];
|
||||
@ -5551,7 +5539,11 @@
|
||||
thread: ThreadUpdater.thread,
|
||||
newPosts: posts,
|
||||
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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -42,6 +42,7 @@ beta
|
||||
|
||||
Thread Stats changes:
|
||||
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.
|
||||
|
||||
Thread/Post Hiding changes:
|
||||
|
||||
@ -3488,38 +3488,28 @@ ThreadStats =
|
||||
|
||||
@postCountEl = $ '#post-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
|
||||
name: 'Thread Stats'
|
||||
cb: @node
|
||||
node: ->
|
||||
ThreadStats.thread = @
|
||||
ThreadStats.update()
|
||||
$.on d, 'ThreadUpdate', ThreadStats.update
|
||||
$.add d.body, ThreadStats.dialog
|
||||
update: ->
|
||||
postCount = 0
|
||||
fileCount = 0
|
||||
for ID, post of ThreadStats.thread.posts
|
||||
continue if post.isDead
|
||||
for ID, post of @posts
|
||||
postCount++
|
||||
continue if !post.file or post.file.isDead
|
||||
fileCount++
|
||||
fileCount++ if post.file
|
||||
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.fileCountEl.textContent = fileCount
|
||||
funk = if ThreadStats.isSticky or fileCount <= ThreadStats.fileLimit
|
||||
$.rmClass
|
||||
else
|
||||
$.addClass
|
||||
funk ThreadStats.fileCountEl, 'warning'
|
||||
(if postLimit and !ThreadStats.thread.isSticky then $.addClass else $.rmClass) ThreadStats.postCountEl, 'warning'
|
||||
(if fileLimit and !ThreadStats.thread.isSticky then $.addClass else $.rmClass) ThreadStats.fileCountEl, 'warning'
|
||||
|
||||
ThreadUpdater =
|
||||
init: ->
|
||||
@ -3718,10 +3708,11 @@ ThreadUpdater =
|
||||
$.after root, [$.tn(' '), icon]
|
||||
|
||||
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 'Closed', postObjects[0]
|
||||
ThreadUpdater.updateThreadStatus 'Sticky', OP
|
||||
ThreadUpdater.updateThreadStatus 'Closed', OP
|
||||
|
||||
nodes = [] # post container elements
|
||||
posts = [] # post objects
|
||||
@ -3791,6 +3782,10 @@ ThreadUpdater =
|
||||
newPosts: posts
|
||||
deletedPosts: deletedPosts
|
||||
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 =
|
||||
init: ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user