Abort QR upload on thread death. Some QR notifications work.

This commit is contained in:
Nicolas Stepien 2013-02-14 22:16:18 +01:00
parent 7bdeabedd8
commit c746f9b7e6
3 changed files with 61 additions and 33 deletions

View File

@ -3907,17 +3907,20 @@
req = ThreadUpdater.req; req = ThreadUpdater.req;
switch (req.status) { switch (req.status) {
case 200: case 200:
g.DEAD = false;
ThreadUpdater.parse(JSON.parse(req.response).posts); ThreadUpdater.parse(JSON.parse(req.response).posts);
ThreadUpdater.lastModified = req.getResponseHeader('Last-Modified'); ThreadUpdater.lastModified = req.getResponseHeader('Last-Modified');
ThreadUpdater.set('timer', ThreadUpdater.getInterval()); ThreadUpdater.set('timer', ThreadUpdater.getInterval());
break; break;
case 404: case 404:
g.DEAD = true;
ThreadUpdater.set('timer', null); ThreadUpdater.set('timer', null);
ThreadUpdater.set('status', '404', 'warning'); ThreadUpdater.set('status', '404', 'warning');
clearTimeout(ThreadUpdater.timeoutID); clearTimeout(ThreadUpdater.timeoutID);
ThreadUpdater.thread.kill(); ThreadUpdater.thread.kill();
$.event('ThreadUpdate', { $.event('ThreadUpdate', {
404: true 404: true,
thread: ThreadUpdater.thread
}); });
break; break;
default: default:
@ -4052,6 +4055,7 @@
} }
return $.event('ThreadUpdate', { return $.event('ThreadUpdate', {
404: false, 404: false,
thread: ThreadUpdater.thread,
newPosts: posts, newPosts: posts,
deletedPosts: deletedPosts, deletedPosts: deletedPosts,
deletedFiles: deletedFiles deletedFiles: deletedFiles
@ -4104,6 +4108,13 @@
return QR.hide(); return QR.hide();
} }
}); });
$.on(d, 'ThreadUpdate', function() {
if (g.DEAD) {
return QR.abort();
} else {
return QR.status();
}
});
return Post.prototype.callbacks.push({ return Post.prototype.callbacks.push({
name: 'Quick Reply', name: 'Quick Reply',
cb: this.node cb: this.node
@ -4145,7 +4156,7 @@
if (!Conf['Remember Spoiler'] && (spoiler = $.id('spoiler')).checked) { if (!Conf['Remember Spoiler'] && (spoiler = $.id('spoiler')).checked) {
spoiler.click(); spoiler.click();
} }
return QR.cleanNotification(); return QR.cleanNotifications();
}, },
hide: function() { hide: function() {
d.activeElement.blur(); d.activeElement.blur();
@ -4178,14 +4189,17 @@
if (d.hidden) { if (d.hidden) {
alert(el.textContent); alert(el.textContent);
} }
return QR.lastNotification = new Notification('warning', el); return QR.lastNotifications.push(new Notification('warning', el));
}, },
cleanNotification: function() { lastNotifications: [],
var _ref; cleanNotifications: function() {
if ((_ref = QR.lastNotification) != null) { var notification, _i, _len, _ref;
_ref.close(); _ref = QR.lastNotifications;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
notification = _ref[_i];
notification.close();
} }
return delete QR.lastNotification; return QR.lastNotification = [];
}, },
status: function(data) { status: function(data) {
var disabled, input, value; var disabled, input, value;
@ -4377,7 +4391,7 @@
}, },
fileInput: function() { fileInput: function() {
var file, _i, _len, _ref; var file, _i, _len, _ref;
QR.cleanNotification(); QR.cleanNotifications();
if (this.files.length === 1) { if (this.files.length === 1) {
file = this.files[0]; file = this.files[0];
if (file.size > this.max) { if (file.size > this.max) {
@ -4395,11 +4409,9 @@
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
file = _ref[_i]; file = _ref[_i];
if (file.size > this.max) { if (file.size > this.max) {
QR.error("File " + file.name + " is too large."); QR.error("File " + file.name + " is too large (" + ($.bytesToString(file.size)) + ").");
break;
} else if (-1 === QR.mimeTypes.indexOf(file.type)) { } else if (-1 === QR.mimeTypes.indexOf(file.type)) {
QR.error("" + file.name + ": Unsupported file type."); QR.error("" + file.name + ": Unsupported file type.");
break;
} }
if (!QR.replies[QR.replies.length - 1].file) { if (!QR.replies[QR.replies.length - 1].file) {
QR.replies[QR.replies.length - 1].setFile(file); QR.replies[QR.replies.length - 1].setFile(file);
@ -4868,7 +4880,7 @@
QR.error(err); QR.error(err);
return; return;
} }
QR.cleanNotification(); QR.cleanNotifications();
QR.cooldown.auto = QR.replies.length > 1; QR.cooldown.auto = QR.replies.length > 1;
if (Conf['Auto Hide QR'] && !QR.cooldown.auto) { if (Conf['Auto Hide QR'] && !QR.cooldown.auto) {
QR.hide(); QR.hide();
@ -4927,6 +4939,7 @@
}, },
response: function(html) { response: function(html) {
var ban, board, err, h1, persona, postID, reply, threadID, tmpDoc, _, _ref, _ref1; var ban, board, err, h1, persona, postID, reply, threadID, tmpDoc, _, _ref, _ref1;
delete QR.ajax;
tmpDoc = d.implementation.createHTMLDocument(''); tmpDoc = d.implementation.createHTMLDocument('');
tmpDoc.documentElement.innerHTML = html; tmpDoc.documentElement.innerHTML = html;
if (ban = $('.banType', tmpDoc)) { if (ban = $('.banType', tmpDoc)) {
@ -4958,7 +4971,8 @@
return; return;
} }
h1 = $('h1', tmpDoc); h1 = $('h1', tmpDoc);
QR.lastNotification = new Notification('success', h1.textContent, 5); QR.cleanNotifications();
QR.lastNotifications.push(new Notification('success', h1.textContent, 5));
reply = QR.replies[0]; reply = QR.replies[0];
persona = $.get('QR.persona', {}); persona = $.get('QR.persona', {});
persona = { persona = {
@ -4991,11 +5005,11 @@
return QR.resetFileInput(); return QR.resetFileInput();
}, },
abort: function() { abort: function() {
var _ref; if (QR.ajax) {
if ((_ref = QR.ajax) != null) { QR.ajax.abort();
_ref.abort(); delete QR.ajax;
QR.error('QR upload aborted.');
} }
delete QR.ajax;
return QR.status(); return QR.status();
} }
}; };

View File

@ -2410,21 +2410,24 @@ ThreadUpdater =
{req} = ThreadUpdater {req} = ThreadUpdater
switch req.status switch req.status
when 200 when 200
g.DEAD = false
ThreadUpdater.parse JSON.parse(req.response).posts ThreadUpdater.parse JSON.parse(req.response).posts
ThreadUpdater.lastModified = req.getResponseHeader 'Last-Modified' ThreadUpdater.lastModified = req.getResponseHeader 'Last-Modified'
ThreadUpdater.set 'timer', ThreadUpdater.getInterval() ThreadUpdater.set 'timer', ThreadUpdater.getInterval()
when 404 when 404
g.DEAD = true
ThreadUpdater.set 'timer', null ThreadUpdater.set 'timer', null
ThreadUpdater.set 'status', '404', 'warning' ThreadUpdater.set 'status', '404', 'warning'
clearTimeout ThreadUpdater.timeoutID clearTimeout ThreadUpdater.timeoutID
ThreadUpdater.thread.kill() ThreadUpdater.thread.kill()
$.event 'ThreadUpdate', 404: true $.event 'ThreadUpdate',
404: true
thread: ThreadUpdater.thread
# if Conf['Unread Count'] # if Conf['Unread Count']
# Unread.title = Unread.title.match(/^.+-/)[0] + ' 404' # Unread.title = Unread.title.match(/^.+-/)[0] + ' 404'
# else # else
# d.title = d.title.match(/^.+-/)[0] + ' 404' # d.title = d.title.match(/^.+-/)[0] + ' 404'
# Unread.update true # Unread.update true
# QR.abort()
else else
ThreadUpdater.outdateCount++ ThreadUpdater.outdateCount++
ThreadUpdater.set 'timer', ThreadUpdater.getInterval() ThreadUpdater.set 'timer', ThreadUpdater.getInterval()
@ -2536,6 +2539,7 @@ ThreadUpdater =
$.event 'ThreadUpdate', $.event 'ThreadUpdate',
404: false 404: false
thread: ThreadUpdater.thread
newPosts: posts newPosts: posts
deletedPosts: deletedPosts deletedPosts: deletedPosts
deletedFiles: deletedFiles deletedFiles: deletedFiles

View File

@ -32,6 +32,11 @@ QR =
return unless Conf['Persistent QR'] return unless Conf['Persistent QR']
QR.open() QR.open()
QR.hide() if Conf['Auto Hide QR'] QR.hide() if Conf['Auto Hide QR']
$.on d, 'ThreadUpdate', ->
if g.DEAD
QR.abort()
else
QR.status()
Post::callbacks.push Post::callbacks.push
name: 'Quick Reply' name: 'Quick Reply'
@ -64,7 +69,7 @@ QR =
QR.resetFileInput() QR.resetFileInput()
if not Conf['Remember Spoiler'] and (spoiler = $.id 'spoiler').checked if not Conf['Remember Spoiler'] and (spoiler = $.id 'spoiler').checked
spoiler.click() spoiler.click()
QR.cleanNotification() QR.cleanNotifications()
hide: -> hide: ->
d.activeElement.blur() d.activeElement.blur()
$.addClass QR.el, 'autohide' $.addClass QR.el, 'autohide'
@ -89,10 +94,12 @@ QR =
# Focus the captcha input on captcha error. # Focus the captcha input on captcha error.
$('[autocomplete]', QR.el).focus() $('[autocomplete]', QR.el).focus()
alert el.textContent if d.hidden alert el.textContent if d.hidden
QR.lastNotification = new Notification 'warning', el QR.lastNotifications.push new Notification 'warning', el
cleanNotification: -> lastNotifications: []
QR.lastNotification?.close() cleanNotifications: ->
delete QR.lastNotification for notification in QR.lastNotifications
notification.close()
QR.lastNotification = []
status: (data={}) -> status: (data={}) ->
return unless QR.el return unless QR.el
@ -278,7 +285,7 @@ QR =
QR.fileInput.call e.dataTransfer QR.fileInput.call e.dataTransfer
$.addClass QR.el, 'dump' $.addClass QR.el, 'dump'
fileInput: -> fileInput: ->
QR.cleanNotification() QR.cleanNotifications()
# Set or change current reply's file. # Set or change current reply's file.
if @files.length is 1 if @files.length is 1
file = @files[0] file = @files[0]
@ -294,11 +301,9 @@ QR =
# Create new replies with these files. # Create new replies with these files.
for file in @files for file in @files
if file.size > @max if file.size > @max
QR.error "File #{file.name} is too large." QR.error "File #{file.name} is too large (#{$.bytesToString file.size})."
break
else if -1 is QR.mimeTypes.indexOf file.type else if -1 is QR.mimeTypes.indexOf file.type
QR.error "#{file.name}: Unsupported file type." QR.error "#{file.name}: Unsupported file type."
break
unless QR.replies[QR.replies.length - 1].file unless QR.replies[QR.replies.length - 1].file
# set last reply's file # set last reply's file
QR.replies[QR.replies.length - 1].setFile file QR.replies[QR.replies.length - 1].setFile file
@ -668,7 +673,7 @@ QR =
QR.status() QR.status()
QR.error err QR.error err
return return
QR.cleanNotification() QR.cleanNotifications()
# Enable auto-posting if we have stuff to post, disable it otherwise. # Enable auto-posting if we have stuff to post, disable it otherwise.
QR.cooldown.auto = QR.replies.length > 1 QR.cooldown.auto = QR.replies.length > 1
@ -722,6 +727,8 @@ QR =
QR.ajax = $.ajax $.id('postForm').parentNode.action, callbacks, opts QR.ajax = $.ajax $.id('postForm').parentNode.action, callbacks, opts
response: (html) -> response: (html) ->
delete QR.ajax
tmpDoc = d.implementation.createHTMLDocument '' tmpDoc = d.implementation.createHTMLDocument ''
tmpDoc.documentElement.innerHTML = html tmpDoc.documentElement.innerHTML = html
if ban = $ '.banType', tmpDoc # banned/warning if ban = $ '.banType', tmpDoc # banned/warning
@ -763,7 +770,8 @@ QR =
return return
h1 = $ 'h1', tmpDoc h1 = $ 'h1', tmpDoc
QR.lastNotification = new Notification 'success', h1.textContent, 5 QR.cleanNotifications()
QR.lastNotifications.push new Notification 'success', h1.textContent, 5
reply = QR.replies[0] reply = QR.replies[0]
@ -803,6 +811,8 @@ QR =
QR.resetFileInput() QR.resetFileInput()
abort: -> abort: ->
QR.ajax?.abort() if QR.ajax
delete QR.ajax QR.ajax.abort()
delete QR.ajax
QR.error 'QR upload aborted.'
QR.status() QR.status()