Merge pull request #35 from mossroy/master

Issue #30 : Handle the NOT_LOGGED_IN errors that can come from tt-rss backends.
This commit is contained in:
Jeena Paradies 2014-08-09 17:39:57 +02:00
commit 2895e2749e
2 changed files with 63 additions and 27 deletions

View file

@ -162,35 +162,46 @@ App.prototype.reload = function() {
App.prototype.gotUnreadFeeds = function(new_articles) { App.prototype.gotUnreadFeeds = function(new_articles) {
if(new_articles == null || !this.validate(new_articles)) { // on error load the saved unread articles. if(new_articles == null || !this.validate(new_articles)) {
var old_articles = localStorage.unread_articles; // Check if we did not get a NOT_LOGGED_IN error, and ask the
if(old_articles) { // user to login again if it is the case.
this.unread_articles = JSON.parse(old_articles); // This can happen with TT-RSS backend
} if (new_articles.error && new_articles.error === "NOT_LOGGED_IN") {
this.populateList(); alert("Your TinyTinyRSS session has expired. Please login again");
this.login.fillLoginFormFromLocalStorage();
this.login.log_in();
}
else {
// On other errors, load the saved unread articles.
var old_articles = localStorage.unread_articles;
if(old_articles) {
this.unread_articles = JSON.parse(old_articles);
}
this.populateList();
}
} else { } else {
this.unread_articles = this.unread_articles.concat(new_articles);
this.unread_articles = this.unread_articles.concat(new_articles); if(new_articles.length > 0) {
try {
if(new_articles.length > 0) { //To check if when it fails it is the same
try { localStorage.unread_articles = JSON.stringify(this.unread_articles);
//To check if when it fails it is the same var size = parseInt(localStorage.maxDownload);
localStorage.unread_articles = JSON.stringify(this.unread_articles); if(localStorage.unread_articles.length < size) {
var size = parseInt(localStorage.maxDownload); var num = parseInt(localStorage.numArticles);
if(localStorage.unread_articles.length < size) { this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles,num);
var num = parseInt(localStorage.numArticles); } else {
this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles,num); alert("Limit size reached: Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length +" bytes");
} else { }
alert("Limit size reached: Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length +" bytes"); }
} catch (e) {
} alert("Reached maximum memory by app " + e.name + " " + e.message + ". We will keep working in anycase with: " + localStorage.unread_articles.length);
catch (e) { }
alert("Reached maximum memory by app " + e.name + " " + e.message + ". We will keep working in anycase with: " + localStorage.unread_articles.length); this.populateList();
} }
this.populateList();
}
} }
}; };

View file

@ -67,6 +67,7 @@ Login.prototype.authenticate = function(e) {
if(data.version) { if(data.version) {
var auth = btoa(user + ':' + password); var auth = btoa(user + ':' + password);
localStorage.server_url = server_url; localStorage.server_url = server_url;
localStorage.username = user;
localStorage.session_id = auth; localStorage.session_id = auth;
localStorage.backend = "OwnCloud"; localStorage.backend = "OwnCloud";
_this.app.after_login(localStorage.backend); _this.app.after_login(localStorage.backend);
@ -83,6 +84,7 @@ Login.prototype.authenticate = function(e) {
Pond.login(server_url, user, password, function(data) { Pond.login(server_url, user, password, function(data) {
if(data.session_token) { if(data.session_token) {
localStorage.server_url = server_url; localStorage.server_url = server_url;
localStorage.username = user;
localStorage.session_id = data.session_token; localStorage.session_id = data.session_token;
localStorage.backend = "Pond"; localStorage.backend = "Pond";
_this.app.after_login(localStorage.backend); _this.app.after_login(localStorage.backend);
@ -106,6 +108,7 @@ Login.prototype.authenticate = function(e) {
} else { } else {
localStorage.server_url = server_url; localStorage.server_url = server_url;
localStorage.username = user;
localStorage.session_id = data.session_id; localStorage.session_id = data.session_id;
localStorage.backend = "TinyTinyRSS"; localStorage.backend = "TinyTinyRSS";
_this.app.after_login(localStorage.backend); _this.app.after_login(localStorage.backend);
@ -120,7 +123,29 @@ Login.prototype.authenticate = function(e) {
return false; return false;
}; };
Login.prototype.fillLoginFormFromLocalStorage = function() {
var serverUrl = localStorage.server_url;
if (serverUrl) {
$("#url").value = serverUrl;
}
var userName = localStorage.username;
if (userName) {
$("#un").value = userName;
}
var backendName = localStorage.backend;
if (backendName === "TinyTinyRSS") {
$("#login form").backend[0].checked = true;
}
else if (backendName === "OwnCloud") {
$("#login form").backend[1].checked = true;
}
else if (backendName === "Pond") {
$("#login form").backend[2].checked = true;
}
}
Login.prototype.log_out = function() { Login.prototype.log_out = function() {
this.fillLoginFormFromLocalStorage();
localStorage.removeItem("server_url"); localStorage.removeItem("server_url");
localStorage.removeItem("session_id"); localStorage.removeItem("session_id");
localStorage.removeItem("unread_articles"); localStorage.removeItem("unread_articles");