Skip to content

Commit

Permalink
refactor(user): impl env for the fn
Browse files Browse the repository at this point in the history
  • Loading branch information
kKaskak committed Jan 13, 2025
1 parent dc08b17 commit b37d3e8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/types/profile/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DefaultOnError, DefaultOnNull, DurationSeconds, NoneAsEmptyString};

use crate::constants::NEW_USER_DAYS;
use crate::runtime::Env;

#[serde_as]
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -72,9 +73,11 @@ pub struct User {
pub gdpr_consent: GDPRConsent,
}

pub fn is_new_user(date_registered: DateTime<Utc>) -> bool {
let now = Utc::now();
let one_month = Duration::days(NEW_USER_DAYS);
impl User {
pub fn is_new_user<E: Env + 'static>(&self) -> bool {
let now = E::now();
let one_month = Duration::days(NEW_USER_DAYS);

now.signed_duration_since(date_registered) < one_month
now.signed_duration_since(self.date_registered) < one_month
}
}
4 changes: 2 additions & 2 deletions stremio-core-web/src/model/serialize_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ mod model {
use serde::Serialize;

use stremio_core::deep_links::SearchHistoryItemDeepLinks;
use stremio_core::types::profile::is_new_user;
use stremio_core::types::{
events::Events, notifications::NotificationItem, resource::MetaItemId,
};
use url::Url;

use crate::env::WebEnv;
use crate::model::deep_links_ext::DeepLinksExt;

#[derive(Serialize)]
Expand Down Expand Up @@ -89,7 +89,7 @@ mod model {
key: auth.key.clone(),
user: User {
user: &auth.user,
is_new_user: is_new_user(auth.user.date_registered),
is_new_user: auth.user.is_new_user::<WebEnv>(),
},
}),
},
Expand Down

0 comments on commit b37d3e8

Please sign in to comment.