|
449 | 449 | } |
450 | 450 |
|
451 | 451 | let rowID = -1; |
452 | | - visibleArticles.sort((e1, e2) => new Date(e2.date) - new Date(e1.date)) |
453 | | - .each((torrentEntry) => { |
454 | | - rssArticleTable.updateRowData({ |
455 | | - rowId: ++rowID, |
456 | | - name: torrentEntry.title, |
457 | | - link: torrentEntry.link, |
458 | | - torrentURL: torrentEntry.torrentURL, |
459 | | - feedUid: torrentEntry.feedUid, |
460 | | - dataId: torrentEntry.id, |
461 | | - isRead: torrentEntry.isRead |
462 | | - }); |
| 452 | + visibleArticles.sort((e1, e2) => new Date(e2.date) - new Date(e1.date)); |
| 453 | + for (const torrentEntry of visibleArticles) { |
| 454 | + rssArticleTable.updateRowData({ |
| 455 | + rowId: ++rowID, |
| 456 | + name: torrentEntry.title, |
| 457 | + link: torrentEntry.link, |
| 458 | + torrentURL: torrentEntry.torrentURL, |
| 459 | + feedUid: torrentEntry.feedUid, |
| 460 | + dataId: torrentEntry.id, |
| 461 | + isRead: torrentEntry.isRead |
463 | 462 | }); |
| 463 | + } |
464 | 464 |
|
465 | 465 | clearDetails(); |
466 | 466 | rssArticleTable.updateTable(false); |
|
647 | 647 |
|
648 | 648 | // check if list of articles differs |
649 | 649 | let needsUpdate = false; |
650 | | - flattenedResp.filter((r) => !r.isFolder) |
651 | | - .each((r) => { |
652 | | - let articlesDiffer = true; |
653 | | - if (r.articles.length === feedData[r.uid].length) { |
654 | | - articlesDiffer = false; |
655 | | - for (let i = 0; i < r.articles.length; ++i) { |
656 | | - if (feedData[r.uid][i].id !== r.articles[i].id) |
657 | | - articlesDiffer = true; |
658 | | - } |
| 650 | + for (const r of flattenedResp) { |
| 651 | + if (r.isFolder) |
| 652 | + continue; |
| 653 | + |
| 654 | + let articlesDiffer = true; |
| 655 | + if (r.articles.length === feedData[r.uid].length) { |
| 656 | + articlesDiffer = false; |
| 657 | + for (let i = 0; i < r.articles.length; ++i) { |
| 658 | + if (feedData[r.uid][i].id !== r.articles[i].id) |
| 659 | + articlesDiffer = true; |
659 | 660 | } |
| 661 | + } |
660 | 662 |
|
661 | | - if (articlesDiffer) { |
662 | | - // update unread count |
663 | | - const oldUnread = feedData[r.uid].map((art) => !art.isRead).filter(Boolean).length; |
664 | | - const newUnread = r.articles.map((art) => !art.isRead).filter(Boolean).length; |
665 | | - const unreadDifference = newUnread - oldUnread; |
| 663 | + if (articlesDiffer) { |
| 664 | + // update unread count |
| 665 | + const oldUnread = feedData[r.uid].map((art) => !art.isRead).filter(Boolean).length; |
| 666 | + const newUnread = r.articles.map((art) => !art.isRead).filter(Boolean).length; |
| 667 | + const unreadDifference = newUnread - oldUnread; |
666 | 668 |
|
667 | | - // find all parents (and self) and add unread difference |
668 | | - for (const row of rssFeedTable.getRowValues()) { |
669 | | - if (r.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath) |
670 | | - row.full_data.unread += unreadDifference; |
671 | | - } |
| 669 | + // find all parents (and self) and add unread difference |
| 670 | + for (const row of rssFeedTable.getRowValues()) { |
| 671 | + if (r.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath) |
| 672 | + row.full_data.unread += unreadDifference; |
| 673 | + } |
672 | 674 |
|
673 | | - needsUpdate = true; |
| 675 | + needsUpdate = true; |
674 | 676 |
|
675 | | - // update data |
676 | | - feedData[r.uid] = r.articles; |
| 677 | + // update data |
| 678 | + feedData[r.uid] = r.articles; |
677 | 679 |
|
678 | | - // if feed that is open changed, reload |
679 | | - if ((openedFeedPath !== undefined) && (r.fullName.slice(0, openedFeedPath.length) === openedFeedPath)) |
680 | | - showRssFeed(r.fullName); |
| 680 | + // if feed that is open changed, reload |
| 681 | + if ((openedFeedPath !== undefined) && (r.fullName.slice(0, openedFeedPath.length) === openedFeedPath)) |
| 682 | + showRssFeed(r.fullName); |
| 683 | + } |
| 684 | + else { |
| 685 | + // calculate read difference and update feed data |
| 686 | + let readDifference = 0; |
| 687 | + let readChanged = false; |
| 688 | + for (let i = 0; i < r.articles.length; ++i) { |
| 689 | + const oldRead = feedData[r.uid][i].isRead ? 1 : 0; |
| 690 | + const newRead = r.articles[i].isRead ? 1 : 0; |
| 691 | + feedData[r.uid][i].isRead = r.articles[i].isRead; |
| 692 | + readDifference += oldRead - newRead; |
| 693 | + if (readDifference !== 0) |
| 694 | + readChanged = true; |
681 | 695 | } |
682 | | - else { |
683 | | - // calculate read difference and update feed data |
684 | | - let readDifference = 0; |
685 | | - let readChanged = false; |
686 | | - for (let i = 0; i < r.articles.length; ++i) { |
687 | | - const oldRead = feedData[r.uid][i].isRead ? 1 : 0; |
688 | | - const newRead = r.articles[i].isRead ? 1 : 0; |
689 | | - feedData[r.uid][i].isRead = r.articles[i].isRead; |
690 | | - readDifference += oldRead - newRead; |
691 | | - if (readDifference !== 0) |
692 | | - readChanged = true; |
693 | | - } |
694 | 696 |
|
695 | | - // if read on article changed |
696 | | - if (readChanged) { |
697 | | - needsUpdate = true; |
698 | | - // find all items that contain this rss feed and add read difference |
699 | | - for (const row of rssFeedTable.getRowValues()) { |
700 | | - if (r.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath) |
701 | | - row.full_data.unread += readDifference; |
702 | | - } |
| 697 | + // if read on article changed |
| 698 | + if (readChanged) { |
| 699 | + needsUpdate = true; |
| 700 | + // find all items that contain this rss feed and add read difference |
| 701 | + for (const row of rssFeedTable.getRowValues()) { |
| 702 | + if (r.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath) |
| 703 | + row.full_data.unread += readDifference; |
| 704 | + } |
703 | 705 |
|
704 | | - // if feed that is opened changed update dynamically |
705 | | - if ((openedFeedPath !== undefined) && (r.fullName.slice(0, openedFeedPath.length) === openedFeedPath)) { |
706 | | - for (let i = 0; i < r.articles.length; ++i) { |
707 | | - for (const row of rssArticleTable.getRowValues()) { |
708 | | - if ((row.full_data.feedUid === r.uid) && (row.full_data.dataId === r.articles[i].id)) { |
709 | | - row.full_data.isRead = r.articles[i].isRead; |
710 | | - break; |
711 | | - } |
| 706 | + // if feed that is opened changed update dynamically |
| 707 | + if ((openedFeedPath !== undefined) && (r.fullName.slice(0, openedFeedPath.length) === openedFeedPath)) { |
| 708 | + for (let i = 0; i < r.articles.length; ++i) { |
| 709 | + for (const row of rssArticleTable.getRowValues()) { |
| 710 | + if ((row.full_data.feedUid === r.uid) && (row.full_data.dataId === r.articles[i].id)) { |
| 711 | + row.full_data.isRead = r.articles[i].isRead; |
| 712 | + break; |
712 | 713 | } |
713 | 714 | } |
714 | 715 | } |
715 | 716 | } |
716 | 717 | } |
717 | | - }); |
| 718 | + } |
| 719 | + } |
718 | 720 | if (statusDiffers) |
719 | 721 | rssFeedTable.updateTable(true); |
720 | 722 | if (needsUpdate) { |
|
878 | 880 | const markItemAsRead = (path) => { |
879 | 881 | // feed data mark as read |
880 | 882 | for (const feedID in feedData) { |
881 | | - if (pathByFeedId.get(feedID).slice(0, path.length) === path) |
882 | | - feedData[feedID].each((el) => el.isRead = true); |
| 883 | + if (pathByFeedId.get(feedID).slice(0, path.length) === path) { |
| 884 | + for (const el of feedData[feedID]) |
| 885 | + el.isRead = true; |
| 886 | + } |
883 | 887 | } |
884 | 888 |
|
885 | 889 | // mark rows as read |
|
938 | 942 |
|
939 | 943 | // update feed data |
940 | 944 | let prevReadState = true; |
941 | | - feedData[uid].each((article) => { |
| 945 | + for (const article of feedData[uid]) { |
942 | 946 | if (article.id === id) { |
943 | 947 | prevReadState = article.isRead; |
944 | 948 | article.isRead = true; |
945 | 949 | } |
946 | | - }); |
| 950 | + } |
947 | 951 |
|
948 | 952 | if (!prevReadState) { |
949 | 953 | // find all items that contain this feed and subtract 1 |
|
976 | 980 | .map((sRow) => rssFeedTable.getRow(sRow).full_data.dataPath); |
977 | 981 | // filter children |
978 | 982 | const reducedDatapaths = selectedDatapaths.filter((path) => |
979 | | - selectedDatapaths.filter((innerPath) => path.slice(0, innerPath.length) === innerPath).length === 1 |
| 983 | + selectedDatapaths.filter(path.startsWith).length === 1 |
980 | 984 | ); |
981 | | - reducedDatapaths.each((path) => markItemAsRead(path)); |
| 985 | + for (const path of reducedDatapaths) |
| 986 | + markItemAsRead(path); |
982 | 987 | }; |
983 | 988 |
|
984 | 989 | const openRssDownloader = () => { |
|
0 commit comments