From 5c8a6d88243c2142204b7b2c9bdf89efc0252f15 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Fri, 15 Dec 2023 14:25:02 +0200 Subject: [PATCH] add dismissed events bucket --- src/commonMain/rust/bridge/action.rs | 3 + src/commonMain/rust/bridge/event.rs | 5 ++ src/commonMain/rust/model/model.rs | 11 +++- src/commonMain/rust/stremio_core_android.rs | 22 +++++-- .../stremio/core/runtime/action_ctx.proto | 1 + .../proto/stremio/core/runtime/event.proto | 64 ++++++++++--------- 6 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/commonMain/rust/bridge/action.rs b/src/commonMain/rust/bridge/action.rs index 1bd1293..d99a75e 100644 --- a/src/commonMain/rust/bridge/action.rs +++ b/src/commonMain/rust/bridge/action.rs @@ -75,6 +75,9 @@ impl FromProtobuf for runtime::Action { Action::Ctx(ActionCtx::PullNotifications) } Some(action_ctx::Args::GetEvents(_args)) => Action::Ctx(ActionCtx::GetEvents), + Some(action_ctx::Args::DismissEvent(id)) => { + Action::Ctx(ActionCtx::DismissEvent(id.to_owned())) + } None => unimplemented!("ActionCtx missing"), }, Some(runtime::action::Type::Link(action_link)) => match &action_link.args { diff --git a/src/commonMain/rust/bridge/event.rs b/src/commonMain/rust/bridge/event.rs index 782daa3..52bc27a 100644 --- a/src/commonMain/rust/bridge/event.rs +++ b/src/commonMain/rust/bridge/event.rs @@ -31,6 +31,11 @@ impl ToProtobuf for Event { runtime::event::NotificationsPushedToStorage { ids: ids.clone() }, ) } + Event::DismissedEventsPushedToStorage { uid } => { + runtime::event::Type::DismissedEventsPushedToStorage( + runtime::event::DismissedEventsPushedToStorage { uid: uid.clone() }, + ) + } Event::UserPulledFromAPI { uid } => { runtime::event::Type::UserPulledFromApi(runtime::event::UserPulledFromApi { uid: uid.clone(), diff --git a/src/commonMain/rust/model/model.rs b/src/commonMain/rust/model/model.rs index 7e2e30e..6ca00ed 100644 --- a/src/commonMain/rust/model/model.rs +++ b/src/commonMain/rust/model/model.rs @@ -12,6 +12,7 @@ use stremio_core::models::player::Player; use stremio_core::models::streaming_server::StreamingServer; use stremio_core::runtime::Effects; use stremio_core::types::api::LinkAuthKey; +use stremio_core::types::events::DismissedEventsBucket; use stremio_core::types::library::LibraryBucket; use stremio_core::types::notifications::NotificationsBucket; use stremio_core::types::profile::Profile; @@ -49,11 +50,19 @@ impl AndroidModel { streams: StreamsBucket, notifications: NotificationsBucket, search_history: SearchHistoryBucket, + dismissed_events: DismissedEventsBucket, ) -> (AndroidModel, Effects) { let (continue_watching_preview, continue_watching_preview_effects) = ContinueWatchingPreview::new(&library, ¬ifications); - let ctx = Ctx::new(profile, library, streams, notifications, search_history); + let ctx = Ctx::new( + profile, + library, + streams, + notifications, + search_history, + dismissed_events, + ); let (discover, discover_effects) = CatalogWithFilters::::new(&ctx.profile); let (library_, library_effects) = diff --git a/src/commonMain/rust/stremio_core_android.rs b/src/commonMain/rust/stremio_core_android.rs index 7bc9a29..d2611ea 100644 --- a/src/commonMain/rust/stremio_core_android.rs +++ b/src/commonMain/rust/stremio_core_android.rs @@ -12,11 +12,13 @@ use jni::{JNIEnv, JavaVM}; use lazy_static::lazy_static; use prost::Message; use stremio_core::constants::{ - LIBRARY_RECENT_STORAGE_KEY, LIBRARY_STORAGE_KEY, NOTIFICATIONS_STORAGE_KEY, - PROFILE_STORAGE_KEY, SEARCH_HISTORY_STORAGE_KEY, STREAMS_STORAGE_KEY, + DISMISSED_EVENTS_STORAGE_KEY, LIBRARY_RECENT_STORAGE_KEY, LIBRARY_STORAGE_KEY, + NOTIFICATIONS_STORAGE_KEY, PROFILE_STORAGE_KEY, SEARCH_HISTORY_STORAGE_KEY, + STREAMS_STORAGE_KEY, }; use stremio_core::models::common::Loadable; use stremio_core::runtime::{Env, EnvError, Runtime, RuntimeEvent}; +use stremio_core::types::events::DismissedEventsBucket; use stremio_core::types::library::LibraryBucket; use stremio_core::types::notifications::NotificationsBucket; use stremio_core::types::profile::Profile; @@ -59,7 +61,7 @@ pub unsafe extern "C" fn Java_com_stremio_core_Core_initializeNative( let init_result = AndroidEnv::exec_sync(AndroidEnv::init(&env, storage)); match init_result { Ok(_) => { - let storage_result = AndroidEnv::exec_sync(future::try_join( + let storage_result = AndroidEnv::exec_sync(future::try_join3( future::try_join5( AndroidEnv::get_storage::(PROFILE_STORAGE_KEY), AndroidEnv::get_storage::(LIBRARY_RECENT_STORAGE_KEY), @@ -68,11 +70,13 @@ pub unsafe extern "C" fn Java_com_stremio_core_Core_initializeNative( AndroidEnv::get_storage::(NOTIFICATIONS_STORAGE_KEY), ), AndroidEnv::get_storage::(SEARCH_HISTORY_STORAGE_KEY), + AndroidEnv::get_storage::(DISMISSED_EVENTS_STORAGE_KEY), )); match storage_result { Ok(( (profile, recent_bucket, other_bucket, streams, notifications), search_history, + dismissed_events, )) => { let profile = profile.unwrap_or_default(); let mut library = LibraryBucket::new(profile.uid(), vec![]); @@ -90,8 +94,16 @@ pub unsafe extern "C" fn Java_com_stremio_core_Core_initializeNative( )); let search_history = search_history.unwrap_or(SearchHistoryBucket::new(profile.uid())); - let (model, effects) = - AndroidModel::new(profile, library, streams, notifications, search_history); + let dismissed_events = + dismissed_events.unwrap_or(DismissedEventsBucket::new(profile.uid())); + let (model, effects) = AndroidModel::new( + profile, + library, + streams, + notifications, + search_history, + dismissed_events, + ); let (runtime, rx) = Runtime::::new( model, effects.into_iter().collect::>(), diff --git a/src/main/proto/stremio/core/runtime/action_ctx.proto b/src/main/proto/stremio/core/runtime/action_ctx.proto index 8a6af79..d785892 100644 --- a/src/main/proto/stremio/core/runtime/action_ctx.proto +++ b/src/main/proto/stremio/core/runtime/action_ctx.proto @@ -32,6 +32,7 @@ message ActionCtx { google.protobuf.Empty sync_library_with_api = 18; google.protobuf.Empty pull_notifications = 19; google.protobuf.Empty get_events = 20; + string dismiss_event = 21; } message LibraryItemToggle { diff --git a/src/main/proto/stremio/core/runtime/event.proto b/src/main/proto/stremio/core/runtime/event.proto index ca0dd4d..354d0d5 100644 --- a/src/main/proto/stremio/core/runtime/event.proto +++ b/src/main/proto/stremio/core/runtime/event.proto @@ -14,36 +14,37 @@ message Event { StreamsPushedToStorage streams_pushed_to_storage = 3; SearchHistoryPushedToStorage search_history_pushed_to_storage = 4; NotificationsPushedToStorage notifications_pushed_to_storage = 5; - UserPulledFromAPI user_pulled_from_api = 6; - UserPushedToAPI user_pushed_to_api = 7; - AddonsPulledFromAPI addons_pulled_from_api = 8; - AddonsPushedToAPI addons_pushed_to_api = 9; - LibrarySyncWithAPIPlanned library_sync_with_api_planned = 10; - LibraryItemsPushedToAPI library_items_pushed_to_api = 11; - LibraryItemsPulledFromAPI library_items_pulled_from_api = 12; - UserAuthenticated user_authenticated = 13; - UserLoggedOut user_logged_out = 14; - SessionDeleted session_deleted = 15; - TraktAddonFetched trakt_addon_fetched = 16; - TraktLoggedOut trakt_logged_out = 17; - AddonInstalled addon_installed = 18; - AddonUpgraded addon_upgraded = 19; - AddonUninstalled addon_uninstalled = 20; - SettingsUpdated settings_updated = 21; - LibraryItemAdded library_item_added = 22; - LibraryItemRemoved library_item_removed = 23; - LibraryItemRewinded library_item_rewinded = 24; - LibraryItemNotificationsToggled library_item_notifications_toggled = 25; - NotificationsDismissed notifications_dismissed = 26; - PlayerPlaying player_playing = 27; - PlayerStopped player_stopped = 28; - PlayerNextVideo player_next_video = 29; - PlayerEnded player_ended = 30; - TraktPlaying trakt_playing = 31; - TraktPaused trakt_paused = 32; - MagnetParsed magnet_parsed = 33; - TorrentParsed torrent_parsed = 34; - PlayingOnDevice playing_on_device = 35; + DismissedEventsPushedToStorage dismissed_events_pushed_to_storage = 6; + UserPulledFromAPI user_pulled_from_api = 7; + UserPushedToAPI user_pushed_to_api = 8; + AddonsPulledFromAPI addons_pulled_from_api = 9; + AddonsPushedToAPI addons_pushed_to_api = 10; + LibrarySyncWithAPIPlanned library_sync_with_api_planned = 11; + LibraryItemsPushedToAPI library_items_pushed_to_api = 12; + LibraryItemsPulledFromAPI library_items_pulled_from_api = 13; + UserAuthenticated user_authenticated = 14; + UserLoggedOut user_logged_out = 15; + SessionDeleted session_deleted = 16; + TraktAddonFetched trakt_addon_fetched = 17; + TraktLoggedOut trakt_logged_out = 18; + AddonInstalled addon_installed = 19; + AddonUpgraded addon_upgraded = 20; + AddonUninstalled addon_uninstalled = 21; + SettingsUpdated settings_updated = 22; + LibraryItemAdded library_item_added = 23; + LibraryItemRemoved library_item_removed = 24; + LibraryItemRewinded library_item_rewinded = 25; + LibraryItemNotificationsToggled library_item_notifications_toggled = 26; + NotificationsDismissed notifications_dismissed = 27; + PlayerPlaying player_playing = 28; + PlayerStopped player_stopped = 29; + PlayerNextVideo player_next_video = 30; + PlayerEnded player_ended = 31; + TraktPlaying trakt_playing = 32; + TraktPaused trakt_paused = 33; + MagnetParsed magnet_parsed = 34; + TorrentParsed torrent_parsed = 35; + PlayingOnDevice playing_on_device = 36; Error error = 100; } @@ -62,6 +63,9 @@ message Event { message NotificationsPushedToStorage { repeated string ids = 1; } + message DismissedEventsPushedToStorage { + optional string uid = 1; + } message UserPulledFromAPI { optional string uid = 1; }