From d98385797696f452ed392e9900b5ceecab104a27 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 31 Jan 2015 01:16:03 -0800 Subject: [PATCH] Merge from Appchan X: src/Monitoring --- src/Monitoring/MarkNewIPs.coffee | 8 ++------ src/Monitoring/ThreadStats.coffee | 2 +- src/Monitoring/ThreadUpdater.coffee | 9 +++++---- src/Monitoring/ThreadWatcher.coffee | 16 ++++++++-------- src/Monitoring/Unread.coffee | 24 +++++++++++++----------- 5 files changed, 29 insertions(+), 30 deletions(-) diff --git a/src/Monitoring/MarkNewIPs.coffee b/src/Monitoring/MarkNewIPs.coffee index 1c6a4386f..263d7e53a 100644 --- a/src/Monitoring/MarkNewIPs.coffee +++ b/src/Monitoring/MarkNewIPs.coffee @@ -7,7 +7,7 @@ MarkNewIPs = node: -> MarkNewIPs.ipCount = @ipCount - MarkNewIPs.postIDs = @posts.keys.map (x) -> +x + MarkNewIPs.postIDs = (+x for x in @posts.keys) $.on d, 'ThreadUpdate', MarkNewIPs.onUpdate onUpdate: (e) -> @@ -35,11 +35,7 @@ MarkNewIPs = suffix = if (ipCount // 10) % 10 is 1 'th' else - switch ipCount % 10 - when 1 then 'st' - when 2 then 'nd' - when 3 then 'rd' - else 'th' + ['st', 'nd', 'rd'][ipCount % 10 - 1] or 'th' # fuck switches counter = $.el 'span', className: 'ip-counter' textContent: "(#{ipCount})" diff --git a/src/Monitoring/ThreadStats.coffee b/src/Monitoring/ThreadStats.coffee index 76795bf8b..9b821626c 100755 --- a/src/Monitoring/ThreadStats.coffee +++ b/src/Monitoring/ThreadStats.coffee @@ -84,5 +84,5 @@ ThreadStats = ThreadStats.pageCountEl.textContent = page.page (if page.page is @response.length then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning' # Thread data may be stale (modification date given < time of last post). If so, try again on next thread update. - ThreadStats.lastPageUpdate = new Date thread.last_modified * 1000 + ThreadStats.lastPageUpdate = new Date thread.last_modified * $.SECOND return diff --git a/src/Monitoring/ThreadUpdater.coffee b/src/Monitoring/ThreadUpdater.coffee index cc6a9cebb..06d80a0a0 100755 --- a/src/Monitoring/ThreadUpdater.coffee +++ b/src/Monitoring/ThreadUpdater.coffee @@ -12,7 +12,7 @@ ThreadUpdater = @dialog = sc = UI.dialog 'updater', 'bottom: 0px; left: 0px;', <%= html('
') %> $.addClass doc, 'float' - $.ready => + $.ready -> $.add d.body, sc @checkPostCount = 0 @@ -120,11 +120,11 @@ ThreadUpdater = -> not d.hidden autoUpdate: (e) -> ThreadUpdater.count ThreadUpdater.isUpdating = @checked - interval: -> + interval: (e) -> val = parseInt @value, 10 if val < 1 then val = 1 ThreadUpdater.interval = @value = val - $.cb.value.call @ + $.cb.value.call @ if e load: (e) -> {req} = ThreadUpdater switch req.status @@ -239,6 +239,7 @@ ThreadUpdater = ThreadUpdater.req?.abort() ThreadUpdater.req = $.ajax "//a.4cdn.org/#{ThreadUpdater.thread.board}/thread/#{ThreadUpdater.thread}.json", onloadend: ThreadUpdater.cb.load + timeout: $.MINUTE , whenModified: true @@ -344,7 +345,7 @@ ThreadUpdater = $.event 'ThreadUpdate', 404: false threadID: ThreadUpdater.thread.fullID - newPosts: posts.map (post) -> post.fullID + newPosts: (post.fullID for post in posts) postCount: OP.replies + 1 fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead) ipCount: OP.unique_ips diff --git a/src/Monitoring/ThreadWatcher.coffee b/src/Monitoring/ThreadWatcher.coffee index c385353c6..7b4541e71 100755 --- a/src/Monitoring/ThreadWatcher.coffee +++ b/src/Monitoring/ThreadWatcher.coffee @@ -14,7 +14,7 @@ ThreadWatcher = @status = $ '#watcher-status', @dialog @list = @dialog.lastElementChild - @refreshButton = $ '.move > .refresh', @dialog + @refreshButton = $ '.refresh', @dialog @unreaddb = Unread.db or new DataBoard 'lastReadPosts' $.on d, 'QRPostSuccessful', @cb.post @@ -36,13 +36,6 @@ ThreadWatcher = ThreadWatcher.fetchAuto() - Post.callbacks.push - name: 'Thread Watcher' - cb: @node - CatalogThread.callbacks.push - name: 'Thread Watcher' - cb: @catalogNode - if g.VIEW is 'index' and Conf['JSON Navigation'] and Conf['Menu'] and g.BOARD.ID isnt 'f' Menu.menu.addEntry el: $.el 'a', href: 'javascript:;' @@ -60,6 +53,13 @@ ThreadWatcher = $.on @el, 'click', @cb true + Post.callbacks.push + name: 'Thread Watcher' + cb: @node + CatalogThread.callbacks.push + name: 'Thread Watcher' + cb: @catalogNode + isWatched: (thread) -> ThreadWatcher.db?.get {boardID: thread.board.ID, threadID: thread.ID} diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index fb78fd62a..5670fbff2 100755 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -1,20 +1,21 @@ Unread = init: -> - return if g.VIEW isnt 'thread' or - !Conf['Unread Count'] and - !Conf['Unread Favicon'] and - !Conf['Unread Line'] and - !Conf['Scroll to Last Read Post'] and - !Conf['Thread Watcher'] and - !Conf['Desktop Notifications'] and - !Conf['Quote Threading'] + return unless g.VIEW is 'thread' and ( + Conf['Unread Count'] or + Conf['Unread Favicon'] or + Conf['Unread Line'] or + Conf['Scroll to Last Read Post'] or + Conf['Thread Watcher'] or + Conf['Desktop Notifications'] or + Conf['Quote Threading'] + ) @db = new DataBoard 'lastReadPosts', @sync @hr = $.el 'hr', id: 'unread-line' - @posts = new Set - @postsQuotingYou = new Set - @order = new RandomAccessList + @posts = new Set() + @postsQuotingYou = new Set() + @order = new RandomAccessList() @position = null Thread.callbacks.push @@ -182,6 +183,7 @@ Unread = updatePosition: -> while Unread.position and !Unread.posts.has Unread.position.ID Unread.position = Unread.position.next + return saveLastReadPost: $.debounce 2 * $.SECOND, -> postIDs = Unread.thread.posts.keys