From 5660b8701caed69c392b3f8c5af19700fc7cbbc7 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 29 Jun 2019 23:11:49 -0700 Subject: [PATCH] Add link to header menu to mark all posts in a thread as unread. #1299 --- src/Monitoring/Unread.coffee | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 2f39d0775..8034fa29f 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -62,6 +62,14 @@ Unread = $.one d, '4chanXInitFinished', Unread.ready $.on d, 'PostsInserted', Unread.onUpdate $.on d, 'ThreadUpdate', (e) -> Unread.update() if e.detail[404] + resetLink = $.el 'a', + href: 'javascript:;' + className: 'unread-reset' + textContent: 'Mark all unread' + $.on resetLink, 'click', Unread.reset + Header.menu.addEntry + el: resetLink + order: 70 ready: -> Unread.scroll() if Conf['Remember Last Read Post'] and Conf['Scroll to Last Read Post'] @@ -89,6 +97,28 @@ Unread = break return + reset: -> + return unless Unread.lastReadPost? + + Unread.posts = new Set() + Unread.postsQuotingYou = new Set() + Unread.order = new RandomAccessList() + Unread.position = null + Unread.lastReadPost = 0 + Unread.readCount = 0 + Unread.thread.posts.forEach (post) -> Unread.addPost.call post + + $.forceSync 'Remember Last Read Post' + if Conf['Remember Last Read Post'] and (!Unread.thread.isDead or Unread.thread.isArchived) + Unread.db.set + boardID: Unread.thread.board.ID + threadID: Unread.thread.ID + val: 0 + + Unread.updatePosition() + Unread.setLine() + Unread.update() + sync: -> return unless Unread.lastReadPost? lastReadPost = Unread.db.get