Show threads from other sites in watcher.

This commit is contained in:
ccd0 2018-12-04 20:08:04 -08:00
parent 1fbe76e3cd
commit 2b59c9e380
3 changed files with 37 additions and 30 deletions

View File

@ -17,7 +17,7 @@ ThreadWatcher =
@refreshButton = $ '.refresh', @dialog @refreshButton = $ '.refresh', @dialog
@closeButton = $('.move > .close', @dialog) @closeButton = $('.move > .close', @dialog)
@unreaddb = Unread.db or UnreadIndex.db or new DataBoard 'lastReadPosts' @unreaddb = Unread.db or UnreadIndex.db or new DataBoard 'lastReadPosts'
@unreadEnabled = Conf['Remember Last Read Post'] and Site.software is 'yotsuba' @unreadEnabled = Conf['Remember Last Read Post']
$.on d, 'QRPostSuccessful', @cb.post $.on d, 'QRPostSuccessful', @cb.post
$.on sc, 'click', @toggleWatcher $.on sc, 'click', @toggleWatcher
@ -129,16 +129,17 @@ ThreadWatcher =
$.event 'CloseMenu' $.event 'CloseMenu'
pruneDeads: -> pruneDeads: ->
return if $.hasClass @, 'disabled' return if $.hasClass @, 'disabled'
for {boardID, threadID, data} in ThreadWatcher.getAll() when data.isDead for {siteID, boardID, threadID, data} in ThreadWatcher.getAll() when data.isDead
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {siteID, boardID, threadID}
ThreadWatcher.refresh() ThreadWatcher.refresh()
$.event 'CloseMenu' $.event 'CloseMenu'
toggle: -> toggle: ->
{thread} = Get.postFromNode @ {thread} = Get.postFromNode @
ThreadWatcher.toggle thread ThreadWatcher.toggle thread
rm: -> rm: ->
{siteID} = @parentNode.dataset
[boardID, threadID] = @parentNode.dataset.fullID.split '.' [boardID, threadID] = @parentNode.dataset.fullID.split '.'
ThreadWatcher.rm boardID, +threadID ThreadWatcher.rm siteID, boardID, +threadID
post: (e) -> post: (e) ->
{boardID, threadID, postID} = e.detail {boardID, threadID, postID} = e.detail
if postID is threadID if postID is threadID
@ -148,9 +149,10 @@ ThreadWatcher =
ThreadWatcher.add g.threads[boardID + '.' + threadID] ThreadWatcher.add g.threads[boardID + '.' + threadID]
onIndexUpdate: (e) -> onIndexUpdate: (e) ->
{db} = ThreadWatcher {db} = ThreadWatcher
siteID = Site.hostname
boardID = g.BOARD.ID boardID = g.BOARD.ID
nKilled = 0 nKilled = 0
for threadID, data of db.data[Site.hostname].boards[boardID] when not data?.isDead and "#{boardID}.#{threadID}" not in e.detail.threads for threadID, data of db.data[siteID].boards[boardID] when not data?.isDead and "#{boardID}.#{threadID}" not in e.detail.threads
# Don't prune threads that have yet to appear in index. # Don't prune threads that have yet to appear in index.
continue unless e.detail.threads.some (fullID) -> +fullID.split('.')[1] > threadID continue unless e.detail.threads.some (fullID) -> +fullID.split('.')[1] > threadID
nKilled++ nKilled++
@ -159,7 +161,7 @@ ThreadWatcher =
else else
db.extend {boardID, threadID, val: {isDead: true}} db.extend {boardID, threadID, val: {isDead: true}}
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
ThreadWatcher.fetchStatus {boardID, threadID, data} ThreadWatcher.fetchStatus {siteID, boardID, threadID, data}
ThreadWatcher.refresh() if nKilled ThreadWatcher.refresh() if nKilled
onThreadRefresh: (e) -> onThreadRefresh: (e) ->
thread = g.threads[e.detail.threadID] thread = g.threads[e.detail.threadID]
@ -212,8 +214,8 @@ ThreadWatcher =
return return
fetchStatus: (thread, force) -> fetchStatus: (thread, force) ->
return unless Site.software is 'yotsuba' {siteID, boardID, threadID, data} = thread
{boardID, threadID, data} = thread return unless Site.software is 'yotsuba' and siteID is Site.hostname
return if data.isDead and not force return if data.isDead and not force
if ThreadWatcher.requests.length is 0 if ThreadWatcher.requests.length is 0
ThreadWatcher.status.textContent = '...' ThreadWatcher.status.textContent = '...'
@ -288,14 +290,15 @@ ThreadWatcher =
getAll: -> getAll: ->
all = [] all = []
for boardID, threads of ThreadWatcher.db.data[Site.hostname].boards for siteID, boards of ThreadWatcher.db.data
if Conf['Current Board'] and boardID isnt g.BOARD.ID for boardID, threads of boards.boards
if Conf['Current Board'] and (siteID isnt Site.hostname or boardID isnt g.BOARD.ID)
continue continue
for threadID, data of threads when data and typeof data is 'object' for threadID, data of threads when data and typeof data is 'object'
all.push {boardID, threadID, data} all.push {siteID, boardID, threadID, data}
all all
makeLine: (boardID, threadID, data) -> makeLine: (siteID, boardID, threadID, data) ->
x = $.el 'a', x = $.el 'a',
className: 'fa fa-times' className: 'fa fa-times'
href: 'javascript:;' href: 'javascript:;'
@ -305,7 +308,7 @@ ThreadWatcher =
excerpt or= "/#{boardID}/ - No.#{threadID}" excerpt or= "/#{boardID}/ - No.#{threadID}"
link = $.el 'a', link = $.el 'a',
href: Site.urls.thread({boardID, threadID}) href: SW[Site.swDict[siteID]].urls.thread({siteID, boardID, threadID})
title: excerpt title: excerpt
className: 'watcher-link' className: 'watcher-link'
@ -323,6 +326,7 @@ ThreadWatcher =
div = $.el 'div' div = $.el 'div'
fullID = "#{boardID}.#{threadID}" fullID = "#{boardID}.#{threadID}"
div.dataset.fullID = fullID div.dataset.fullID = fullID
div.dataset.siteID = siteID
$.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}" $.addClass div, 'current' if g.VIEW is 'thread' and fullID is "#{g.BOARD}.#{g.THREADID}"
$.addClass div, 'dead-thread' if data.isDead $.addClass div, 'dead-thread' if data.isDead
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
@ -334,11 +338,11 @@ ThreadWatcher =
build: -> build: ->
nodes = [] nodes = []
for {boardID, threadID, data} in ThreadWatcher.getAll() for {siteID, boardID, threadID, data} in ThreadWatcher.getAll()
# Add missing excerpt for threads added by Auto Watch # Add missing excerpt for threads added by Auto Watch
if not data.excerpt? and (thread = g.threads["#{boardID}.#{threadID}"]) if not data.excerpt? and siteID is Site.hostname and (thread = g.threads["#{boardID}.#{threadID}"])
ThreadWatcher.db.extend {boardID, threadID, val: {excerpt: Get.threadExcerpt thread}} ThreadWatcher.db.extend {boardID, threadID, val: {excerpt: Get.threadExcerpt thread}}
nodes.push ThreadWatcher.makeLine boardID, threadID, data nodes.push ThreadWatcher.makeLine siteID, boardID, threadID, data
{list} = ThreadWatcher {list} = ThreadWatcher
$.rmAll list $.rmAll list
$.add list, nodes $.add list, nodes
@ -368,6 +372,7 @@ ThreadWatcher =
return return
update: (boardID, threadID, newData) -> update: (boardID, threadID, newData) ->
siteID = Site.hostname
return if not (data = ThreadWatcher.db?.get {boardID, threadID}) return if not (data = ThreadWatcher.db?.get {boardID, threadID})
if newData.isDead and Conf['Auto Prune'] if newData.isDead and Conf['Auto Prune']
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {boardID, threadID}
@ -378,8 +383,8 @@ ThreadWatcher =
return unless n return unless n
return if not (data = ThreadWatcher.db.get {boardID, threadID}) return if not (data = ThreadWatcher.db.get {boardID, threadID})
ThreadWatcher.db.extend {boardID, threadID, val: newData} ThreadWatcher.db.extend {boardID, threadID, val: newData}
if line = $ "#watched-threads > [data-full-i-d='#{boardID}.#{threadID}']", ThreadWatcher.dialog if line = $ "#watched-threads > [data-site-i-d='#{siteID}'][data-full-i-d='#{boardID}.#{threadID}']", ThreadWatcher.dialog
newLine = ThreadWatcher.makeLine boardID, threadID, data newLine = ThreadWatcher.makeLine siteID, boardID, threadID, data
$.replace line, newLine $.replace line, newLine
ThreadWatcher.refreshIcon() ThreadWatcher.refreshIcon()
else else
@ -394,20 +399,22 @@ ThreadWatcher =
ThreadWatcher.db.extend {boardID, threadID, val: {isDead: true}, rm: ['unread', 'quotingYou']}, cb ThreadWatcher.db.extend {boardID, threadID, val: {isDead: true}, rm: ['unread', 'quotingYou']}, cb
toggle: (thread) -> toggle: (thread) ->
siteID = Site.hostname
boardID = thread.board.ID boardID = thread.board.ID
threadID = thread.ID threadID = thread.ID
if ThreadWatcher.db.get {boardID, threadID} if ThreadWatcher.db.get {boardID, threadID}
ThreadWatcher.rm boardID, threadID ThreadWatcher.rm siteID, boardID, threadID
else else
ThreadWatcher.add thread ThreadWatcher.add thread
add: (thread) -> add: (thread) ->
data = {} data = {}
siteID = Site.hostname
boardID = thread.board.ID boardID = thread.board.ID
threadID = thread.ID threadID = thread.ID
if thread.isDead if thread.isDead
if Conf['Auto Prune'] and ThreadWatcher.db.get {boardID, threadID} if Conf['Auto Prune'] and ThreadWatcher.db.get {boardID, threadID}
ThreadWatcher.rm boardID, threadID ThreadWatcher.rm siteID, boardID, threadID
return return
data.isDead = true data.isDead = true
data.excerpt = Get.threadExcerpt thread data.excerpt = Get.threadExcerpt thread
@ -417,10 +424,10 @@ ThreadWatcher =
ThreadWatcher.db.set {boardID, threadID, val: data} ThreadWatcher.db.set {boardID, threadID, val: data}
ThreadWatcher.refresh() ThreadWatcher.refresh()
if ThreadWatcher.unreadEnabled and Conf['Show Unread Count'] if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
ThreadWatcher.fetchStatus {boardID, threadID, data}, true ThreadWatcher.fetchStatus {siteID: Site.hostname, boardID, threadID, data}, true
rm: (boardID, threadID) -> rm: (siteID, boardID, threadID) ->
ThreadWatcher.db.delete {boardID, threadID} ThreadWatcher.db.delete {siteID, boardID, threadID}
ThreadWatcher.refresh() ThreadWatcher.refresh()
menu: menu:

