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: ->
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})"

View File

@ -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

View File

@ -12,7 +12,7 @@ ThreadUpdater =
@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>') %>
$.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

View File

@ -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}

View File

@ -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