Fix Tinyboard/vichan post form redirecting before your posts can be recorded as yours. #2171
This commit is contained in:
parent
d77bacd6e0
commit
a6ab951170
@ -11,6 +11,12 @@ Tinyboard =
|
||||
return unless settings.url is form.action
|
||||
return unless (postID = +request.responseJSON?.id)
|
||||
detail = {boardID, threadID, postID}
|
||||
try
|
||||
{redirect, noko} = request.responseJSON
|
||||
if redirect and originalNoko? and !originalNoko and !noko
|
||||
detail.redirect = redirect
|
||||
event = new CustomEvent 'QRPostSuccessful', {bubbles: true, detail: detail}
|
||||
document.dispatchEvent event
|
||||
originalNoko = window.tb_settings?.ajax?.always_noko_replies
|
||||
((window.tb_settings or= {}).ajax or= {}).always_noko_replies = true
|
||||
, {boardID: g.BOARD.ID, threadID: g.THREADID}
|
||||
|
||||
@ -141,11 +141,12 @@ ThreadWatcher =
|
||||
ThreadWatcher.rm siteID, boardID, +threadID
|
||||
post: (e) ->
|
||||
{boardID, threadID, postID} = e.detail
|
||||
cb = PostRedirect.delay()
|
||||
if postID is threadID
|
||||
if Conf['Auto Watch']
|
||||
ThreadWatcher.addRaw boardID, threadID, {}
|
||||
ThreadWatcher.addRaw boardID, threadID, {}, cb
|
||||
else if Conf['Auto Watch Reply']
|
||||
ThreadWatcher.add g.threads[boardID + '.' + threadID] or new Thread(threadID, g.boards[boardID] or new Board(boardID))
|
||||
ThreadWatcher.add (g.threads[boardID + '.' + threadID] or new Thread(threadID, g.boards[boardID] or new Board(boardID))), cb
|
||||
onIndexUpdate: (e) ->
|
||||
{db} = ThreadWatcher
|
||||
siteID = g.SITE.ID
|
||||
@ -528,21 +529,21 @@ ThreadWatcher =
|
||||
else
|
||||
ThreadWatcher.add thread
|
||||
|
||||
add: (thread) ->
|
||||
add: (thread, cb) ->
|
||||
data = {}
|
||||
siteID = g.SITE.ID
|
||||
boardID = thread.board.ID
|
||||
threadID = thread.ID
|
||||
if thread.isDead
|
||||
if Conf['Auto Prune'] and ThreadWatcher.db.get {boardID, threadID}
|
||||
ThreadWatcher.rm siteID, boardID, threadID
|
||||
ThreadWatcher.rm siteID, boardID, threadID, cb
|
||||
return
|
||||
data.isDead = true
|
||||
data.excerpt = Get.threadExcerpt thread if thread.OP
|
||||
ThreadWatcher.addRaw boardID, threadID, data
|
||||
ThreadWatcher.addRaw boardID, threadID, data, cb
|
||||
|
||||
addRaw: (boardID, threadID, data) ->
|
||||
ThreadWatcher.db.set {boardID, threadID, val: data}
|
||||
addRaw: (boardID, threadID, data, cb) ->
|
||||
ThreadWatcher.db.set {boardID, threadID, val: data}, cb
|
||||
ThreadWatcher.refresh()
|
||||
thread = {siteID: g.SITE.ID, boardID, threadID, data, force: true}
|
||||
if Conf['Show Page'] and !data.isDead
|
||||
@ -550,8 +551,8 @@ ThreadWatcher =
|
||||
else if ThreadWatcher.unreadEnabled and Conf['Show Unread Count']
|
||||
ThreadWatcher.fetchStatus thread
|
||||
|
||||
rm: (siteID, boardID, threadID) ->
|
||||
ThreadWatcher.db.delete {siteID, boardID, threadID}
|
||||
rm: (siteID, boardID, threadID, cb) ->
|
||||
ThreadWatcher.db.delete {siteID, boardID, threadID}, cb
|
||||
ThreadWatcher.refresh()
|
||||
|
||||
menu:
|
||||
|
||||
21
src/Posting/PostRedirect.coffee
Normal file
21
src/Posting/PostRedirect.coffee
Normal file
@ -0,0 +1,21 @@
|
||||
PostRedirect =
|
||||
init: ->
|
||||
$.on d, 'QRPostSuccessful', (e) =>
|
||||
return unless e.detail.redirect
|
||||
@event = e
|
||||
@delays = 0
|
||||
$.queueTask =>
|
||||
if e is @event and @delays is 0
|
||||
location.href = e.detail.redirect
|
||||
|
||||
delays: 0
|
||||
|
||||
delay: ->
|
||||
return null unless @event
|
||||
e = @event
|
||||
@delays++
|
||||
() =>
|
||||
return unless e is @event
|
||||
@delays--
|
||||
if @delays is 0
|
||||
location.href = e.detail.redirect
|
||||
@ -5,10 +5,11 @@ QuoteYou =
|
||||
@db = new DataBoard 'yourPosts'
|
||||
$.sync 'Remember Your Posts', (enabled) -> Conf['Remember Your Posts'] = enabled
|
||||
$.on d, 'QRPostSuccessful', (e) ->
|
||||
cb = PostRedirect.delay()
|
||||
$.get 'Remember Your Posts', Conf['Remember Your Posts'], (items) ->
|
||||
return unless items['Remember Your Posts']
|
||||
{boardID, threadID, postID} = e.detail
|
||||
(QuoteYou.db.set {boardID, threadID, postID, val: true})
|
||||
QuoteYou.db.set {boardID, threadID, postID, val: true}, cb
|
||||
|
||||
return unless g.VIEW in ['index', 'thread', 'archive']
|
||||
|
||||
|
||||
@ -46,7 +46,7 @@ class DataBoard
|
||||
@sync?()
|
||||
cb?()
|
||||
|
||||
delete: ({siteID, boardID, threadID, postID}) ->
|
||||
delete: ({siteID, boardID, threadID, postID}, cb) ->
|
||||
siteID or= g.SITE.ID
|
||||
return unless @data[siteID]
|
||||
@save =>
|
||||
@ -60,6 +60,7 @@ class DataBoard
|
||||
@deleteIfEmpty {siteID, boardID}
|
||||
else
|
||||
delete @data[siteID].boards[boardID]
|
||||
, cb
|
||||
|
||||
deleteIfEmpty: ({siteID, boardID, threadID}) ->
|
||||
return unless @data[siteID]
|
||||
|
||||
@ -536,6 +536,7 @@ Main =
|
||||
['Polyfill', Polyfill]
|
||||
['Board Configuration', BoardConfig]
|
||||
['Normalize URL', NormalizeURL]
|
||||
['Delay Redirect on Post', PostRedirect]
|
||||
['Captcha Configuration', Captcha.replace]
|
||||
['Image Host Rewriting', ImageHost]
|
||||
['Redirect', Redirect]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user