Skip to content

Commit

Permalink
pass notifs count to_protobuf fn if available
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBeastLT committed Dec 13, 2023
1 parent b4e9d03 commit 5406581
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 43 deletions.
18 changes: 15 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/commonMain/rust/bridge/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl FromProtobuf<Action> for runtime::Action {
Some(action_ctx::Args::PullNotifications(_args)) => {
Action::Ctx(ActionCtx::PullNotifications)
}
Some(action_ctx::Args::GetEvents(_args)) => Action::Ctx(ActionCtx::GetEvents),
None => unimplemented!("ActionCtx missing"),
},
Some(runtime::action::Type::Link(action_link)) => match &action_link.args {
Expand Down Expand Up @@ -189,6 +190,9 @@ impl FromProtobuf<Action> for runtime::Action {
Some(action_player::Args::PausedChanged(paused)) => {
Action::Player(ActionPlayer::PausedChanged { paused: *paused })
}
Some(action_player::Args::NextVideo(_args)) => {
Action::Player(ActionPlayer::NextVideo {})
}
Some(action_player::Args::Ended(_args)) => Action::Player(ActionPlayer::Ended {}),
None => unimplemented!("ActionLink missing"),
},
Expand Down
3 changes: 3 additions & 0 deletions src/commonMain/rust/bridge/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ impl ToProtobuf<runtime::Event, ()> for Event {
Event::PlayerStopped { .. } => {
runtime::event::Type::PlayerStopped(runtime::event::PlayerStopped {})
}
Event::PlayerNextVideo { .. } => {
runtime::event::Type::PlayerNextVideo(runtime::event::PlayerNextVideo {})
}
Event::PlayerEnded { .. } => {
runtime::event::Type::PlayerEnded(runtime::event::PlayerEnded {})
}
Expand Down
44 changes: 44 additions & 0 deletions src/commonMain/rust/bridge/events.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use stremio_core::types::api::{GetModalResponse, GetNotificationResponse};
use stremio_core::types::events::Events;

use crate::bridge::ToProtobuf;
use crate::protobuf::stremio::core::models;

impl ToProtobuf<models::Events, ()> for Events {
fn to_protobuf(&self, _args: &()) -> models::Events {
models::Events {
modal: Default::default(),
notification: Default::default(),
}
}
}

impl ToProtobuf<models::EventModal, ()> for GetModalResponse {
fn to_protobuf(&self, _args: &()) -> models::EventModal {
models::EventModal {
id: self.id.to_owned(),
title: self.id.to_owned(),
message: self.id.to_owned(),
image_url: self.image_url.to_protobuf(&()),
addon: self
.addon
.as_ref()
.map(|addon| models::event_modal::ModalAddon {
manifest_url: addon.manifest_url.to_protobuf(&()),
name: addon.name.to_owned(),
}),
external_url: self.external_url.to_protobuf(&()),
}
}
}

impl ToProtobuf<models::EventNotification, ()> for GetNotificationResponse {
fn to_protobuf(&self, _args: &()) -> models::EventNotification {
models::EventNotification {
id: self.id.to_owned(),
title: self.id.to_owned(),
message: self.id.to_owned(),
external_url: self.external_url.to_protobuf(&()),
}
}
}
19 changes: 12 additions & 7 deletions src/commonMain/rust/bridge/library_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ use stremio_core::types::library::LibraryItem;
use crate::bridge::ToProtobuf;
use crate::protobuf::stremio::core::types;

impl ToProtobuf<types::LibraryItem, Ctx> for LibraryItem {
fn to_protobuf(&self, ctx: &Ctx) -> types::LibraryItem {
let notifications = ctx
.notifications
.items
.get(&self.id)
.map(|notifs| notifs.len())
impl ToProtobuf<types::LibraryItem, (&Ctx, Option<usize>)> for LibraryItem {
fn to_protobuf(
&self,
(ctx, maybe_notifications): &(&Ctx, Option<usize>),
) -> types::LibraryItem {
let notifications = maybe_notifications
.or_else(|| {
ctx.notifications
.items
.get(&self.id)
.map(|notifs| notifs.len())
})
.unwrap_or_default();
let settings = &ctx.profile.settings;
let streaming_server_url = &settings.streaming_server_url;
Expand Down
40 changes: 37 additions & 3 deletions src/commonMain/rust/bridge/loadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use stremio_core::deep_links::MetaItemDeepLinks;
use stremio_core::models::common::{Loadable, ResourceError};
use stremio_core::models::ctx::Ctx;
use stremio_core::models::link::LinkError;
use stremio_core::models::streaming_server::{PlaybackDevice, Settings};
use stremio_core::models::streaming_server::PlaybackDevice;
use stremio_core::runtime::EnvError;
use stremio_core::types::addon::{Descriptor, DescriptorPreview, ResourcePath, ResourceRequest};
use stremio_core::types::api::{LinkAuthKey, LinkCodeResponse};
use stremio_core::types::api::{
GetModalResponse, GetNotificationResponse, LinkAuthKey, LinkCodeResponse,
};
use stremio_core::types::library::LibraryItem;
use stremio_core::types::resource::{MetaItem, MetaItemPreview, Stream, Subtitles};
use stremio_core::types::streaming_server::Statistics;
use stremio_core::types::streaming_server::{Settings, Statistics};
use stremio_watched_bitfield::WatchedBitField;
use url::Url;

Expand Down Expand Up @@ -306,3 +308,35 @@ impl ToProtobuf<models::loadable_descriptor::Content, Ctx> for Loadable<Descript
}
}
}

impl ToProtobuf<models::loadable_modal::Content, ()> for Loadable<GetModalResponse, EnvError> {
fn to_protobuf(&self, _args: &()) -> models::loadable_modal::Content {
match &self {
Loadable::Ready(ready) => {
models::loadable_modal::Content::Ready(ready.to_protobuf(&()))
}
Loadable::Err(error) => models::loadable_modal::Content::Error(models::Error {
message: error.to_string(),
}),
Loadable::Loading => models::loadable_modal::Content::Loading(models::Loading {}),
}
}
}

impl ToProtobuf<models::loadable_notification::Content, ()>
for Loadable<GetNotificationResponse, EnvError>
{
fn to_protobuf(&self, _args: &()) -> models::loadable_notification::Content {
match &self {
Loadable::Ready(ready) => {
models::loadable_notification::Content::Ready(ready.to_protobuf(&()))
}
Loadable::Err(error) => models::loadable_notification::Content::Error(models::Error {
message: error.to_string(),
}),
Loadable::Loading => {
models::loadable_notification::Content::Loading(models::Loading {})
}
}
}
}
3 changes: 3 additions & 0 deletions src/commonMain/rust/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub use env_error::*;
mod event;
pub use event::*;

mod events;
pub use events::*;

mod extra_value;
pub use extra_value::*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::protobuf::stremio::core::{models, types};

impl ToProtobuf<types::LibraryItem, Ctx> for Item {
fn to_protobuf(&self, ctx: &Ctx) -> types::LibraryItem {
self.library_item.to_protobuf(ctx)
self.library_item
.to_protobuf(&(ctx, Some(self.notifications)))
}
}

Expand Down
1 change: 1 addition & 0 deletions src/commonMain/rust/model/fields/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ impl ToProtobuf<models::Ctx, ()> for Ctx {
fn to_protobuf(&self, _args: &()) -> models::Ctx {
models::Ctx {
profile: self.profile.to_protobuf(&()),
events: self.events.to_protobuf(&()),
}
}
}
2 changes: 1 addition & 1 deletion src/commonMain/rust/model/fields/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<F> ToProtobuf<models::LibraryWithFilters, Ctx> for LibraryWithFilters<F> {
models::LibraryWithFilters {
selected: self.selected.to_protobuf(&()),
selectable: self.selectable.to_protobuf(&()),
catalog: self.catalog.to_protobuf(ctx),
catalog: self.catalog.to_protobuf(&(ctx, None)),
}
}
}
2 changes: 1 addition & 1 deletion src/commonMain/rust/model/fields/library_by_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl ToProtobuf<models::LibraryCatalog, Ctx> for Catalog {
let items = self
.iter()
.flatten()
.map(|item| item.to_protobuf(ctx))
.map(|item| item.to_protobuf(&(ctx, None)))
.collect::<Vec<_>>();
let r#type = items.first().map(|item| item.r#type.to_owned());
models::LibraryCatalog { r#type, items }
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/rust/model/fields/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl ToProtobuf<models::Player, Ctx> for Player {
None,
)),
series_info: self.series_info.to_protobuf(&()),
library_item: self.library_item.to_protobuf(ctx),
library_item: self.library_item.to_protobuf(&(ctx, None)),
stream_state: self.stream_state.to_protobuf(&()),
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/commonMain/rust/model/fields/streaming_server.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use stremio_core::models::streaming_server::{
PlaybackDevice, Selected as StreamingServerSelected, Settings as StreamingServerSettings,
StatisticsRequest, StreamingServer,
PlaybackDevice, Selected as StreamingServerSelected, StatisticsRequest, StreamingServer,
};
use stremio_core::types::streaming_server::Statistics;
use stremio_core::types::streaming_server::{Settings, Statistics};

use crate::bridge::{FromProtobuf, ToProtobuf};
use crate::protobuf::stremio::core::models;

impl FromProtobuf<StreamingServerSettings> for models::streaming_server::Settings {
fn from_protobuf(&self) -> StreamingServerSettings {
StreamingServerSettings {
impl FromProtobuf<Settings> for models::streaming_server::Settings {
fn from_protobuf(&self) -> Settings {
Settings {
app_path: self.app_path.to_owned(),
cache_root: self.cache_root.to_owned(),
server_version: self.server_version.to_owned(),
remote_https: self.remote_https.clone(),
cache_size: self.cache_size.to_owned(),
bt_max_connections: self.bt_max_connections,
bt_handshake_timeout: self.bt_handshake_timeout,
Expand Down Expand Up @@ -76,12 +76,13 @@ impl ToProtobuf<models::streaming_server::Statistics, ()> for Statistics {
}
}

impl ToProtobuf<models::streaming_server::Settings, ()> for StreamingServerSettings {
impl ToProtobuf<models::streaming_server::Settings, ()> for Settings {
fn to_protobuf(&self, _args: &()) -> models::streaming_server::Settings {
models::streaming_server::Settings {
app_path: self.app_path.to_string(),
cache_root: self.cache_root.to_string(),
server_version: self.server_version.to_string(),
remote_https: self.remote_https.clone(),
cache_size: self.cache_size,
bt_max_connections: self.bt_max_connections,
bt_handshake_timeout: self.bt_handshake_timeout,
Expand All @@ -99,6 +100,7 @@ impl ToProtobuf<models::StreamingServer, ()> for StreamingServer {
selected: self.selected.to_protobuf(&()),
settings: self.settings.to_protobuf(&()),
base_url: self.base_url.to_protobuf(&()),
remote_url: self.remote_url.to_protobuf(&()),
torrent: self
.torrent
.to_owned()
Expand Down
44 changes: 44 additions & 0 deletions src/main/proto/stremio/core/models/ctx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,52 @@ package stremio.core.models;

option java_package = "com.stremio.core.models";

import "stremio/core/models/loadable.proto";
import "stremio/core/types/profile.proto";

message Ctx {
required stremio.core.types.Profile profile = 1;
required Events events = 2;
}

message Events {
required LoadableModal modal = 1;
required LoadableNotification notification = 2;
}

message EventModal {
required string id = 1;
required string title = 2;
required string message = 3;
required string image_url = 4;
optional ModalAddon addon = 5;
optional string external_url = 6;

message ModalAddon {
required string manifest_url = 5;
required string name = 6;
}
}

message EventNotification {
required string id = 1;
required string title = 2;
required string message = 3;
optional string external_url = 7;
}

message LoadableModal {
oneof content {
Loading loading = 1;
Error error = 2;
EventModal ready = 3;
}
}

message LoadableNotification {
oneof content {
Loading loading = 1;
Error error = 2;
EventNotification ready = 3;
}
}
Loading

0 comments on commit 5406581

Please sign in to comment.