Skip to content

Commit

Permalink
fix(ctx): remove related streams from bucket when uninstalling addon
Browse files Browse the repository at this point in the history
  • Loading branch information
tymmesyde committed Oct 12, 2023
1 parent aa43b09 commit 3f2f332
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/models/ctx/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ impl<E: Env + 'static> Update<E> for Ctx {
Some(auth_key) => Effects::one(delete_session::<E>(auth_key)).unchanged(),
_ => Effects::none().unchanged(),
};
let profile_effects = update_profile::<E>(&mut self.profile, &self.status, msg);
let profile_effects =
update_profile::<E>(&mut self.profile, &mut self.streams, &self.status, msg);
let library_effects =
update_library::<E>(&mut self.library, &self.profile, &self.status, msg);
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
Expand Down Expand Up @@ -110,7 +111,8 @@ impl<E: Env + 'static> Update<E> for Ctx {
.join(notifications_effects)
}
Msg::Internal(Internal::CtxAuthResult(auth_request, result)) => {
let profile_effects = update_profile::<E>(&mut self.profile, &self.status, msg);
let profile_effects =
update_profile::<E>(&mut self.profile, &mut self.streams, &self.status, msg);
let library_effects =
update_library::<E>(&mut self.library, &self.profile, &self.status, msg);
let trakt_addon_effects = update_trakt_addon::<E>(
Expand Down Expand Up @@ -157,7 +159,8 @@ impl<E: Env + 'static> Update<E> for Ctx {
.join(ctx_effects)
}
_ => {
let profile_effects = update_profile::<E>(&mut self.profile, &self.status, msg);
let profile_effects =
update_profile::<E>(&mut self.profile, &mut self.streams, &self.status, msg);
let library_effects =
update_library::<E>(&mut self.library, &self.profile, &self.status, msg);
let streams_effects = update_streams::<E>(&mut self.streams, &self.status, msg);
Expand Down
8 changes: 8 additions & 0 deletions src/models/ctx/update_profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E: Env + 'static>(
profile: &mut Profile,
streams: &mut StreamsBucket,
status: &CtxStatus,
msg: &Msg,
) -> Effects {
Expand Down Expand Up @@ -159,6 +161,12 @@ pub fn update_profile<E: Env + 'static>(
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::<E>(
profile.addons.to_owned(),
Expand Down

0 comments on commit 3f2f332

Please sign in to comment.