Add the 'ThreadUpdate' API/event.

This commit is contained in:
Nicolas Stepien 2013-02-14 21:45:52 +01:00
parent b90931b80d
commit 0ffebeca0b
2 changed files with 52 additions and 34 deletions

View File

@ -3916,8 +3916,9 @@
ThreadUpdater.set('status', '404', 'warning'); ThreadUpdater.set('status', '404', 'warning');
clearTimeout(ThreadUpdater.timeoutID); clearTimeout(ThreadUpdater.timeoutID);
ThreadUpdater.thread.kill(); ThreadUpdater.thread.kill();
ThreadUpdater.outdateCount++; $.event('ThreadUpdate', {
ThreadUpdater.set('timer', ThreadUpdater.getInterval()); 404: true
});
break; break;
default: default:
ThreadUpdater.outdateCount++; ThreadUpdater.outdateCount++;
@ -3988,7 +3989,7 @@
}); });
}, },
parse: function(postObjects) { parse: function(postObjects) {
var ID, count, files, index, node, nodes, num, post, postObject, posts, scroll, _i, _len, _ref; 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; Build.spoilerRange[ThreadUpdater.thread.board] = postObjects[0].custom_spoiler;
nodes = []; nodes = [];
posts = []; posts = [];
@ -4010,6 +4011,8 @@
nodes.push(node); nodes.push(node);
posts.push(new Post(node, ThreadUpdater.thread, ThreadUpdater.thread.board)); posts.push(new Post(node, ThreadUpdater.thread, ThreadUpdater.thread.board));
} }
deletedPosts = [];
deletedFiles = [];
_ref = ThreadUpdater.thread.posts; _ref = ThreadUpdater.thread.posts;
for (ID in _ref) { for (ID in _ref) {
post = _ref[ID]; post = _ref[ID];
@ -4019,11 +4022,18 @@
ID = +ID; ID = +ID;
if (-1 === index.indexOf(ID)) { if (-1 === index.indexOf(ID)) {
post.kill(); post.kill();
deletedPosts.push(post);
} else if (post.file && !post.file.isDead && -1 === files.indexOf(ID)) { } else if (post.file && !post.file.isDead && -1 === files.indexOf(ID)) {
post.kill(true); post.kill(true);
deletedFiles.push(post);
} }
} }
if (count) { if (!count) {
ThreadUpdater.set('status', null, null);
ThreadUpdater.outdateCount++;
} else {
ThreadUpdater.set('status', "+" + count, 'new');
ThreadUpdater.outdateCount = 0;
if (Conf['Beep'] && $.hidden()) { if (Conf['Beep'] && $.hidden()) {
if (!ThreadUpdater.audio) { if (!ThreadUpdater.audio) {
ThreadUpdater.audio = $.el('audio', { ThreadUpdater.audio = $.el('audio', {
@ -4032,20 +4042,20 @@
} }
ThreadUpdater.audio.play(); ThreadUpdater.audio.play();
} }
ThreadUpdater.set('status', "+" + count, 'new'); ThreadUpdater.lastPost = posts[count - 1].ID;
ThreadUpdater.outdateCount = 0; Main.callbackNodes(Post, posts);
} else { scroll = Conf['Auto Scroll'] && ThreadUpdater.scrollBG() && ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25;
ThreadUpdater.set('status', null, null); $.add(ThreadUpdater.root, nodes);
ThreadUpdater.outdateCount++; if (scroll) {
return; nodes[0].scrollIntoView();
} }
ThreadUpdater.lastPost = posts[count - 1].ID;
Main.callbackNodes(Post, posts);
scroll = Conf['Auto Scroll'] && ThreadUpdater.scrollBG() && ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25;
$.add(ThreadUpdater.root, nodes);
if (scroll) {
return nodes[0].scrollIntoView();
} }
return $.event('ThreadUpdate', {
404: false,
newPosts: posts,
deletedPosts: deletedPosts,
deletedFiles: deletedFiles
});
} }
}; };

View File

@ -2418,14 +2418,13 @@ ThreadUpdater =
ThreadUpdater.set 'status', '404', 'warning' ThreadUpdater.set 'status', '404', 'warning'
clearTimeout ThreadUpdater.timeoutID clearTimeout ThreadUpdater.timeoutID
ThreadUpdater.thread.kill() ThreadUpdater.thread.kill()
$.event 'ThreadUpdate', 404: true
# if Conf['Unread Count'] # if Conf['Unread Count']
# Unread.title = Unread.title.match(/^.+-/)[0] + ' 404' # Unread.title = Unread.title.match(/^.+-/)[0] + ' 404'
# else # else
# d.title = d.title.match(/^.+-/)[0] + ' 404' # d.title = d.title.match(/^.+-/)[0] + ' 404'
# Unread.update true # Unread.update true
# QR.abort() # QR.abort()
ThreadUpdater.outdateCount++
ThreadUpdater.set 'timer', ThreadUpdater.getInterval()
else else
ThreadUpdater.outdateCount++ ThreadUpdater.outdateCount++
ThreadUpdater.set 'timer', ThreadUpdater.getInterval() ThreadUpdater.set 'timer', ThreadUpdater.getInterval()
@ -2502,32 +2501,41 @@ ThreadUpdater =
nodes.push node nodes.push node
posts.push new Post node, ThreadUpdater.thread, ThreadUpdater.thread.board posts.push new Post node, ThreadUpdater.thread, ThreadUpdater.thread.board
deletedPosts = []
deletedFiles = []
# Check for deleted posts/files. # Check for deleted posts/files.
for ID, post of ThreadUpdater.thread.posts for ID, post of ThreadUpdater.thread.posts
continue if post.isDead continue if post.isDead
ID = +ID ID = +ID
if -1 is index.indexOf ID if -1 is index.indexOf ID
post.kill() post.kill()
deletedPosts.push post
else if post.file and !post.file.isDead and -1 is files.indexOf ID else if post.file and !post.file.isDead and -1 is files.indexOf ID
post.kill true post.kill true
deletedFiles.push post
if count unless count
if Conf['Beep'] and $.hidden() #and !Unread.replies.length ThreadUpdater.set 'status', null, null
ThreadUpdater.outdateCount++
else
ThreadUpdater.set 'status', "+#{count}", 'new'
ThreadUpdater.outdateCount = 0
if Conf['Beep'] and $.hidden() # XXX and !Unread.replies.length
unless ThreadUpdater.audio unless ThreadUpdater.audio
ThreadUpdater.audio = $.el 'audio', src: ThreadUpdater.beep ThreadUpdater.audio = $.el 'audio', src: ThreadUpdater.beep
ThreadUpdater.audio.play() ThreadUpdater.audio.play()
ThreadUpdater.set 'status', "+#{count}", 'new'
ThreadUpdater.outdateCount = 0
else
ThreadUpdater.set 'status', null, null
ThreadUpdater.outdateCount++
return
ThreadUpdater.lastPost = posts[count - 1].ID ThreadUpdater.lastPost = posts[count - 1].ID
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
scroll = Conf['Auto Scroll'] and ThreadUpdater.scrollBG() and scroll = Conf['Auto Scroll'] and ThreadUpdater.scrollBG() and
ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25 ThreadUpdater.root.getBoundingClientRect().bottom - doc.clientHeight < 25
$.add ThreadUpdater.root, nodes $.add ThreadUpdater.root, nodes
if scroll if scroll
nodes[0].scrollIntoView() nodes[0].scrollIntoView()
$.event 'ThreadUpdate',
404: false
newPosts: posts
deletedPosts: deletedPosts
deletedFiles: deletedFiles