Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for notifications #213

Merged
merged 102 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
13c933e
fix(frontend): memory leak
IgnisDa Jul 26, 2023
f7a8deb
feat(frontend): remove imports from sidebar
IgnisDa Jul 27, 2023
8269bdf
fix(frontend): change title
IgnisDa Jul 27, 2023
8ac9af0
chore(exercise-app): delete project
IgnisDa Jul 27, 2023
943d433
Revert "chore(exercise-app): delete project"
IgnisDa Jul 27, 2023
acbbbd5
feat(backend): add models for monitoring metadata
IgnisDa Jul 27, 2023
de039fc
feat(backend): basic fn to monitor metadata
IgnisDa Jul 27, 2023
a21fcc3
feat(backend): add resolver to toggle metadata monitor
IgnisDa Jul 27, 2023
778956f
feat(backend): do not delete metadata which are monitored
IgnisDa Jul 27, 2023
6dd889b
fix(frontend): display num times watched always
IgnisDa Jul 27, 2023
611fa94
feat(frontend): add homepage link
IgnisDa Jul 27, 2023
4ce2e7c
docs(importing): cleanup information
IgnisDa Jul 28, 2023
9ab466c
feat(backend): start collapsing related media into one
IgnisDa Jul 28, 2023
8edb0dc
feat(backend): resolver to get media details
IgnisDa Jul 28, 2023
3807f6d
fix(backend): implement in progress seen item
IgnisDa Jul 28, 2023
bd20e72
feat(frontend): adapt to new gql schema
IgnisDa Jul 28, 2023
976b965
fix(frontend): change network waterfall
IgnisDa Jul 28, 2023
8e5e20d
feat(backend): return media details from resolver
IgnisDa Jul 28, 2023
1778c17
chore(frontend): adapt to new gql schema
IgnisDa Jul 28, 2023
e43c994
feat(backend): return next episode details
IgnisDa Jul 28, 2023
e16c981
chore(frontend): adapt to new gql schema
IgnisDa Jul 28, 2023
e105dc6
fix(backend): return correct next episode
IgnisDa Jul 28, 2023
bac2f89
feat(backend): return if media is monitored
IgnisDa Jul 28, 2023
0edcec3
chore(graphql): add mutation to toggle media monitor
IgnisDa Jul 28, 2023
8f47d5f
feat(frontend): add btn to toggle media monitor
IgnisDa Jul 28, 2023
d7b1a4b
fix(frontend): improve summary layout
IgnisDa Jul 28, 2023
23f9041
fix(backend): remove useless field
IgnisDa Jul 28, 2023
4652898
feat(backend): start storing notification prefs in db
IgnisDa Jul 28, 2023
e9f9ab9
feat(backend): remove summary model
IgnisDa Jul 28, 2023
51f8b68
chore(frontend): adapt to new gql schema
IgnisDa Jul 28, 2023
8ff8bcd
fix(backend): calculate summary correctly
IgnisDa Jul 28, 2023
575066a
chore(graphql): get prefs for notifications
IgnisDa Jul 28, 2023
393cf2a
feat(frontend): use light logo
IgnisDa Jul 28, 2023
95a663d
feat(frontend): separate sidebar section for dashboard
IgnisDa Jul 28, 2023
977d72c
feat(*): allow listing monitored items
IgnisDa Jul 28, 2023
efbfe04
feat(backend): allow updating any property
IgnisDa Jul 28, 2023
fbe2bcd
chore(frontend): adapt to new gql schema
IgnisDa Jul 28, 2023
895ac0c
chore(*): change expected input
IgnisDa Jul 28, 2023
46189b1
feat(backend): store media details
IgnisDa Jul 28, 2023
de4d6bd
chore(frontend): adapt to new gql schema
IgnisDa Jul 28, 2023
91b685f
feat(backend): store media status in database
IgnisDa Jul 28, 2023
8bea6cd
fix(backend): correct migrations
IgnisDa Jul 28, 2023
1a46a9c
feat(backend): remove todo
IgnisDa Jul 28, 2023
c31461f
feat(backend): handle notifs prefs
IgnisDa Jul 28, 2023
62e051b
feat(frontend): allow changing notifs settings
IgnisDa Jul 28, 2023
568baf8
fix(frontend): remove useless conditionals
IgnisDa Jul 28, 2023
8595104
fix(frontend): change home page title
IgnisDa Jul 28, 2023
4c7bf4b
fix(frontend): display summary on home-page
IgnisDa Jul 28, 2023
3782812
fix(backend): handle cases with incorrect num pages
IgnisDa Jul 28, 2023
76a195d
style(backend): apply clippy lint
IgnisDa Jul 28, 2023
1071376
fix(backend): number of pages media tracker
IgnisDa Jul 28, 2023
7d5dee7
feat(backend): add field to store notifications data
IgnisDa Jul 28, 2023
ffbd44c
feat(backend): add config for other notif platforms
IgnisDa Jul 28, 2023
b569398
chore(backend): add todo comment
IgnisDa Jul 28, 2023
0e18da6
feat(backend): add resolver to create a user notification
IgnisDa Jul 28, 2023
068bdfb
feat(backend): add resolver to delete notification platform
IgnisDa Jul 29, 2023
a605b1b
feat(backend): add resolver to get all notification platforms
IgnisDa Jul 29, 2023
0fda43c
chore(graphql): add queries/mutations for notification platforms
IgnisDa Jul 29, 2023
8c3e40d
feat(frontend): add separate profile settings page
IgnisDa Jul 29, 2023
58be48d
feat(frontend): add links to settings pages
IgnisDa Jul 29, 2023
b499366
feat(frontend): complete preference settings page
IgnisDa Jul 29, 2023
9b076c4
feat(frontend): add token settings page
IgnisDa Jul 29, 2023
149ca7c
feat(frontend): add miscellaneous settings page
IgnisDa Jul 29, 2023
565f73c
feat(frontend): add integration settings page
IgnisDa Jul 29, 2023
e3caeac
feat(frontend): add user settings page
IgnisDa Jul 29, 2023
425c25b
chore(frontend): delete useless page
IgnisDa Jul 29, 2023
d129b4e
fix(frontend): display user settings only to admin
IgnisDa Jul 29, 2023
fd27b49
fix(frontend): use scroll area in navbar
IgnisDa Jul 29, 2023
0586563
build(backend): bump version
IgnisDa Jul 29, 2023
ea37b8a
feat(frontend): basic notifications page
IgnisDa Jul 29, 2023
1d2c432
feat(frontend): allow adding platforms
IgnisDa Jul 29, 2023
f2ebcde
feat(backend): allow sending discord messages
IgnisDa Jul 29, 2023
dbb6fa6
feat(frontend): use icon for btn
IgnisDa Jul 29, 2023
71af3a4
feat(backend): add resolver to test notification
IgnisDa Jul 29, 2023
611a553
feat(frontend): allow testing notification platforms
IgnisDa Jul 29, 2023
3e19ff0
feat(backend): handle gotify notification platform
IgnisDa Jul 29, 2023
1ca4821
feat(backend): handle ntfy notification platform
IgnisDa Jul 29, 2023
866cfe1
feat(backend): add pushbullet notification platform
IgnisDa Jul 29, 2023
a20e704
feat(backend): add pushover notification platform
IgnisDa Jul 29, 2023
5d5918f
feat(backend): add pushsafer notification platform
IgnisDa Jul 29, 2023
30de764
fix(frontend): remove required fields
IgnisDa Jul 29, 2023
958c365
feat(frontend): add tooltips to action btns
IgnisDa Jul 29, 2023
3580f95
fix(backend): update more fields
IgnisDa Jul 30, 2023
307de16
Revert "Revert "chore(exercise-app): delete project""
IgnisDa Jul 30, 2023
87473d9
feat(frontend): add explanations
IgnisDa Jul 30, 2023
a77f47b
feat(*): removed `released` notification
IgnisDa Jul 30, 2023
1f801ad
refactor(*): remove `monitored` field
IgnisDa Jul 30, 2023
d9d2b8a
fix(frontend): change size of switch btn
IgnisDa Jul 30, 2023
47af3ff
docs: change MediaTracker info
IgnisDa Jul 30, 2023
7fdbf22
fix(frontend): change description
IgnisDa Jul 30, 2023
83da069
feat(*): single btn to trigger notifications
IgnisDa Jul 30, 2023
a78d67c
fix(backend): notifications not being trigerred
IgnisDa Jul 30, 2023
98ca929
fix(frontend): make inputs clearer
IgnisDa Jul 30, 2023
6b44dde
feat(backend): collect notifications to send
IgnisDa Jul 30, 2023
fb165bb
feat(backend): trigger update metadata job
IgnisDa Jul 30, 2023
770ad09
feat(backend): trigger notifications
IgnisDa Jul 30, 2023
d1402a3
fix(backend): send remaining notifications
IgnisDa Jul 30, 2023
a586394
fix(backend): monitor podcasts
IgnisDa Jul 30, 2023
d0eab0e
fix(backend): insert notification platform at front
IgnisDa Jul 30, 2023
92544c8
Revert "refactor(*): remove `monitored` field"
IgnisDa Jul 30, 2023
f072b78
fix(backend): also handle monitored media
IgnisDa Jul 30, 2023
c492b33
feat(frontend): change notif preferences info
IgnisDa Jul 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .moon/workspace.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$schema: 'https://moonrepo.dev/schemas/workspace.json'

