diff --git a/src/models/ctx/ctx.rs b/src/models/ctx/ctx.rs index 26a900a91..c8be16888 100644 --- a/src/models/ctx/ctx.rs +++ b/src/models/ctx/ctx.rs @@ -81,7 +81,8 @@ impl Update for Ctx { Some(auth_key) => Effects::one(delete_session::(auth_key)).unchanged(), _ => Effects::none().unchanged(), }; - let profile_effects = update_profile::(&mut self.profile, &self.status, msg); + let profile_effects = + update_profile::(&mut self.profile, &mut self.streams, &self.status, msg); let library_effects = update_library::(&mut self.library, &self.profile, &self.status, msg); let streams_effects = update_streams::(&mut self.streams, &self.status, msg); @@ -110,7 +111,8 @@ impl Update for Ctx { .join(notifications_effects) } Msg::Internal(Internal::CtxAuthResult(auth_request, result)) => { - let profile_effects = update_profile::(&mut self.profile, &self.status, msg); + let profile_effects = + update_profile::(&mut self.profile, &mut self.streams, &self.status, msg); let library_effects = update_library::(&mut self.library, &self.profile, &self.status, msg); let trakt_addon_effects = update_trakt_addon::( @@ -157,7 +159,8 @@ impl Update for Ctx { .join(ctx_effects) } _ => { - let profile_effects = update_profile::(&mut self.profile, &self.status, msg); + let profile_effects = + update_profile::(&mut self.profile, &mut self.streams, &self.status, msg); let library_effects = update_library::(&mut self.library, &self.profile, &self.status, msg); let streams_effects = update_streams::(&mut self.streams, &self.status, msg); diff --git a/src/models/ctx/update_profile.rs b/src/models/ctx/update_profile.rs index 9d79fe946..e04c73c13 100644 --- a/src/models/ctx/update_profile.rs +++ b/src/models/ctx/update_profile.rs @@ -7,12 +7,14 @@ use crate::types::api::{ fetch_api, APIError, APIRequest, APIResult, CollectionResponse, SuccessResponse, }; use crate::types::profile::{Auth, AuthKey, Profile, Settings, User}; +use crate::types::streams::StreamsBucket; use enclose::enclose; use futures::{future, FutureExt, TryFutureExt}; use std::collections::HashSet; pub fn update_profile( profile: &mut Profile, + streams: &mut StreamsBucket, status: &CtxStatus, msg: &Msg, ) -> Effects { @@ -159,6 +161,12 @@ pub fn update_profile( if let Some(addon_position) = addon_position { if !profile.addons[addon_position].flags.protected && !addon.flags.protected { profile.addons.remove(addon_position); + + // Remove stream related to this addon from the streams bucket + streams + .items + .retain(|_key, item| item.stream_transport_url != addon.transport_url); + let push_to_api_effects = match profile.auth_key() { Some(auth_key) => Effects::one(push_addons_to_api::( profile.addons.to_owned(),