Refactor adding of unread posts.
This commit is contained in:
parent
370d73d183
commit
b618b760b8
@ -18,6 +18,9 @@ Unread =
|
|||||||
Thread.callbacks.push
|
Thread.callbacks.push
|
||||||
name: 'Unread'
|
name: 'Unread'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
Post.callbacks.push
|
||||||
|
name: 'Unread'
|
||||||
|
cb: @addPost
|
||||||
|
|
||||||
readCount: 0
|
readCount: 0
|
||||||
|
|
||||||
@ -36,11 +39,12 @@ Unread =
|
|||||||
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] and not Conf['Quote Threading']
|
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line'] and not Conf['Quote Threading']
|
||||||
|
|
||||||
ready: ->
|
ready: ->
|
||||||
unless Conf['Quote Threading']
|
if Conf['Quote Threading']
|
||||||
posts = []
|
QuoteThreading.force()
|
||||||
Unread.thread.posts.forEach (post) -> posts.push post if post.isReply
|
else
|
||||||
Unread.addPosts posts
|
Unread.setLine true if Conf['Unread Line']
|
||||||
QuoteThreading.force() if Conf['Quote Threading']
|
Unread.read()
|
||||||
|
Unread.update()
|
||||||
Unread.scroll() if Conf['Scroll to Last Read Post'] and not Conf['Quote Threading']
|
Unread.scroll() if Conf['Scroll to Last Read Post'] and not Conf['Quote Threading']
|
||||||
|
|
||||||
scroll: ->
|
scroll: ->
|
||||||
@ -76,24 +80,14 @@ Unread =
|
|||||||
Unread.setLine() if Conf['Unread Line'] and not Conf['Quote Threading']
|
Unread.setLine() if Conf['Unread Line'] and not Conf['Quote Threading']
|
||||||
Unread.update()
|
Unread.update()
|
||||||
|
|
||||||
addPost: (post) ->
|
addPost: ->
|
||||||
return if post.ID <= Unread.lastReadPost or post.isHidden or QR.db?.get {
|
return if @isClone or @ID <= Unread.lastReadPost or !@isReply or @isHidden or QR.db?.get {
|
||||||
boardID: post.board.ID
|
boardID: @board.ID
|
||||||
threadID: post.thread.ID
|
threadID: @thread.ID
|
||||||
postID: post.ID
|
postID: @ID
|
||||||
}
|
}
|
||||||
Unread.posts.push post
|
Unread.posts.push @
|
||||||
Unread.addPostQuotingYou post
|
Unread.addPostQuotingYou @
|
||||||
|
|
||||||
addPosts: (posts) ->
|
|
||||||
oldCount = Unread.posts.length
|
|
||||||
for post in posts
|
|
||||||
Unread.addPost post
|
|
||||||
if Conf['Unread Line'] and not Conf['Quote Threading']
|
|
||||||
# Force line on visible threads if there were no unread posts previously.
|
|
||||||
Unread.setLine (oldCount is 0 and Unread.posts.length isnt 0)
|
|
||||||
Unread.read()
|
|
||||||
Unread.update()
|
|
||||||
|
|
||||||
addPostQuotingYou: (post) ->
|
addPostQuotingYou: (post) ->
|
||||||
for quotelink in post.nodes.quotelinks when QR.db?.get Get.postDataFromLink quotelink
|
for quotelink in post.nodes.quotelinks when QR.db?.get Get.postDataFromLink quotelink
|
||||||
@ -115,13 +109,11 @@ Unread =
|
|||||||
, 7 * $.SECOND
|
, 7 * $.SECOND
|
||||||
|
|
||||||
onUpdate: (e) ->
|
onUpdate: (e) ->
|
||||||
if e.detail[404]
|
if !e.detail[404]
|
||||||
Unread.update()
|
# Force line on visible threads if there were no unread posts previously.
|
||||||
else if !QuoteThreading.enabled
|
Unread.setLine(!Unread.hr.parentNode) if Conf['Unread Line'] and not Conf['Quote Threading']
|
||||||
Unread.addPosts(g.posts[fullID] for fullID in e.detail.newPosts)
|
|
||||||
else
|
|
||||||
Unread.read()
|
Unread.read()
|
||||||
Unread.update()
|
Unread.update()
|
||||||
|
|
||||||
readSinglePost: (post) ->
|
readSinglePost: (post) ->
|
||||||
{ID} = post
|
{ID} = post
|
||||||
|
|||||||
@ -29,10 +29,7 @@ QuoteThreading =
|
|||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
{posts} = g
|
{posts} = g
|
||||||
return if @isClone or not QuoteThreading.enabled
|
return if @isClone or not QuoteThreading.enabled or !@isReply or @isHidden
|
||||||
|
|
||||||
Unread.addPost @
|
|
||||||
return if @thread.OP is @ or @isHidden # Filtered
|
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
len = g.BOARD.ID.length + 1
|
len = g.BOARD.ID.length + 1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user