Merge from Appchan X: src/Monitoring

This commit is contained in:
ccd0 2015-01-31 01:16:03 -08:00
parent 7147ad0a01
commit d983857976
5 changed files with 29 additions and 30 deletions

View File

@ -7,7 +7,7 @@ MarkNewIPs =
node: -> node: ->
MarkNewIPs.ipCount = @ipCount MarkNewIPs.ipCount = @ipCount
MarkNewIPs.postIDs = @posts.keys.map (x) -> +x MarkNewIPs.postIDs = (+x for x in @posts.keys)
$.on d, 'ThreadUpdate', MarkNewIPs.onUpdate $.on d, 'ThreadUpdate', MarkNewIPs.onUpdate
onUpdate: (e) -> onUpdate: (e) ->
@ -35,11 +35,7 @@ MarkNewIPs =
suffix = if (ipCount // 10) % 10 is 1 suffix = if (ipCount // 10) % 10 is 1
'th' 'th'
else else
switch ipCount % 10 ['st', 'nd', 'rd'][ipCount % 10 - 1] or 'th' # fuck switches
when 1 then 'st'
when 2 then 'nd'
when 3 then 'rd'
else 'th'
counter = $.el 'span', counter = $.el 'span',
className: 'ip-counter' className: 'ip-counter'
textContent: "(#{ipCount})" textContent: "(#{ipCount})"

View File

@ -84,5 +84,5 @@ ThreadStats =
ThreadStats.pageCountEl.textContent = page.page ThreadStats.pageCountEl.textContent = page.page
(if page.page is @response.length then $.addClass else $.rmClass) ThreadStats.pageCountEl, 'warning' (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. # 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 return

View File

@ -12,7 +12,7 @@ ThreadUpdater =
@dialog = sc = UI.dialog 'updater', 'bottom: 0px; left: 0px;', @dialog = sc = UI.dialog 'updater', 'bottom: 0px; left: 0px;',
<%= html('<div class="move"></div><span id="update-status"></span><span id="update-timer" title="Update now"></span>') %> <%= html('<div class="move"></div><span id="update-status"></span><span id="update-timer" title="Update now"></span>') %>
$.addClass doc, 'float' $.addClass doc, 'float'
$.ready => $.ready ->
$.add d.body, sc $.add d.body, sc
@checkPostCount = 0 @checkPostCount = 0
@ -120,11 +120,11 @@ ThreadUpdater =
-> not d.hidden -> not d.hidden
autoUpdate: (e) -> autoUpdate: (e) ->
ThreadUpdater.count ThreadUpdater.isUpdating = @checked ThreadUpdater.count ThreadUpdater.isUpdating = @checked
interval: -> interval: (e) ->
val = parseInt @value, 10 val = parseInt @value, 10
if val < 1 then val = 1 if val < 1 then val = 1
ThreadUpdater.interval = @value = val ThreadUpdater.interval = @value = val
$.cb.value.call @ $.cb.value.call @ if e
load: (e) -> load: (e) ->
{req} = ThreadUpdater {req} = ThreadUpdater
switch req.status switch req.status
@ -239,6 +239,7 @@ ThreadUpdater =
ThreadUpdater.req?.abort() ThreadUpdater.req?.abort()
ThreadUpdater.req = $.ajax "//a.4cdn.org/#{ThreadUpdater.thread.board}/thread/#{ThreadUpdater.thread}.json", ThreadUpdater.req = $.ajax "//a.4cdn.org/#{ThreadUpdater.thread.board}/thread/#{ThreadUpdater.thread}.json",
onloadend: ThreadUpdater.cb.load onloadend: ThreadUpdater.cb.load
timeout: $.MINUTE
, ,
whenModified: true whenModified: true
@ -344,7 +345,7 @@ ThreadUpdater =
$.event 'ThreadUpdate', $.event 'ThreadUpdate',
404: false 404: false
threadID: ThreadUpdater.thread.fullID threadID: ThreadUpdater.thread.fullID
newPosts: posts.map (post) -> post.fullID newPosts: (post.fullID for post in posts)
postCount: OP.replies + 1 postCount: OP.replies + 1
fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead) fileCount: OP.images + (!!ThreadUpdater.thread.OP.file and !ThreadUpdater.thread.OP.file.isDead)
ipCount: OP.unique_ips ipCount: OP.unique_ips

View File

@ -14,7 +14,7 @@ ThreadWatcher =
@status = $ '#watcher-status', @dialog @status = $ '#watcher-status', @dialog
@list = @dialog.lastElementChild @list = @dialog.lastElementChild
@refreshButton = $ '.move > .refresh', @dialog @refreshButton = $ '.refresh', @dialog
@unreaddb = Unread.db or new DataBoard 'lastReadPosts' @unreaddb = Unread.db or new DataBoard 'lastReadPosts'
$.on d, 'QRPostSuccessful', @cb.post $.on d, 'QRPostSuccessful', @cb.post
@ -36,13 +36,6 @@ ThreadWatcher =
ThreadWatcher.fetchAuto() 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' if g.VIEW is 'index' and Conf['JSON Navigation'] and Conf['Menu'] and g.BOARD.ID isnt 'f'
Menu.menu.addEntry Menu.menu.addEntry
el: $.el 'a', href: 'javascript:;' el: $.el 'a', href: 'javascript:;'
@ -60,6 +53,13 @@ ThreadWatcher =
$.on @el, 'click', @cb $.on @el, 'click', @cb
true true
Post.callbacks.push
name: 'Thread Watcher'
cb: @node
CatalogThread.callbacks.push
name: 'Thread Watcher'
cb: @catalogNode
isWatched: (thread) -> isWatched: (thread) ->
ThreadWatcher.db?.get {boardID: thread.board.ID, threadID: thread.ID} ThreadWatcher.db?.get {boardID: thread.board.ID, threadID: thread.ID}

View File

@ -1,20 +1,21 @@
Unread = Unread =
init: -> init: ->
return if g.VIEW isnt 'thread' or return unless g.VIEW is 'thread' and (
!Conf['Unread Count'] and Conf['Unread Count'] or
!Conf['Unread Favicon'] and Conf['Unread Favicon'] or
!Conf['Unread Line'] and Conf['Unread Line'] or
!Conf['Scroll to Last Read Post'] and Conf['Scroll to Last Read Post'] or
!Conf['Thread Watcher'] and Conf['Thread Watcher'] or
!Conf['Desktop Notifications'] and Conf['Desktop Notifications'] or
!Conf['Quote Threading'] Conf['Quote Threading']
)
@db = new DataBoard 'lastReadPosts', @sync @db = new DataBoard 'lastReadPosts', @sync
@hr = $.el 'hr', @hr = $.el 'hr',
id: 'unread-line' id: 'unread-line'
@posts = new Set @posts = new Set()
@postsQuotingYou = new Set @postsQuotingYou = new Set()
@order = new RandomAccessList @order = new RandomAccessList()
@position = null @position = null
Thread.callbacks.push Thread.callbacks.push
@ -182,6 +183,7 @@ Unread =
updatePosition: -> updatePosition: ->
while Unread.position and !Unread.posts.has Unread.position.ID while Unread.position and !Unread.posts.has Unread.position.ID
Unread.position = Unread.position.next Unread.position = Unread.position.next
return
saveLastReadPost: $.debounce 2 * $.SECOND, -> saveLastReadPost: $.debounce 2 * $.SECOND, ->
postIDs = Unread.thread.posts.keys postIDs = Unread.thread.posts.keys