Skip to content

Commit

Permalink
convert naive time to utc time
Browse files Browse the repository at this point in the history
  • Loading branch information
phiresky committed Jul 5, 2023
1 parent 2158621 commit 222d7cb
Show file tree
Hide file tree
Showing 57 changed files with 481 additions and 276 deletions.
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 crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ mod site;

#[async_trait::async_trait(?Send)]
pub trait Perform {
type Response: serde::ser::Serialize + Send;
type Response: serde::ser::Serialize + Send + Clone + Sync;

async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError>;
}
Expand Down
6 changes: 3 additions & 3 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
site::FederatedInstances,
};
use anyhow::Context;
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use futures::try_join;
use lemmy_db_schema::{
impls::person::is_banned,
Expand Down Expand Up @@ -164,7 +164,7 @@ pub async fn local_user_view_from_jwt_opt(

/// Checks if user's token was issued before user's password reset.
pub fn check_validator_time(
validator_time: &NaiveDateTime,
validator_time: &DateTime<Utc>,
claims: &Claims,
) -> Result<(), LemmyError> {
let user_validation_time = validator_time.timestamp();
Expand All @@ -177,7 +177,7 @@ pub fn check_validator_time(

pub fn check_user_valid(
banned: bool,
ban_expires: Option<NaiveDateTime>,
ban_expires: Option<DateTime<Utc>>,
deleted: bool,
) -> Result<(), LemmyError> {
// Check for a site ban
Expand Down
6 changes: 3 additions & 3 deletions crates/apub/src/activities/block/block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use activitypub_federation::{
traits::{ActivityHandler, Actor},
};
use anyhow::anyhow;
use chrono::NaiveDateTime;
use chrono::{DateTime, FixedOffset};
use lemmy_api_common::{
context::LemmyContext,
utils::{remove_user_data, remove_user_data_in_community},
Expand Down Expand Up @@ -48,7 +48,7 @@ impl BlockUser {
mod_: &ApubPerson,
remove_data: Option<bool>,
reason: Option<String>,
expires: Option<NaiveDateTime>,
expires: Option<DateTime<FixedOffset>>,
context: &Data<LemmyContext>,
) -> Result<BlockUser, LemmyError> {
let audience = if let SiteOrCommunity::Community(c) = target {
Expand Down Expand Up @@ -81,7 +81,7 @@ impl BlockUser {
mod_: &ApubPerson,
remove_data: bool,
reason: Option<String>,
expires: Option<NaiveDateTime>,
expires: Option<DateTime<FixedOffset>>,
context: &Data<LemmyContext>,
) -> Result<(), LemmyError> {
let block = BlockUser::new(
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/activities/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use activitypub_federation::{
fetch::object_id::ObjectId,
traits::{Actor, Object},
};
use chrono::NaiveDateTime;
use chrono::{DateTime, FixedOffset};
use lemmy_api_common::{
community::{BanFromCommunity, BanFromCommunityResponse},
context::LemmyContext,
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Object for SiteOrCommunity {
type Error = LemmyError;

#[tracing::instrument(skip_all)]
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<FixedOffset>> {
Some(match self {
SiteOrCommunity::Site(i) => i.last_refreshed_at,
SiteOrCommunity::Community(c) => c.last_refreshed_at,
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/fetcher/post_or_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
},
};
use activitypub_federation::{config::Data, traits::Object};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{
source::{community::Community, post::Post},
Expand Down Expand Up @@ -35,7 +35,7 @@ impl Object for PostOrComment {
type Kind = PageOrNote;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None
}

Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/fetcher/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use activitypub_federation::{
fetch::{object_id::ObjectId, webfinger::webfinger_resolve_actor},
traits::Object,
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::LemmyError;
use serde::Deserialize;
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Object for SearchableObjects {
type Kind = SearchableKinds;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
match self {
SearchableObjects::Person(p) => p.last_refreshed_at(),
SearchableObjects::Community(c) => c.last_refreshed_at(),
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/fetcher/user_or_community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use activitypub_federation::{
config::Data,
traits::{Actor, Object},
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::LemmyError;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -37,7 +37,7 @@ impl Object for UserOrCommunity {
type Kind = PersonOrGroup;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(match self {
UserOrCommunity::User(p) => p.last_refreshed_at,
UserOrCommunity::Community(p) => p.last_refreshed_at,
Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use activitypub_federation::{
protocol::{values::MediaTypeMarkdownOrHtml, verification::verify_domains_match},
traits::Object,
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
use lemmy_db_schema::{
source::{
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Object for ApubComment {
type Kind = Note;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None
}

Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use activitypub_federation::{
kinds::actor::GroupType,
traits::{Actor, Object},
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::{
context::LemmyContext,
utils::{generate_featured_url, generate_moderators_url, generate_outbox_url},
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Object for ApubCommunity {
type Kind = Group;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(self.last_refreshed_at)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use activitypub_federation::{
protocol::{values::MediaTypeHtml, verification::verify_domains_match},
traits::{Actor, Object},
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::{context::LemmyContext, utils::local_site_opt_to_slur_regex};
use lemmy_db_schema::{
newtypes::InstanceId,
Expand Down Expand Up @@ -61,7 +61,7 @@ impl Object for ApubSite {
type Kind = Instance;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(self.last_refreshed_at)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use activitypub_federation::{
protocol::verification::verify_domains_match,
traits::{Actor, Object},
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::{
context::LemmyContext,
utils::{generate_outbox_url, local_site_opt_to_slur_regex},
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Object for ApubPerson {
type Kind = Person;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(self.last_refreshed_at)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use activitypub_federation::{
traits::Object,
};
use anyhow::anyhow;
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use html2md::parse_html;
use lemmy_api_common::{
context::LemmyContext,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl Object for ApubPost {
type Kind = Page;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None
}

Expand Down
4 changes: 2 additions & 2 deletions crates/apub/src/objects/private_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use activitypub_federation::{
protocol::{values::MediaTypeHtml, verification::verify_domains_match},
traits::Object,
};
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use lemmy_api_common::{context::LemmyContext, utils::check_person_block};
use lemmy_db_schema::{
source::{
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Object for ApubPrivateMessage {
type Kind = ChatMessage;
type Error = LemmyError;

fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None
}

Expand Down
16 changes: 8 additions & 8 deletions crates/db_schema/src/aggregates/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::schema::{
use serde::{Deserialize, Serialize};
#[cfg(feature = "full")]
use ts_rs::TS;

use chrono::{DateTime, Utc};
#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
#[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))]
Expand All @@ -24,7 +24,7 @@ pub struct CommentAggregates {
pub score: i64,
pub upvotes: i64,
pub downvotes: i64,
pub published: chrono::NaiveDateTime,
pub published: DateTime<Utc>,
/// The total number of children in this comment branch.
pub child_count: i32,
pub hot_rank: i32,
Expand All @@ -45,7 +45,7 @@ pub struct CommunityAggregates {
pub subscribers: i64,
pub posts: i64,
pub comments: i64,
pub published: chrono::NaiveDateTime,
pub published: DateTime<Utc>,
/// The number of users with any activity in the last day.
pub users_active_day: i64,
/// The number of users with any activity in the last week.
Expand Down Expand Up @@ -85,11 +85,11 @@ pub struct PostAggregates {
pub score: i64,
pub upvotes: i64,
pub downvotes: i64,
pub published: chrono::NaiveDateTime,
pub published: DateTime<Utc>,
/// A newest comment time, limited to 2 days, to prevent necrobumping
pub newest_comment_time_necro: chrono::NaiveDateTime,
pub newest_comment_time_necro: DateTime<Utc>,
/// The time of the newest comment in the post.
pub newest_comment_time: chrono::NaiveDateTime,
pub newest_comment_time: DateTime<Utc>,
/// If the post is featured on the community.
pub featured_community: bool,
/// If the post is featured on the site / to local.
Expand All @@ -111,7 +111,7 @@ pub struct PersonPostAggregates {
///
/// This is updated to the current post comment count every time they view a post.
pub read_comments: i64,
pub published: chrono::NaiveDateTime,
pub published: DateTime<Utc>,
}

#[derive(Clone, Default)]
Expand All @@ -121,7 +121,7 @@ pub struct PersonPostAggregatesForm {
pub person_id: PersonId,
pub post_id: PostId,
pub read_comments: i64,
pub published: Option<chrono::NaiveDateTime>,
pub published: Option<DateTime<Utc>>,
}

#[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/db_schema/src/diesel_ltree.patch
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ index 255c6422..f2ccf5e2 100644
#[derive(diesel::sql_types::SqlType)]
#[diesel(postgres_type(name = "sort_type_enum"))]
@@ -76,13 +76,13 @@ diesel::table! {
published -> Timestamp,
published -> Timestamptz,
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/db_schema/src/impls/email_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use diesel::{
insert_into,
result::Error,
ExpressionMethods,
QueryDsl,
QueryDsl, IntoSql, sql_types::Timestamptz,
};
use diesel_async::RunQueryDsl;

Expand All @@ -31,7 +31,7 @@ impl EmailVerification {
let conn = &mut get_conn(pool).await?;
email_verification
.filter(verification_token.eq(token))
.filter(published.gt(now - 7.days()))
.filter(published.gt(now.into_sql::<Timestamptz>() - 7.days()))
.first::<Self>(conn)
.await
}
Expand Down
7 changes: 4 additions & 3 deletions crates/db_schema/src/impls/password_reset_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use diesel::{
dsl::{insert_into, now, IntervalDsl},
result::Error,
ExpressionMethods,
QueryDsl,
QueryDsl, sql_types::Timestamptz, IntoSql,
};
use diesel_async::RunQueryDsl;
use sha2::{Digest, Sha256};
use chrono::{DateTime, Utc};

#[async_trait]
impl Crud for PasswordResetRequest {
Expand Down Expand Up @@ -75,7 +76,7 @@ impl PasswordResetRequest {
let token_hash: String = bytes_to_hex(hasher.finalize().to_vec());
password_reset_request
.filter(token_encrypted.eq(token_hash))
.filter(published.gt(now - 1.days()))
.filter(published.gt(now.into_sql::<Timestamptz>() - 1.days()))
.first::<Self>(conn)
.await
}
Expand All @@ -87,7 +88,7 @@ impl PasswordResetRequest {
let conn = &mut get_conn(pool).await?;
password_reset_request
.filter(local_user_id.eq(user_id))
.filter(published.gt(now - 1.days()))
.filter(published.gt(now.into_sql::<Timestamptz>() - 1.days()))
.count()
.get_result(conn)
.await
Expand Down
5 changes: 3 additions & 2 deletions crates/db_schema/src/impls/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use crate::{
utils::{functions::lower, get_conn, naive_now, DbPool},
};
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
use diesel_async::RunQueryDsl;
use diesel_async::RunQueryDsl;use chrono::{DateTime, Utc};


#[async_trait]
impl Crud for Person {
Expand Down Expand Up @@ -94,7 +95,7 @@ impl Person {
}
}

pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool {
pub fn is_banned(banned_: bool, expires: Option<DateTime<Utc>>) -> bool {
if let Some(expires) = expires {
banned_ && expires.gt(&naive_now())
} else {
Expand Down
Loading

0 comments on commit 222d7cb

Please sign in to comment.