Permalink
Browse files

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

  • Loading branch information...
ccd0 committed Oct 17, 2018
1 parent 8d727ed commit 8be6bd38981ee0cba37bd1e4bd5b6186d60b9fc3
View
@@ -713,6 +713,7 @@ Index =
thread = new Thread ID, g.BOARD
newThreads.push thread
thread.json = threadData
thread.lastPost = if threadData.last_replies then threadData.last_replies[threadData.last_replies.length - 1].no else ID
threads.push thread
if ((OP = thread.OP) and not OP.isFetchedQuote)
@@ -16,7 +16,7 @@ ThreadWatcher =
@list = @dialog.lastElementChild
@refreshButton = $ '.refresh', @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'
$.on d, 'QRPostSuccessful', @cb.post
@@ -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
@@ -61,6 +61,7 @@ class Post
@board.posts.push @ID, @
@thread.posts.push @ID, @
@thread.lastPost = @ID if @ID > @thread.lastPost
g.posts.push @fullID, @
parseNodes: (root) ->
@@ -13,12 +13,14 @@ class Thread
@fileLimit = false
@ipCount = undefined
@json = null
@lastPost = 0
@OP = null
@catalogView = null
@nodes =
root: null
root: null
summary: null
@board.threads.push @ID, @
g.threads.push @fullID, @
View
@@ -383,6 +383,11 @@ Config =
'Scroll back to the last read post when reopening a thread.'
1
]
'Mark Read from Index': [
false
'Add links in the index for marking threads read.'
1
]
'Remove Thread Excerpt': [
false
'Replace the excerpt of the thread in the tab title with the board title.'
View
@@ -1063,6 +1063,18 @@ span.hide-announcement {
margin: 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 */
#updater {
View
@@ -510,6 +510,7 @@ Main =
['Thread Expansion', ExpandThread]
['Favicon', Favicon]
['Unread', Unread]
['Mark Read from Index', UnreadIndex]
['Quote Threading', QuoteThreading]
['Thread Stats', ThreadStats]
['Thread Updater', ThreadUpdater]

0 comments on commit 8be6bd3

Please sign in to comment.