Stacks: Check if there episodes insteads of shows

If you added a Feed where a Show exists but it had no episodes
entries, the stack would end up in a populated state, but the
HomeView would be blank without widgets.

This changes it so the stack state depends upon the episodes
table being populated instead of the show. The downside
is that if your only feed is one without episodes you can
no longer navigate and interact with it.
This commit is contained in:
Jordan Petridis 2018-10-06 10:22:24 +03:00
parent 1e6eca307b
commit 32bd2a89a3
No known key found for this signature in database
GPG Key ID: E8523968931763BE
2 changed files with 4 additions and 5 deletions

View File

@ -5,7 +5,6 @@ use diesel::prelude::*;
use diesel;
use diesel::dsl::exists;
use diesel::query_builder::AsQuery;
use diesel::select;
use database::connection;
@ -379,13 +378,13 @@ pub(crate) fn episode_exists(title_: &str, show_id_: i32) -> Result<bool, DataEr
/// Check if the `episodes table contains any rows
///
/// Return true if `episodes` table is populated.
pub fn is_episodes_populated() -> Result<bool, DataError> {
pub fn is_episodes_populated(filter_show_ids: &[i32]) -> Result<bool, DataError> {
use schema::episodes::dsl::*;
let db = connection();
let con = db.get()?;
select(exists(episodes.as_query()))
select(exists(episodes.filter(show_id.ne_all(filter_show_ids))))
.get_result(&con)
.map_err(From::from)
}

View File

@ -3,7 +3,7 @@ use gtk::prelude::*;
use crossbeam_channel::Sender;
use failure::Error;
use podcasts_data::dbqueries::is_podcasts_populated;
use podcasts_data::dbqueries::is_episodes_populated;
use app::Action;
use stacks::content::State;
@ -78,7 +78,7 @@ impl ShowStack {
fn determine_state(&mut self) -> Result<(), Error> {
let ign = get_ignored_shows()?;
debug!("IGNORED SHOWS {:?}", ign);
if is_podcasts_populated(&ign)? {
if is_episodes_populated(&ign)? {
self.sender.send(Action::PopulatedState);
} else {
self.sender.send(Action::EmptyState);