Fix Unread Count with JSON features

This commit is contained in:
Zixaphir 2014-01-10 23:41:09 -07:00
parent 685f74de50
commit 1900bbfa27
3 changed files with 46 additions and 90 deletions

View File

@ -11943,28 +11943,23 @@
Main.handleErrors(errors); Main.handleErrors(errors);
} }
}, },
ready: function() { ready: function(name, feature, condition) {
var condition, err, errors, feature, name, _i, _len, _ref, _ref1; var err, error;
_ref = [['Unread Count', Unread, Conf['Unread Count']], ['Quote Threading', QuoteThreading, Conf['Quote Threading'] && !Conf['Unread Count']]]; try {
for (_i = 0, _len = _ref.length; _i < _len; _i++) { if (condition) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1], condition = _ref1[2]; feature();
try {
if (condition) {
feature.ready();
}
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Failed to reconnect feature " + name + ".",
error: err
});
} }
} catch (_error) {
err = _error;
error = [
{
message: "Quote Threading Failed.",
error: err
}
];
} }
if (errors) { if (error) {
Main.handleErrors(errors); Main.handleErrors(error);
} }
return QR.generatePostableThreadsList(); return QR.generatePostableThreadsList();
}, },
@ -12170,7 +12165,7 @@
} }
Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready(); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']);
return Navigate.buildThread(); return Navigate.buildThread();
}, },
buildThread: function() { buildThread: function() {
@ -12179,6 +12174,7 @@
$.rmAll(board); $.rmAll(board);
$.add(board, Navigate.threadRoot); $.add(board, Navigate.threadRoot);
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']);
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
} }
@ -12190,18 +12186,6 @@
id: 'popState' id: 'popState'
}); });
return Navigate.navigate.call(a); return Navigate.navigate.call(a);
},
refresh: function(context) {
var boardID, feature, name, threadID, view, _i, _len, _ref, _ref1;
return;
boardID = context.boardID, view = context.view, threadID = context.threadID;
_ref = Main.features;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1];
if (feature.refresh) {
feature.refresh();
}
}
} }
}; };

View File

@ -11932,28 +11932,23 @@
Main.handleErrors(errors); Main.handleErrors(errors);
} }
}, },
ready: function() { ready: function(name, feature, condition) {
var condition, err, errors, feature, name, _i, _len, _ref, _ref1; var err, error;
_ref = [['Unread Count', Unread, Conf['Unread Count']], ['Quote Threading', QuoteThreading, Conf['Quote Threading'] && !Conf['Unread Count']]]; try {
for (_i = 0, _len = _ref.length; _i < _len; _i++) { if (condition) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1], condition = _ref1[2]; feature();
try {
if (condition) {
feature.ready();
}
} catch (_error) {
err = _error;
if (!errors) {
errors = [];
}
errors.push({
message: "Failed to reconnect feature " + name + ".",
error: err
});
} }
} catch (_error) {
err = _error;
error = [
{
message: "Quote Threading Failed.",
error: err
}
];
} }
if (errors) { if (error) {
Main.handleErrors(errors); Main.handleErrors(error);
} }
return QR.generatePostableThreadsList(); return QR.generatePostableThreadsList();
}, },
@ -12159,7 +12154,7 @@
} }
Main.callbackNodes(Thread, [thread]); Main.callbackNodes(Thread, [thread]);
Main.callbackNodes(Post, posts); Main.callbackNodes(Post, posts);
Navigate.ready(); Navigate.ready('Quote Threading', QuoteThreading.force, Conf['Quote Threading']);
return Navigate.buildThread(); return Navigate.buildThread();
}, },
buildThread: function() { buildThread: function() {
@ -12168,6 +12163,7 @@
$.rmAll(board); $.rmAll(board);
$.add(board, Navigate.threadRoot); $.add(board, Navigate.threadRoot);
if (Conf['Unread Count']) { if (Conf['Unread Count']) {
Navigate.ready('Unread Count', Unread.ready, Conf['Unread Count']);
Unread.read(); Unread.read();
return Unread.update(); return Unread.update();
} }
@ -12182,18 +12178,6 @@
}); });
return Navigate.navigate.call(a); return Navigate.navigate.call(a);
}); });
},
refresh: function(context) {
var boardID, feature, name, threadID, view, _i, _len, _ref, _ref1;
return;
boardID = context.boardID, view = context.view, threadID = context.threadID;
_ref = Main.features;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
_ref1 = _ref[_i], name = _ref1[0], feature = _ref1[1];
if (feature.refresh) {
feature.refresh();
}
}
} }
}; };

View File

@ -81,20 +81,16 @@ Navigate =
return return
ready: -> ready: (name, feature, condition) ->
for [name, feature, condition] in [ try
['Unread Count', Unread, Conf['Unread Count']] feature() if condition
['Quote Threading', QuoteThreading, Conf['Quote Threading'] and not Conf['Unread Count']] catch err
] error = [
try message: "Quote Threading Failed."
feature.ready() if condition error: err
catch err ]
errors = [] unless errors
errors.push
message: "Failed to reconnect feature #{name}."
error: err
Main.handleErrors errors if errors Main.handleErrors error if error
QR.generatePostableThreadsList() QR.generatePostableThreadsList()
updateContext: (view) -> updateContext: (view) ->
@ -220,8 +216,6 @@ Navigate =
Navigate.notice = new Notice 'info', 'Loading thread...' Navigate.notice = new Notice 'info', 'Loading thread...'
), 3 * $.SECOND ), 3 * $.SECOND
# Navigate.refresh {boardID, view, threadID}
load: (e) -> load: (e) ->
$.rmClass Index.button, 'fa-spin' $.rmClass Index.button, 'fa-spin'
{req, notice} = Navigate {req, notice} = Navigate
@ -278,7 +272,7 @@ Navigate =
Main.callbackNodes Thread, [thread] Main.callbackNodes Thread, [thread]
Main.callbackNodes Post, posts Main.callbackNodes Post, posts
Navigate.ready() Navigate.ready 'Quote Threading', QuoteThreading.force, Conf['Quote Threading']
Navigate.buildThread() Navigate.buildThread()
@ -286,7 +280,9 @@ Navigate =
board = $ '.board' board = $ '.board'
$.rmAll board $.rmAll board
$.add board, Navigate.threadRoot $.add board, Navigate.threadRoot
if Conf['Unread Count'] if Conf['Unread Count']
Navigate.ready 'Unread Count', Unread.ready, Conf['Unread Count']
Unread.read() Unread.read()
Unread.update() Unread.update()
@ -300,11 +296,3 @@ Navigate =
id: 'popState' id: 'popState'
Navigate.navigate.call a Navigate.navigate.call a
refresh: (context) ->
return
{boardID, view, threadID} = context
# Refresh features
feature.refresh() for [name, feature] in Main.features when feature.refresh
return