View File

@ -48,7 +48,7 @@ SW.tinyboard =
false false
urls: urls:
thread: ({boardID, threadID}) -> "#{location.origin}/#{boardID}/res/#{threadID}.html" thread: ({siteID, boardID, threadID}) -> "#{if siteID is Site.hostname then location.origin else ('http://' + siteID)}/#{boardID}/res/#{threadID}.html"
selectors: selectors:
board: 'form[name="postcontrols"]' board: 'form[name="postcontrols"]'

View File

@ -1,15 +1,15 @@
Site = Site =
init: (cb) -> init: (cb) ->
swDict = {} @swDict = {}
for line in Conf['siteSoftware'].split('\n') when line[0] isnt '#' for line in Conf['siteSoftware'].split('\n') when line[0] isnt '#'
[hostname, software] = line.split(' ') [hostname, software] = line.split(' ')
swDict[hostname] = software if software of SW @swDict[hostname] = software if software of SW
{hostname} = location {hostname} = location
while hostname and hostname not of swDict while hostname and hostname not of @swDict
hostname = hostname.replace(/^[^.]*\.?/, '') hostname = hostname.replace(/^[^.]*\.?/, '')
hostname = '4chan.org' if hostname is '4channel.org' hostname = '4chan.org' if hostname is '4channel.org'
if hostname if hostname
@set hostname, swDict[hostname] @set hostname, @swDict[hostname]
cb() cb()
else else
$.onExists doc, 'body', => $.onExists doc, 'body', =>