diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 1014377b1..8f5ebcc59 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -355,9 +355,14 @@ Config = true 'Show a line to distinguish read posts from unread ones.' ] + 'Remember Last Read Post': [ + true + 'Remember how far you\'ve read after you close the thread.' + ] 'Scroll to Last Read Post': [ true 'Scroll back to the last read post when reopening a thread.' + 1 ] 'Thread Excerpt': [ true diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index 997d852a9..c246e0579 100644 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -145,7 +145,7 @@ ThreadWatcher = if Conf['Auto Prune'] or not (data and typeof data is 'object') # corrupt data db.delete {boardID, threadID} else - if Conf['Show Unread Count'] + if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] ThreadWatcher.fetchStatus {boardID, threadID, data} data.isDead = true db.set {boardID, threadID, val: data} @@ -174,7 +174,7 @@ ThreadWatcher = clearTimeout ThreadWatcher.timeout return unless Conf['Auto Update Thread Watcher'] {db} = ThreadWatcher - interval = if Conf['Show Unread Count'] then 5 * $.MINUTE else 2 * $.HOUR + interval = if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] then 5 * $.MINUTE else 2 * $.HOUR now = Date.now() if now >= (db.data.lastChecked or 0) + interval db.data.lastChecked = now @@ -291,7 +291,7 @@ ThreadWatcher = title: data.excerpt className: 'watcher-link' - if Conf['Show Unread Count'] and data.unread? + if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] and data.unread? count = $.el 'span', textContent: "(#{data.unread})" className: 'watcher-unread' @@ -307,7 +307,7 @@ ThreadWatcher = div.dataset.fullID = fullID $.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}" $.addClass div, 'dead-thread' if data.isDead - if Conf['Show Unread Count'] + if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] $.addClass div, 'replies-read' if data.unread is 0 $.addClass div, 'replies-unread' if data.unread $.addClass div, 'replies-quoting-you' if data.quotingYou @@ -397,7 +397,7 @@ ThreadWatcher = data.excerpt = Get.threadExcerpt thread ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.refresh() - if Conf['Show Unread Count'] + if Conf['Remember Last Read Post'] and Conf['Show Unread Count'] ThreadWatcher.fetchStatus {boardID, threadID, data}, true rm: (boardID, threadID) -> @@ -473,6 +473,10 @@ ThreadWatcher = el: UI.checkbox name, name.replace(' Thread Watcher', '') entry.el.title = desc input = entry.el.firstElementChild + if name is 'Show Unread Count' and not Conf['Remember Last Read Post'] + input.disabled = true + $.addClass entry.el, 'disabled' + entry.el.title += '\n[Remember Last Read Post is disabled.]' $.on input, 'change', $.cb.checked $.on input, 'change', ThreadWatcher.refresh if name in ['Current Board', 'Show Unread Count'] $.on input, 'change', ThreadWatcher.fetchAuto if name in ['Show Unread Count', 'Auto Update Thread Watcher'] diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index 3d8d820c8..930cd4509 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -4,13 +4,14 @@ Unread = Conf['Unread Count'] or Conf['Unread Favicon'] or Conf['Unread Line'] or - Conf['Scroll to Last Read Post'] or - Conf['Thread Watcher'] or + Conf['Remember Last Read Post'] or Conf['Desktop Notifications'] or Conf['Quote Threading'] ) - @db = new DataBoard 'lastReadPosts', @sync + if Conf['Remember Last Read Post'] + @db = new DataBoard 'lastReadPosts', @sync + @hr = $.el 'hr', id: 'unread-line' @posts = new Set() @@ -50,10 +51,10 @@ Unread = node: -> Unread.thread = @ Unread.title = d.title - Unread.lastReadPost = Unread.db.get + Unread.lastReadPost = Unread.db?.get( boardID: @board.ID threadID: @ID - defaultValue: 0 + ) or 0 Unread.readCount = 0 Unread.readCount++ for ID in @posts.keys when +ID <= Unread.lastReadPost $.one d, '4chanXInitFinished', Unread.ready @@ -63,7 +64,7 @@ Unread = Unread.setLine true Unread.read() Unread.update() - Unread.scroll() if Conf['Scroll to Last Read Post'] + Unread.scroll() if Conf['Remember Last Read Post'] and Conf['Scroll to Last Read Post'] $.on d, 'scroll visibilitychange', Unread.read $.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] @@ -192,6 +193,7 @@ Unread = return saveLastReadPost: $.debounce 2 * $.SECOND, -> + return unless Conf['Remember Last Read Post'] and Unread.db postIDs = Unread.thread.posts.keys for i in [Unread.readCount...postIDs.length] by 1 ID = +postIDs[i] @@ -228,7 +230,7 @@ Unread = Unread.title d.title = "#{titleQuotingYou}#{titleCount}#{titleDead}" - unless Unread.thread.isDead and !Unread.thread.isArchived + if Conf['Remember Last Read Post'] and (!Unread.thread.isDead or Unread.thread.isArchived) ThreadWatcher.update Unread.thread.board.ID, Unread.thread.ID, isDead: Unread.thread.isDead unread: count