projects:
exercise-app: 'apps/exercise-app'
frontend: 'apps/frontend'
kodi: 'apps/kodi'
generated: 'libs/generated'
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "1.17.7"
version = "1.18.0"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-V3"
Expand Down
25 changes: 12 additions & 13 deletions apps/backend/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,28 @@ impl Job for ScheduledJob {
const NAME: &'static str = "apalis::ScheduledJob";
}

pub async fn general_media_cleanup_jobs(
_information: ScheduledJob,
ctx: JobContext,
) -> Result<(), JobError> {
pub async fn media_jobs(_information: ScheduledJob, ctx: JobContext) -> Result<(), JobError> {
tracing::trace!("Invalidating invalid media import jobs");
ctx.data::<Arc<ImporterService>>()
.unwrap()
.invalidate_import_jobs()
.await
.unwrap();
tracing::trace!("Cleaning up media items without associated user activities");
ctx.data::<Arc<MiscellaneousService>>()
.unwrap()
let service = ctx.data::<Arc<MiscellaneousService>>().unwrap();
service
.cleanup_metadata_with_associated_user_activities()
.await
.unwrap();
tracing::trace!("Checking for updates for media in Watchlist");
service
.update_watchlist_media_and_send_notifications()
.await
.unwrap();
Ok(())
}

pub async fn general_user_cleanup(
_information: ScheduledJob,
ctx: JobContext,
) -> Result<(), JobError> {
pub async fn user_jobs(_information: ScheduledJob, ctx: JobContext) -> Result<(), JobError> {
tracing::trace!("Cleaning up user and metadata association");
ctx.data::<Arc<MiscellaneousService>>()
.unwrap()
Expand Down Expand Up @@ -126,7 +125,7 @@ pub async fn user_created_job(
.await
.unwrap();
service
.calculate_user_media_summary(&information.user_id)
.calculate_user_media_summary(information.user_id)
.await
.unwrap();
Ok(())
Expand All @@ -148,7 +147,7 @@ pub async fn recalculate_user_summary_job(
tracing::trace!("Calculating summary for user {:?}", information.user_id);
ctx.data::<Arc<MiscellaneousService>>()
.unwrap()
.calculate_user_media_summary(&information.user_id)
.calculate_user_media_summary(information.user_id)
.await
.unwrap();
tracing::trace!(
Expand All @@ -173,7 +172,7 @@ pub async fn update_metadata_job(
) -> Result<(), JobError> {
ctx.data::<Arc<MiscellaneousService>>()
.unwrap()
.update_metadata(information.metadata)
.update_metadata(information.metadata.id)
.await
.unwrap();
Ok(())
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/entities/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub struct Model {
pub creators: MetadataCreators,
pub source: MetadataSource,
pub specifics: MediaSpecifics,
pub production_status: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
1 change: 0 additions & 1 deletion apps/backend/src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ pub mod metadata_to_collection;
pub mod metadata_to_genre;
pub mod review;
pub mod seen;
pub mod summary;
pub mod user;
pub mod user_to_metadata;
1 change: 0 additions & 1 deletion apps/backend/src/entities/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ pub use super::metadata_to_collection::Entity as MetadataToCollection;
pub use super::metadata_to_genre::Entity as MetadataToGenre;
pub use super::review::Entity as Review;
pub use super::seen::Entity as Seen;
pub use super::summary::Entity as Summary;
pub use super::user::Entity as User;
pub use super::user_to_metadata::Entity as UserToMetadata;
40 changes: 0 additions & 40 deletions apps/backend/src/entities/summary.rs

This file was deleted.

17 changes: 7 additions & 10 deletions apps/backend/src/entities/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use serde::{Deserialize, Serialize};

use crate::{
migrator::UserLot,
users::{UserPreferences, UserSinkIntegrations, UserYankIntegrations},
models::media::UserSummary,
users::{UserNotifications, UserPreferences, UserSinkIntegrations, UserYankIntegrations},
};

fn get_hasher() -> Argon2<'static> {
Expand All @@ -35,6 +36,10 @@ pub struct Model {
pub yank_integrations: Option<UserYankIntegrations>,
#[graphql(skip)]
pub sink_integrations: UserSinkIntegrations,
#[graphql(skip)]
pub notifications: UserNotifications,
#[graphql(skip)]
pub summary: Option<UserSummary>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand All @@ -47,8 +52,6 @@ pub enum Relation {
Review,
#[sea_orm(has_many = "super::seen::Entity")]
Seen,
#[sea_orm(has_many = "super::summary::Entity")]
Summary,
}

impl Related<super::collection::Entity> for Entity {
Expand All @@ -75,12 +78,6 @@ impl Related<super::seen::Entity> for Entity {
}
}

impl Related<super::summary::Entity> for Entity {
fn to() -> RelationDef {
Relation::Summary.def()
}
}

impl Related<super::metadata::Entity> for Entity {
fn to() -> RelationDef {
super::user_to_metadata::Relation::Metadata.def()
Expand All @@ -96,7 +93,7 @@ impl ActiveModelBehavior for ActiveModel {
where
C: ConnectionTrait,
{
if !self.password.is_unchanged() || self.password.is_not_set() {
if self.password.is_set() {
let password = self.password.unwrap();
let salt = SaltString::generate(&mut OsRng);
let password_hash = get_hasher()
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/entities/user_to_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub metadata_id: i32,
pub last_updated_on: DateTimeUtc,
pub monitored: bool,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
1 change: 1 addition & 0 deletions apps/backend/src/importer/goodreads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub async fn import(input: DeployGoodreadsImportInput) -> Result<ImportResult> {
identifier: d.book_id.to_string(),
title: d.title,
description: Some(d.book_description),
production_status: "Released".to_owned(),
lot: MetadataLot::Book,
source: MetadataSource::Custom,
creators: vec![MetadataCreator {
Expand Down
19 changes: 15 additions & 4 deletions apps/backend/src/importer/media_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ struct ItemSeen {
episode_id: Option<i32>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
enum ItemNumberOfPages {
Nothing(String),
Something(i32),
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
struct ItemDetails {
Expand All @@ -126,7 +133,7 @@ struct ItemDetails {
title: String,
overview: Option<String>,
authors: Option<Vec<String>>,
number_of_pages: Option<i32>,
number_of_pages: Option<ItemNumberOfPages>,
}

pub async fn import(input: DeployMediaTrackerImportInput) -> Result<ImportResult> {
Expand Down Expand Up @@ -252,6 +259,11 @@ pub async fn import(input: DeployMediaTrackerImportInput) -> Result<ImportResult
}
}

let num_pages = details.number_of_pages.and_then(|d| match d {
ItemNumberOfPages::Nothing(_) => None,
ItemNumberOfPages::Something(s) => Some(s),
});

let item = ImportOrExportItem {
source_id: d.id.to_string(),
source,
Expand All @@ -262,6 +274,7 @@ pub async fn import(input: DeployMediaTrackerImportInput) -> Result<ImportResult
identifier,
title: details.title,
description: details.overview,
production_status: "Released".to_owned(),
lot,
source: MetadataSource::Custom,
creators: details
Expand All @@ -278,9 +291,7 @@ pub async fn import(input: DeployMediaTrackerImportInput) -> Result<ImportResult
images: vec![],
publish_year: None,
publish_date: None,
specifics: MediaSpecifics::Book(BookSpecifics {
pages: details.number_of_pages,
}),
specifics: MediaSpecifics::Book(BookSpecifics { pages: num_pages }),
})),
true => ImportOrExportItemIdentifier::NeedsDetails(identifier),
},
Expand Down
10 changes: 5 additions & 5 deletions apps/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ use tower_http::{

use crate::{
background::{
general_media_cleanup_jobs, general_user_cleanup, import_media,
recalculate_user_summary_job, update_exercise_job, update_metadata_job, user_created_job,
yank_integrations_data,
import_media, media_jobs, recalculate_user_summary_job, update_exercise_job,
update_metadata_job, user_created_job, user_jobs, yank_integrations_data,
},
config::get_app_config,
config::AppConfig,
Expand All @@ -64,6 +63,7 @@ mod integrations;
mod migrator;
mod miscellaneous;
mod models;
mod notification;
mod providers;
mod routes;
mod traits;
Expand Down Expand Up @@ -258,7 +258,7 @@ async fn main() -> Result<()> {
)
.layer(ApalisTraceLayer::new())
.layer(ApalisExtension(media_service_1.clone()))
.build_fn(general_user_cleanup)
.build_fn(user_jobs)
})
.register_with_count(1, move |c| {
WorkerBuilder::new(format!("general_media_cleanup_job-{c}"))
Expand All @@ -271,7 +271,7 @@ async fn main() -> Result<()> {
.layer(ApalisTraceLayer::new())
.layer(ApalisExtension(importer_service_2.clone()))
.layer(ApalisExtension(media_service_2.clone()))
.build_fn(general_media_cleanup_jobs)
.build_fn(media_jobs)
})
.register_with_count(1, move |c| {
WorkerBuilder::new(format!("yank_integrations_data-{c}"))
Expand Down
7 changes: 7 additions & 0 deletions apps/backend/src/migrator/m20230410_000001_create_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub enum Metadata {
PublishYear,
// the date which this media was released. Should take precedence if present
PublishDate,
// production status
ProductionStatus,
// all the images for this media item
Images,
// the unique identifier that is returned by the metadata provider
Expand Down Expand Up @@ -167,6 +169,11 @@ impl MigrationTrait for Migration {
)
.col(ColumnDef::new(Metadata::Title).string().not_null())
.col(ColumnDef::new(Metadata::Description).text())
.col(
ColumnDef::new(Metadata::ProductionStatus)
.string()
.not_null(),
)
.col(ColumnDef::new(Metadata::PublishYear).integer())
.col(ColumnDef::new(Metadata::PublishDate).date())
.col(ColumnDef::new(Metadata::Images).json())
Expand Down
12 changes: 12 additions & 0 deletions apps/backend/src/migrator/m20230417_000002_create_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ impl MigrationName for Migration {
/// - the user has it in their seen history
/// - added it to a collection
/// - has reviewed it
/// - added to their monitored media
#[derive(Iden)]
pub enum UserToMetadata {
Table,
UserId,
MetadataId,
LastUpdatedOn,
Monitored,
}

#[derive(
Expand All @@ -50,6 +52,8 @@ pub enum User {
YankIntegrations,
// This field can be `NULL` if the user has not enabled any sink integration
SinkIntegrations,
Notifications,
Summary,
}

#[async_trait::async_trait]
Expand All @@ -73,6 +77,8 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(User::Preferences).json().not_null())
.col(ColumnDef::new(User::YankIntegrations).json())
.col(ColumnDef::new(User::SinkIntegrations).json())
.col(ColumnDef::new(User::Notifications).json())
.col(ColumnDef::new(User::Summary).json())
.to_owned(),
)
.await?;
Expand All @@ -95,6 +101,12 @@ impl MigrationTrait for Migration {
.integer()
.not_null(),
)
.col(
ColumnDef::new(UserToMetadata::Monitored)
.boolean()
.default(false)
.not_null(),
)
.primary_key(
Index::create()
.name("pk-user_metadata")
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/src/migrator/m20230504_000005_create_summary.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FIXME: Remove this model completely.

use sea_orm_migration::prelude::*;

use crate::migrator::m20230417_000002_create_user::User;
Expand Down
Loading