Add optional link to mark threads read from index. #625

This commit is contained in:
ccd0 2018-10-17 05:57:37 -07:00
parent 8d727ed555
commit 8be6bd3898
8 changed files with 93 additions and 2 deletions

View File

@ -713,6 +713,7 @@ Index =
thread = new Thread ID, g.BOARD thread = new Thread ID, g.BOARD
newThreads.push thread newThreads.push thread
thread.json = threadData thread.json = threadData
thread.lastPost = if threadData.last_replies then threadData.last_replies[threadData.last_replies.length - 1].no else ID
threads.push thread threads.push thread
if ((OP = thread.OP) and not OP.isFetchedQuote) if ((OP = thread.OP) and not OP.isFetchedQuote)

View File

@ -16,7 +16,7 @@ ThreadWatcher =
@list = @dialog.lastElementChild @list = @dialog.lastElementChild
@refreshButton = $ '.refresh', @dialog @refreshButton = $ '.refresh', @dialog
@closeButton = $('.move > .close', @dialog) @closeButton = $('.move > .close', @dialog)
@unreaddb = Unread.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'] and Site.software is 'yotsuba'
$.on d, 'QRPostSuccessful', @cb.post $.on d, 'QRPostSuccessful', @cb.post

View File

@ -0,0 +1,69 @@
UnreadIndex =
hasUnread: {}
markReadLink: {}
init: ->
return unless g.VIEW is 'index' and Conf['Remember Last Read Post'] and Conf['Mark Read from Index']
@db = new DataBoard 'lastReadPosts', @sync
if Index.enabled
$.on d, 'IndexRefreshInternal',
@onIndexRefresh
else
Callbacks.Thread.push
name: 'Mark Read from Index'
cb: @node
Callbacks.Post.push
name: 'Mark Read from Index'
cb: @addPost
onIndexRefresh: ->
g.threads.forEach (thread) ->
UnreadIndex.addMarkReadLink thread
UnreadIndex.update thread
node: ->
UnreadIndex.addMarkReadLink @
UnreadIndex.update @
addPost: ->
if @ID is @thread.lastPost
UnreadIndex.update @thread
sync: ->
g.threads.forEach UnreadIndex.update
addMarkReadLink: (thread) ->
return unless thread.nodes.root
link = UnreadIndex.markReadLink[thread.fullID]
unless link
link = UnreadIndex.markReadLink[thread.fullID] = $.el 'a',
className: 'unread-mark-read brackets-wrap'
href: 'javascript:;'
textContent: 'Mark Read'
$.on link, 'click', UnreadIndex.markRead
if link.parentNode isnt thread.nodes.root
$.add thread.nodes.root, link
update: (thread) ->
return unless thread.nodes.root
lastReadPost = UnreadIndex.db.get(
boardID: thread.board.ID
threadID: thread.ID
) or 0
hasUnread = (lastReadPost < thread.lastPost)
if hasUnread isnt UnreadIndex.hasUnread[thread.fullID]
thread.nodes.root.classList.toggle 'unread-thread', hasUnread
markRead: ->
thread = Get.threadFromNode @
UnreadIndex.db.set
boardID: thread.board.ID
threadID: thread.ID
val: thread.lastPost
UnreadIndex.update thread
ThreadWatcher.update thread.board.ID, thread.ID,
unread: 0
quotingYou: false

View File

@ -61,6 +61,7 @@ class Post
@board.posts.push @ID, @ @board.posts.push @ID, @
@thread.posts.push @ID, @ @thread.posts.push @ID, @
@thread.lastPost = @ID if @ID > @thread.lastPost
g.posts.push @fullID, @ g.posts.push @fullID, @
parseNodes: (root) -> parseNodes: (root) ->

View File

@ -13,12 +13,14 @@ class Thread
@fileLimit = false @fileLimit = false
@ipCount = undefined @ipCount = undefined
@json = null @json = null
@lastPost = 0
@OP = null @OP = null
@catalogView = null @catalogView = null
@nodes = @nodes =
root: null root: null
summary: null
@board.threads.push @ID, @ @board.threads.push @ID, @
g.threads.push @fullID, @ g.threads.push @fullID, @

View File

@ -383,6 +383,11 @@ Config =
'Scroll back to the last read post when reopening a thread.' 'Scroll back to the last read post when reopening a thread.'
1 1
] ]
'Mark Read from Index': [
false
'Add links in the index for marking threads read.'
1
]
'Remove Thread Excerpt': [ 'Remove Thread Excerpt': [
false false
'Replace the excerpt of the thread in the tab title with the board title.' 'Replace the excerpt of the thread in the tab title with the board title.'

View File

@ -1063,6 +1063,18 @@ span.hide-announcement {
margin: 0; margin: 0;
border-color: rgb(255,0,0); border-color: rgb(255,0,0);
} }
.unread-mark-read {
float: right;
clear: both;
height: 0;
width: 100%;
position: relative;
top: -1em;
text-align: right;
}
:not(.unread-thread) > .unread-mark-read {
visibility: hidden;
}
/* Thread Updater */ /* Thread Updater */
#updater { #updater {

View File

@ -510,6 +510,7 @@ Main =
['Thread Expansion', ExpandThread] ['Thread Expansion', ExpandThread]
['Favicon', Favicon] ['Favicon', Favicon]
['Unread', Unread] ['Unread', Unread]
['Mark Read from Index', UnreadIndex]
['Quote Threading', QuoteThreading] ['Quote Threading', QuoteThreading]
['Thread Stats', ThreadStats] ['Thread Stats', ThreadStats]
['Thread Updater', ThreadUpdater] ['Thread Updater', ThreadUpdater]