From 87fe975ac69eb31a11019011a793024bc944dc47 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 7 Dec 2018 12:59:26 -0800 Subject: [PATCH] Implement PostsRemoved event. --- src/Filtering/ThreadHiding.coffee | 8 ++++++-- src/General/Index.coffee | 2 ++ src/Miscellaneous/ExpandThread.coffee | 2 ++ src/Quotelinks/QuoteInline.coffee | 2 ++ src/Quotelinks/QuotePreview.coffee | 2 ++ src/main/Main.coffee | 16 +++++++++++++--- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Filtering/ThreadHiding.coffee b/src/Filtering/ThreadHiding.coffee index 625f93395..b5352fc80 100644 --- a/src/Filtering/ThreadHiding.coffee +++ b/src/Filtering/ThreadHiding.coffee @@ -183,7 +183,9 @@ ThreadHiding = threadRoot = thread.nodes.root thread.isHidden = true 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 @@ -196,4 +198,6 @@ ThreadHiding = threadRoot = thread.nodes.root threadRoot.hidden = thread.isHidden = false 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 diff --git a/src/General/Index.coffee b/src/General/Index.coffee index 08418028d..5dd02a09f 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -869,6 +869,8 @@ Index = delete Index.pageNum $.rmAll Index.root $.rmAll Header.hover + if Index.loaded and Index.root.parentNode + $.event 'PostsRemoved', null, Index.root if Conf['Index Mode'] is 'catalog' Index.buildCatalog threadIDs else diff --git a/src/Miscellaneous/ExpandThread.coffee b/src/Miscellaneous/ExpandThread.coffee index bb689fc11..aff64b19b 100644 --- a/src/Miscellaneous/ExpandThread.coffee +++ b/src/Miscellaneous/ExpandThread.coffee @@ -84,6 +84,8 @@ ExpandThread = postsCount++ filesCount++ if 'file' of Get.postFromRoot reply $.rm reply + if Index.enabled # otherwise handled by Main.addPosts + $.event 'PostsRemoved', null, a.parentNode a.textContent = Build.summaryText '+', postsCount, filesCount $.rm $('.summary-bottom', threadRoot) diff --git a/src/Quotelinks/QuoteInline.coffee b/src/Quotelinks/QuoteInline.coffee index ea80963eb..1cda988ad 100644 --- a/src/Quotelinks/QuoteInline.coffee +++ b/src/Quotelinks/QuoteInline.coffee @@ -87,7 +87,9 @@ QuoteInline = root = QuoteInline.findRoot quotelink, isBacklink root = $.x "following-sibling::div[@data-full-i-d='#{boardID}.#{postID}'][1]", root qroot = $.x 'ancestor::*[contains(@class,"postContainer")][1]', root + {parentNode} = root $.rm root + $.event 'PostsRemoved', null, parentNode unless $ '.inline', qroot $.rmClass qroot, 'hasInline' diff --git a/src/Quotelinks/QuotePreview.coffee b/src/Quotelinks/QuotePreview.coffee index ff63a9277..90fc43bf0 100644 --- a/src/Quotelinks/QuotePreview.coffee +++ b/src/Quotelinks/QuotePreview.coffee @@ -52,6 +52,8 @@ QuotePreview = # Stop if it only contains text. return if not (root = @el.firstElementChild) + $.event 'PostsRemoved', null, Header.hover + clone = Get.postFromRoot root post = clone.origin post.rmClone root.dataset.clone diff --git a/src/main/Main.coffee b/src/main/Main.coffee index 8ee5f176c..b9f3abc80 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -370,19 +370,29 @@ Main = return addPosts: (records) -> - threads = [] - posts = [] - errors = [] + threads = [] + threadsRM = [] + posts = [] + errors = [] for record in records thread = Get.threadFromRoot record.target n = posts.length Main.parsePosts record.addedNodes, thread, posts, errors if posts.length > n and thread not in threads 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.callbackNodesDB 'Post', posts, -> for thread in threads $.event 'PostsInserted', null, thread.nodes.root + for thread in threadsRM + $.event 'PostsRemoved', null, thread.nodes.root return callbackNodes: (klass, nodes) ->