Addressed code review comments to reduce redundant lines

This commit is contained in:
Thomas Bachmann 2017-01-08 14:38:16 +01:00
parent 443a90c7ba
commit 456502893c

View File

@ -291,6 +291,14 @@ Module.register("newsfeed",{
return string.charAt(0).toUpperCase() + string.slice(1); return string.charAt(0).toUpperCase() + string.slice(1);
}, },
resetDescrOrFullArticleAndTimer: function() {
this.config.showDescription = false;
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
},
notificationReceived: function(notification, payload, sender) { notificationReceived: function(notification, payload, sender) {
Log.info(this.name + " - received notification: " + notification); Log.info(this.name + " - received notification: " + notification);
if(notification == "ARTICLE_NEXT"){ if(notification == "ARTICLE_NEXT"){
@ -299,11 +307,7 @@ Module.register("newsfeed",{
if (this.activeItem >= this.newsItems.length) { if (this.activeItem >= this.newsItems.length) {
this.activeItem = 0; this.activeItem = 0;
} }
this.config.showDescription = false; this.resetDescrOrFullArticleAndTimer();
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")"); Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100); this.updateDom(100);
} else if(notification == "ARTICLE_PREVIOUS"){ } else if(notification == "ARTICLE_PREVIOUS"){
@ -312,39 +316,22 @@ Module.register("newsfeed",{
if (this.activeItem < 0) { if (this.activeItem < 0) {
this.activeItem = this.newsItems.length - 1; this.activeItem = this.newsItems.length - 1;
} }
this.config.showDescription = false; this.resetDescrOrFullArticleAndTimer();
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")"); Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100); this.updateDom(100);
} }
// received "more details" the first time, so showing article summary // if "more details" is received the first time: show article summary, on second time show full article
else if(notification == "ARTICLE_MORE_DETAILS" && !this.config.showDescription){ else if(notification == "ARTICLE_MORE_DETAILS"){
this.config.showDescription = true; this.config.showDescription = !this.config.showDescription;
this.config.showFullArticle = false; this.config.showFullArticle = !this.config.showDescription;
clearInterval(timer); clearInterval(timer);
timer = null; timer = null;
Log.info(this.name + " - showing article description"); Log.info(this.name + " - showing " + this.config.showDescription ? "article description" : "full article");
this.updateDom(100); this.updateDom(100);
} else if(notification == "ARTICLE_LESS_DETAILS"){ } else if(notification == "ARTICLE_LESS_DETAILS"){
this.config.showDescription = false; this.resetDescrOrFullArticleAndTimer();
this.config.showFullArticle = false;
if(!timer){
this.scheduleUpdateInterval();
}
Log.info(this.name + " - showing only article titles again"); Log.info(this.name + " - showing only article titles again");
this.updateDom(100); this.updateDom(100);
}
// received "more details" a second time, so showing full article
else if(notification == "ARTICLE_MORE_DETAILS" && this.config.showDescription){
this.config.showFullArticle = true;
this.config.showDescription = false;
clearInterval(timer);
timer = null;
Log.info(this.name + " - showing full article");
this.updateDom(100);
} else { } else {
Log.info(this.name + " - unknown notification, ignoring: " + notification); Log.info(this.name + " - unknown notification, ignoring: " + notification);
} }