Implement PostsRemoved event.

This commit is contained in:
ccd0 2018-12-07 12:59:26 -08:00
parent 0ca735c200
commit 87fe975ac6
6 changed files with 27 additions and 5 deletions

View File

@ -183,7 +183,9 @@ ThreadHiding =
threadRoot = thread.nodes.root threadRoot = thread.nodes.root
thread.isHidden = true thread.isHidden = true
Index.updateHideLabel() Index.updateHideLabel()
$.rm thread.catalogView.nodes.root if thread.catalogView and !Index.showHiddenThreads if thread.catalogView and !Index.showHiddenThreads
$.rm thread.catalogView.nodes.root
$.event 'PostsRemoved', null, Index.root
return threadRoot.hidden = true unless makeStub return threadRoot.hidden = true unless makeStub
@ -196,4 +198,6 @@ ThreadHiding =
threadRoot = thread.nodes.root threadRoot = thread.nodes.root
threadRoot.hidden = thread.isHidden = false threadRoot.hidden = thread.isHidden = false
Index.updateHideLabel() Index.updateHideLabel()
$.rm thread.catalogView.nodes.root if thread.catalogView and Index.showHiddenThreads if thread.catalogView and Index.showHiddenThreads
$.rm thread.catalogView.nodes.root
$.event 'PostsRemoved', null, Index.root

View File

@ -869,6 +869,8 @@ Index =
delete Index.pageNum delete Index.pageNum
$.rmAll Index.root $.rmAll Index.root
$.rmAll Header.hover $.rmAll Header.hover
if Index.loaded and Index.root.parentNode
$.event 'PostsRemoved', null, Index.root
if Conf['Index Mode'] is 'catalog' if Conf['Index Mode'] is 'catalog'
Index.buildCatalog threadIDs Index.buildCatalog threadIDs
else else

View File

@ -84,6 +84,8 @@ ExpandThread =
postsCount++ postsCount++
filesCount++ if 'file' of Get.postFromRoot reply filesCount++ if 'file' of Get.postFromRoot reply
$.rm reply $.rm reply
if Index.enabled # otherwise handled by Main.addPosts
$.event 'PostsRemoved', null, a.parentNode
a.textContent = Build.summaryText '+', postsCount, filesCount a.textContent = Build.summaryText '+', postsCount, filesCount
$.rm $('.summary-bottom', threadRoot) $.rm $('.summary-bottom', threadRoot)

View File

@ -87,7 +87,9 @@ QuoteInline =
root = QuoteInline.findRoot quotelink, isBacklink root = QuoteInline.findRoot quotelink, isBacklink
root = $.x "following-sibling::div[@data-full-i-d='#{boardID}.#{postID}'][1]", root root = $.x "following-sibling::div[@data-full-i-d='#{boardID}.#{postID}'][1]", root
qroot = $.x 'ancestor::*[contains(@class,"postContainer")][1]', root qroot = $.x 'ancestor::*[contains(@class,"postContainer")][1]', root
{parentNode} = root
$.rm root $.rm root
$.event 'PostsRemoved', null, parentNode
unless $ '.inline', qroot unless $ '.inline', qroot
$.rmClass qroot, 'hasInline' $.rmClass qroot, 'hasInline'

View File

@ -52,6 +52,8 @@ QuotePreview =
# Stop if it only contains text. # Stop if it only contains text.
return if not (root = @el.firstElementChild) return if not (root = @el.firstElementChild)
$.event 'PostsRemoved', null, Header.hover
clone = Get.postFromRoot root clone = Get.postFromRoot root
post = clone.origin post = clone.origin
post.rmClone root.dataset.clone post.rmClone root.dataset.clone

View File

@ -370,19 +370,29 @@ Main =
return return
addPosts: (records) -> addPosts: (records) ->
threads = [] threads = []
posts = [] threadsRM = []
errors = [] posts = []
errors = []
for record in records for record in records
thread = Get.threadFromRoot record.target thread = Get.threadFromRoot record.target
n = posts.length n = posts.length
Main.parsePosts record.addedNodes, thread, posts, errors Main.parsePosts record.addedNodes, thread, posts, errors
if posts.length > n and thread not in threads if posts.length > n and thread not in threads
threads.push thread threads.push thread
anyRemoved = false
for el in record.removedNodes
if Get.postFromRoot(el)?.nodes.root is el and !doc.contains(el)
anyRemoved = true
break
if anyRemoved and thread not in threadsRM
threadsRM.push thread
Main.handleErrors errors if errors.length Main.handleErrors errors if errors.length
Main.callbackNodesDB 'Post', posts, -> Main.callbackNodesDB 'Post', posts, ->
for thread in threads for thread in threads
$.event 'PostsInserted', null, thread.nodes.root $.event 'PostsInserted', null, thread.nodes.root
for thread in threadsRM
$.event 'PostsRemoved', null, thread.nodes.root
return return
callbackNodes: (klass, nodes) -> callbackNodes: (klass, nodes) ->