getPreviousFeed/getNextFeed: implement wrap around

This commit is contained in:
Andrew Dolgov 2021-04-12 16:04:45 +03:00
parent eadaaebd58
commit 3e22368962
1 changed files with 57 additions and 49 deletions

View File

@ -388,6 +388,24 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
getNextUnread: function(feed, is_cat) {
return this.getNextFeed(feed, is_cat, true);
},
_nextTreeItemFromIndex: function (start, unread_only) {
const items = this.model.store._arrayOfAllItems;
for (let i = start+1; i < items.length; i++) {
const id = String(items[i].id);
const box = this._itemNodesMap[id];
const unread = parseInt(items[i].unread);
if (box && (!unread_only || unread > 0)) {
const row = box[0].rowNode;
const cat = box[0].rowNode.parentNode.parentNode;
if (Element.visible(cat) && Element.visible(row)) {
return items[i];
}
}
}
},
getNextFeed: function (feed, is_cat, unread_only = false) {
let treeItem;
@ -398,36 +416,40 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
}
const items = this.model.store._arrayOfAllItems;
let item = false;
const start = items.indexOf(treeItem);
for (let i = 0; i < items.length; i++) {
if (items[i] == treeItem) {
if (start != -1) {
let item = this._nextTreeItemFromIndex(start, unread_only);
for (let j = i+1; j < items.length; j++) {
const id = String(items[j].id);
// let's try again from the top
// 0 (instead of -1) to skip Special category
if (!item) {
item = this._nextTreeItemFromIndex(0, unread_only);
}
if (item)
return [this.model.store.getValue(item, 'bare_id'),
!this.model.store.getValue(item, 'id').match('FEED:')];
}
return [false, false];
},
_prevTreeItemFromIndex: function (start) {
const items = this.model.store._arrayOfAllItems;
for (let i = start-1; i > 0; i--) {
const id = String(items[i].id);
const box = this._itemNodesMap[id];
const unread = parseInt(items[j].unread);
if (box && (!unread_only || unread > 0)) {
if (box) {
const row = box[0].rowNode;
const cat = box[0].rowNode.parentNode.parentNode;
if (Element.visible(cat) && Element.visible(row)) {
item = items[j];
break;
return items[i];
}
}
}
break;
}
}
if (item) {
return [this.model.store.getValue(item, 'bare_id'),
!this.model.store.getValue(item, 'id').match('FEED:')];
} else {
return [false, false];
}
},
getPreviousFeed: function (feed, is_cat) {
let treeItem;
@ -439,36 +461,22 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/array", "dojo/co
}
const items = this.model.store._arrayOfAllItems;
let item = false;
const start = items.indexOf(treeItem);
for (let i = 0; i < items.length; i++) {
if (items[i] == treeItem) {
if (start != -1) {
let item = this._prevTreeItemFromIndex(start);
for (let j = i-1; j > 0; j--) {
const id = String(items[j].id);
const box = this._itemNodesMap[id];
if (box) {
const row = box[0].rowNode;
const cat = box[0].rowNode.parentNode.parentNode;
if (Element.visible(cat) && Element.visible(row)) {
item = items[j];
break;
}
}
}
break;
}
// wrap from the bottom
if (!item) {
item = this._prevTreeItemFromIndex(items.length);
}
if (item) {
if (item)
return [this.model.store.getValue(item, 'bare_id'),
!this.model.store.getValue(item, 'id').match('FEED:')];
} else {
return [false, false];
}
return [false, false];
},
getFeedCategory: function(feed) {
try {