Sync unread status between tabs/devices.
This commit is contained in:
parent
53ab332406
commit
c0ba3246ce
@ -3615,15 +3615,18 @@ Unread =
|
|||||||
Unread.hr = $.el 'hr',
|
Unread.hr = $.el 'hr',
|
||||||
id: 'unread-line'
|
id: 'unread-line'
|
||||||
Misc.clearThreads "lastReadPosts.#{g.BOARD}"
|
Misc.clearThreads "lastReadPosts.#{g.BOARD}"
|
||||||
|
$.sync "lastReadPosts.#{g.BOARD}", @sync
|
||||||
|
|
||||||
|
Unread.posts = []
|
||||||
|
Unread.postsQuotingYou = []
|
||||||
|
|
||||||
Thread::callbacks.push
|
Thread::callbacks.push
|
||||||
name: 'Unread'
|
name: 'Unread'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
Unread.thread = @
|
Unread.thread = @
|
||||||
Unread.posts = []
|
Unread.title = d.title
|
||||||
Unread.postsQuotingYou = []
|
|
||||||
Unread.title = d.title
|
|
||||||
posts = []
|
posts = []
|
||||||
for ID, post of @posts
|
for ID, post of @posts
|
||||||
posts.push post if post.isReply
|
posts.push post if post.isReply
|
||||||
@ -3640,6 +3643,14 @@ Unread =
|
|||||||
$.on d, 'scroll visibilitychange', Unread.read
|
$.on d, 'scroll visibilitychange', Unread.read
|
||||||
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line']
|
$.on d, 'visibilitychange', Unread.setLine if Conf['Unread Line']
|
||||||
|
|
||||||
|
sync: (lastReadPosts) ->
|
||||||
|
return unless (lastReadPost = lastReadPosts?.threads?[Unread.thread]) and Unread.lastReadPost < lastReadPost
|
||||||
|
Unread.lastReadPost = lastReadPost
|
||||||
|
Unread.readArray Unread.posts
|
||||||
|
Unread.readArray Unread.postsQuotingYou
|
||||||
|
Unread.setLine()
|
||||||
|
Unread.update()
|
||||||
|
|
||||||
addPosts: (newPosts) ->
|
addPosts: (newPosts) ->
|
||||||
if Conf['Quick Reply']
|
if Conf['Quick Reply']
|
||||||
{yourPosts} = QR
|
{yourPosts} = QR
|
||||||
@ -3671,6 +3682,11 @@ Unread =
|
|||||||
else
|
else
|
||||||
Unread.addPosts e.detail.newPosts
|
Unread.addPosts e.detail.newPosts
|
||||||
|
|
||||||
|
readArray: (arr) ->
|
||||||
|
for post, i in arr
|
||||||
|
break if post.ID > Unread.lastReadPost
|
||||||
|
arr.splice 0, i
|
||||||
|
|
||||||
read: (e) ->
|
read: (e) ->
|
||||||
return if d.hidden or !Unread.posts.length
|
return if d.hidden or !Unread.posts.length
|
||||||
height = doc.clientHeight
|
height = doc.clientHeight
|
||||||
@ -3681,13 +3697,11 @@ Unread =
|
|||||||
|
|
||||||
Unread.lastReadPost = Unread.posts[i - 1].ID
|
Unread.lastReadPost = Unread.posts[i - 1].ID
|
||||||
Unread.saveLastReadPost()
|
Unread.saveLastReadPost()
|
||||||
Unread.posts = Unread.posts[i..]
|
Unread.posts.splice 0, i
|
||||||
for post, i in Unread.postsQuotingYou
|
Unread.readArray Unread.postsQuotingYou
|
||||||
break if post.ID > Unread.lastReadPost
|
|
||||||
Unread.postsQuotingYou = Unread.postsQuotingYou[i..]
|
|
||||||
Unread.update() if e
|
Unread.update() if e
|
||||||
|
|
||||||
saveLastReadPost: $.debounce $.SECOND, ->
|
saveLastReadPost: $.debounce 2 * $.SECOND, ->
|
||||||
$.get "lastReadPosts.#{Unread.thread.board}", threads: {}, (item) ->
|
$.get "lastReadPosts.#{Unread.thread.board}", threads: {}, (item) ->
|
||||||
lastReadPosts = item["lastReadPosts.#{Unread.thread.board}"]
|
lastReadPosts = item["lastReadPosts.#{Unread.thread.board}"]
|
||||||
lastReadPosts.threads[Unread.thread] = Unread.lastReadPost
|
lastReadPosts.threads[Unread.thread] = Unread.lastReadPost
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user