diff --git a/Cargo.toml b/Cargo.toml index 807e24e3f..79fb5ca1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -123,7 +123,10 @@ reqwest-tracing = "0.5.3" clokwerk = "0.4.0" doku = { version = "0.21.1", features = ["url-2"] } bcrypt = "0.15.1" -chrono = { version = "0.4.38", features = ["serde"], default-features = false } +chrono = { version = "0.4.38", features = [ + "serde", + "now", +], default-features = false } serde_json = { version = "1.0.121", features = ["preserve_order"] } base64 = "0.22.1" uuid = { version = "1.10.0", features = ["serde", "v4"] } diff --git a/crates/api/src/post/like.rs b/crates/api/src/post/like.rs index e70213765..031e3f0db 100644 --- a/crates/api/src/post/like.rs +++ b/crates/api/src/post/like.rs @@ -10,7 +10,7 @@ use lemmy_api_common::{ use lemmy_db_schema::{ source::{ local_site::LocalSite, - post::{PostLike, PostLikeForm, PostRead}, + post::{PostLike, PostLikeForm, PostRead, PostReadForm}, }, traits::Likeable, }; @@ -47,11 +47,7 @@ pub async fn like_post( ) .await?; - let like_form = PostLikeForm { - post_id: data.post_id, - person_id: local_user_view.person.id, - score: data.score, - }; + let like_form = PostLikeForm::new(data.post_id, local_user_view.person.id, data.score); // Remove any likes first let person_id = local_user_view.person.id; @@ -67,7 +63,8 @@ pub async fn like_post( } // Mark Post Read - PostRead::mark_as_read(&mut context.pool(), post_id, person_id).await?; + let read_form = PostReadForm::new(post_id, person_id); + PostRead::mark_as_read(&mut context.pool(), &read_form).await?; ActivityChannel::submit_activity( SendActivityData::LikePostOrComment { diff --git a/crates/api/src/post/mark_read.rs b/crates/api/src/post/mark_read.rs index def7656b1..2d3284375 100644 --- a/crates/api/src/post/mark_read.rs +++ b/crates/api/src/post/mark_read.rs @@ -3,7 +3,7 @@ use lemmy_api_common::{ context::LemmyContext, post::{MarkPostAsRead, PostResponse}, }; -use lemmy_db_schema::source::post::PostRead; +use lemmy_db_schema::source::post::{PostRead, PostReadForm}; use lemmy_db_views::structs::{LocalUserView, PostView}; use lemmy_utils::error::LemmyResult; @@ -17,10 +17,11 @@ pub async fn mark_post_as_read( let post_id = data.post_id; // Mark the post as read / unread + let form = PostReadForm::new(post_id, person_id); if data.read { - PostRead::mark_as_read(&mut context.pool(), post_id, person_id).await?; + PostRead::mark_as_read(&mut context.pool(), &form).await?; } else { - PostRead::mark_as_unread(&mut context.pool(), post_id, person_id).await?; + PostRead::mark_as_unread(&mut context.pool(), &form).await?; } let post_view = PostView::read( &mut context.pool(), diff --git a/crates/api/src/post/save.rs b/crates/api/src/post/save.rs index 4a382e732..cebbd7fd5 100644 --- a/crates/api/src/post/save.rs +++ b/crates/api/src/post/save.rs @@ -4,7 +4,7 @@ use lemmy_api_common::{ post::{PostResponse, SavePost}, }; use lemmy_db_schema::{ - source::post::{PostRead, PostSaved, PostSavedForm}, + source::post::{PostRead, PostReadForm, PostSaved, PostSavedForm}, traits::Saveable, }; use lemmy_db_views::structs::{LocalUserView, PostView}; @@ -16,10 +16,7 @@ pub async fn save_post( context: Data, local_user_view: LocalUserView, ) -> LemmyResult> { - let post_saved_form = PostSavedForm { - post_id: data.post_id, - person_id: local_user_view.person.id, - }; + let post_saved_form = PostSavedForm::new(data.post_id, local_user_view.person.id); if data.save { PostSaved::save(&mut context.pool(), &post_saved_form) @@ -41,7 +38,8 @@ pub async fn save_post( ) .await?; - PostRead::mark_as_read(&mut context.pool(), post_id, person_id).await?; + let read_form = PostReadForm::new(post_id, person_id); + PostRead::mark_as_read(&mut context.pool(), &read_form).await?; Ok(Json(PostResponse { post_view })) } diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index 85ee9bff0..1af026204 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -1,5 +1,6 @@ use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ build_response::{build_comment_response, send_local_notifs}, comment::{CommentResponse, EditComment}, @@ -19,7 +20,6 @@ use lemmy_db_schema::{ local_site::LocalSite, }, traits::Crud, - utils::naive_now, }; use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_utils::{ @@ -74,7 +74,7 @@ pub async fn update_comment( let form = CommentUpdateForm { content, language_id: Some(language_id), - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), ..Default::default() }; let updated_comment = Comment::update(&mut context.pool(), comment_id, &form) diff --git a/crates/api_crud/src/community/update.rs b/crates/api_crud/src/community/update.rs index 3dca7d892..d9c062c53 100644 --- a/crates/api_crud/src/community/update.rs +++ b/crates/api_crud/src/community/update.rs @@ -1,6 +1,7 @@ use super::check_community_visibility_allowed; use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ build_response::build_community_response, community::{CommunityResponse, EditCommunity}, @@ -22,7 +23,7 @@ use lemmy_db_schema::{ local_site::LocalSite, }, traits::Crud, - utils::{diesel_string_update, diesel_url_update, naive_now}, + utils::{diesel_string_update, diesel_url_update}, }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ @@ -95,7 +96,7 @@ pub async fn update_community( nsfw: data.nsfw, posting_restricted_to_mods: data.posting_restricted_to_mods, visibility: data.visibility, - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), ..Default::default() }; diff --git a/crates/api_crud/src/oauth_provider/update.rs b/crates/api_crud/src/oauth_provider/update.rs index b4734bf36..29ba19b49 100644 --- a/crates/api_crud/src/oauth_provider/update.rs +++ b/crates/api_crud/src/oauth_provider/update.rs @@ -1,10 +1,11 @@ use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{context::LemmyContext, oauth_provider::EditOAuthProvider, utils::is_admin}; use lemmy_db_schema::{ source::oauth_provider::{OAuthProvider, OAuthProviderUpdateForm}, traits::Crud, - utils::{diesel_required_string_update, diesel_required_url_update, naive_now}, + utils::{diesel_required_string_update, diesel_required_url_update}, }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::LemmyError; @@ -32,7 +33,7 @@ pub async fn update_oauth_provider( auto_verify_email: data.auto_verify_email, account_linking_enabled: data.account_linking_enabled, enabled: data.enabled, - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), }; let update_result = diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 6dc847086..948a7617e 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -20,7 +20,7 @@ use lemmy_db_schema::{ source::{ community::Community, local_site::LocalSite, - post::{Post, PostInsertForm, PostLike, PostLikeForm, PostRead}, + post::{Post, PostInsertForm, PostLike, PostLikeForm, PostRead, PostReadForm}, }, traits::{Crud, Likeable}, utils::diesel_url_create, @@ -142,17 +142,14 @@ pub async fn create_post( // They like their own post by default let person_id = local_user_view.person.id; let post_id = inserted_post.id; - let like_form = PostLikeForm { - post_id, - person_id, - score: 1, - }; + let like_form = PostLikeForm::new(post_id, person_id, 1); PostLike::like(&mut context.pool(), &like_form) .await .with_lemmy_type(LemmyErrorType::CouldntLikePost)?; - PostRead::mark_as_read(&mut context.pool(), post_id, person_id).await?; + let read_form = PostReadForm::new(post_id, person_id); + PostRead::mark_as_read(&mut context.pool(), &read_form).await?; build_post_response(&context, community_id, local_user_view, post_id).await } diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index f3c2e1fa6..3b6ef9414 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -7,7 +7,7 @@ use lemmy_api_common::{ use lemmy_db_schema::{ source::{ comment::Comment, - post::{Post, PostRead}, + post::{Post, PostRead, PostReadForm}, }, traits::Crud, }; @@ -65,7 +65,8 @@ pub async fn get_post( let post_id = post_view.post.id; if let Some(person_id) = person_id { - PostRead::mark_as_read(&mut context.pool(), post_id, person_id).await?; + let read_form = PostReadForm::new(post_id, person_id); + PostRead::mark_as_read(&mut context.pool(), &read_form).await?; update_read_comments( person_id, diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 217a6cc24..24bbed009 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -1,6 +1,7 @@ use super::{convert_published_time, create::send_webmention}; use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ build_response::build_post_response, context::LemmyContext, @@ -22,7 +23,7 @@ use lemmy_db_schema::{ post::{Post, PostUpdateForm}, }, traits::Crud, - utils::{diesel_string_update, diesel_url_update, naive_now}, + utils::{diesel_string_update, diesel_url_update}, }; use lemmy_db_views::structs::{LocalUserView, PostView}; use lemmy_utils::{ @@ -131,7 +132,7 @@ pub async fn update_post( alt_text, nsfw: data.nsfw, language_id: Some(language_id), - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), scheduled_publish_time, ..Default::default() }; diff --git a/crates/api_crud/src/private_message/update.rs b/crates/api_crud/src/private_message/update.rs index aa562c626..b9e4785ef 100644 --- a/crates/api_crud/src/private_message/update.rs +++ b/crates/api_crud/src/private_message/update.rs @@ -1,5 +1,6 @@ use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ context::LemmyContext, private_message::{EditPrivateMessage, PrivateMessageResponse}, @@ -12,7 +13,6 @@ use lemmy_db_schema::{ private_message::{PrivateMessage, PrivateMessageUpdateForm}, }, traits::Crud, - utils::naive_now, }; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_utils::{ @@ -47,7 +47,7 @@ pub async fn update_private_message( private_message_id, &PrivateMessageUpdateForm { content: Some(content), - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), ..Default::default() }, ) diff --git a/crates/api_crud/src/site/create.rs b/crates/api_crud/src/site/create.rs index e1ea1d992..b92cf980c 100644 --- a/crates/api_crud/src/site/create.rs +++ b/crates/api_crud/src/site/create.rs @@ -2,6 +2,7 @@ use super::not_zero; use crate::site::{application_question_check, site_default_post_listing_type_check}; use activitypub_federation::{config::Data, http_signatures::generate_actor_keypair}; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ context::LemmyContext, site::{CreateSite, SiteResponse}, @@ -23,7 +24,7 @@ use lemmy_db_schema::{ site::{Site, SiteUpdateForm}, }, traits::Crud, - utils::{diesel_string_update, diesel_url_create, naive_now}, + utils::{diesel_string_update, diesel_url_create}, }; use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_utils::{ @@ -75,7 +76,7 @@ pub async fn create_site( icon: Some(icon), banner: Some(banner), actor_id: Some(actor_id), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), inbox_url, private_key: Some(Some(keypair.private_key)), public_key: Some(keypair.public_key), @@ -102,7 +103,7 @@ pub async fn create_site( legal_information: diesel_string_update(data.legal_information.as_deref()), application_email_admins: data.application_email_admins, hide_modlog_mod_names: data.hide_modlog_mod_names, - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), slur_filter_regex: diesel_string_update(data.slur_filter_regex.as_deref()), actor_name_max_length: data.actor_name_max_length, federation_enabled: data.federation_enabled, diff --git a/crates/api_crud/src/site/update.rs b/crates/api_crud/src/site/update.rs index 085ed69d1..5d1e6aa86 100644 --- a/crates/api_crud/src/site/update.rs +++ b/crates/api_crud/src/site/update.rs @@ -2,6 +2,7 @@ use super::not_zero; use crate::site::{application_question_check, site_default_post_listing_type_check}; use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ context::LemmyContext, request::replace_image, @@ -27,7 +28,7 @@ use lemmy_db_schema::{ site::{Site, SiteUpdateForm}, }, traits::Crud, - utils::{diesel_string_update, diesel_url_update, naive_now}, + utils::{diesel_string_update, diesel_url_update}, RegistrationMode, }; use lemmy_db_views::structs::{LocalUserView, SiteView}; @@ -88,7 +89,7 @@ pub async fn update_site( icon, banner, content_warning: diesel_string_update(data.content_warning.as_deref()), - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), ..Default::default() }; @@ -111,7 +112,7 @@ pub async fn update_site( legal_information: diesel_string_update(data.legal_information.as_deref()), application_email_admins: data.application_email_admins, hide_modlog_mod_names: data.hide_modlog_mod_names, - updated: Some(Some(naive_now())), + updated: Some(Some(Utc::now())), slur_filter_regex: diesel_string_update(data.slur_filter_regex.as_deref()), actor_name_max_length: data.actor_name_max_length, federation_enabled: data.federation_enabled, diff --git a/crates/api_crud/src/tagline/update.rs b/crates/api_crud/src/tagline/update.rs index 043589d26..30b7d4370 100644 --- a/crates/api_crud/src/tagline/update.rs +++ b/crates/api_crud/src/tagline/update.rs @@ -1,5 +1,6 @@ use activitypub_federation::config::Data; use actix_web::web::Json; +use chrono::Utc; use lemmy_api_common::{ context::LemmyContext, tagline::{TaglineResponse, UpdateTagline}, @@ -11,7 +12,6 @@ use lemmy_db_schema::{ tagline::{Tagline, TaglineUpdateForm}, }, traits::Crud, - utils::naive_now, }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::error::LemmyError; @@ -33,7 +33,7 @@ pub async fn update_tagline( let tagline_form = TaglineUpdateForm { content, - updated: naive_now(), + updated: Utc::now(), }; let tagline = Tagline::update(&mut context.pool(), data.id, &tagline_form).await?; diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 85be94246..fadf918bd 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -17,6 +17,7 @@ use activitypub_federation::{ kinds::activity::UpdateType, traits::{ActivityHandler, Actor, Object}, }; +use chrono::Utc; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ source::{ @@ -25,7 +26,6 @@ use lemmy_db_schema::{ person::Person, }, traits::Crud, - utils::naive_now, }; use lemmy_utils::error::{LemmyError, LemmyResult}; use url::Url; @@ -103,7 +103,7 @@ impl ActivityHandler for UpdateCommunity { nsfw: Some(self.object.sensitive.unwrap_or(false)), actor_id: Some(self.object.id.into()), public_key: Some(self.object.public_key.public_key_pem), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), icon: Some(self.object.icon.map(|i| i.url.into())), banner: Some(self.object.image.map(|i| i.url.into())), followers_url: self.object.followers.map(Into::into), diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index d0cf17a51..832b2da6d 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -118,11 +118,7 @@ impl ActivityHandler for CreateOrUpdatePage { let post = ApubPost::from_json(self.object, context).await?; // author likes their own post by default - let like_form = PostLikeForm { - post_id: post.id, - person_id: post.creator_id, - score: 1, - }; + let like_form = PostLikeForm::new(post.id, post.creator_id, 1); PostLike::like(&mut context.pool(), &like_form).await?; // Calculate initial hot_rank for post diff --git a/crates/apub/src/activities/voting/mod.rs b/crates/apub/src/activities/voting/mod.rs index 7c39b2246..5cda291eb 100644 --- a/crates/apub/src/activities/voting/mod.rs +++ b/crates/apub/src/activities/voting/mod.rs @@ -79,11 +79,7 @@ async fn vote_post( context: &Data, ) -> LemmyResult<()> { let post_id = post.id; - let like_form = PostLikeForm { - post_id: post.id, - person_id: actor.id, - score: vote_type.into(), - }; + let like_form = PostLikeForm::new(post.id, actor.id, vote_type.into()); let person_id = actor.id; PostLike::remove(&mut context.pool(), person_id, post_id).await?; PostLike::like(&mut context.pool(), &like_form).await?; diff --git a/crates/apub/src/api/user_settings_backup.rs b/crates/apub/src/api/user_settings_backup.rs index 601ba8664..d5a864bec 100644 --- a/crates/apub/src/api/user_settings_backup.rs +++ b/crates/apub/src/api/user_settings_backup.rs @@ -200,10 +200,7 @@ pub async fn import_settings( &context, |(saved, context)| async move { let post = saved.dereference(&context).await?; - let form = PostSavedForm { - person_id, - post_id: post.id, - }; + let form = PostSavedForm::new(post.id, person_id); PostSaved::save(&mut context.pool(), &form).await?; LemmyResult::Ok(()) }, diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index b7c6a5f51..dc0721404 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -30,7 +30,6 @@ use lemmy_db_schema::{ post::Post, }, traits::Crud, - utils::naive_now, }; use lemmy_utils::{ error::{FederationError, LemmyError, LemmyResult}, @@ -204,7 +203,7 @@ impl Object for ApubComment { language_id, }; let parent_comment_path = parent_comment.map(|t| t.0.path); - let timestamp: DateTime = note.updated.or(note.published).unwrap_or_else(naive_now); + let timestamp: DateTime = note.updated.or(note.published).unwrap_or_else(Utc::now); let comment = Comment::insert_apub( &mut context.pool(), Some(timestamp), diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 2a9abc939..689641910 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -38,7 +38,6 @@ use lemmy_db_schema::{ local_site::LocalSite, }, traits::{ApubActor, Crud}, - utils::naive_now, CommunityVisibility, }; use lemmy_db_views_actor::structs::CommunityFollowerView; @@ -166,7 +165,7 @@ impl Object for ApubCommunity { nsfw: Some(group.sensitive.unwrap_or(false)), actor_id: Some(group.id.into()), local: Some(false), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), icon, banner, sidebar, @@ -193,7 +192,7 @@ impl Object for ApubCommunity { let languages = LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?; - let timestamp = group.updated.or(group.published).unwrap_or_else(naive_now); + let timestamp = group.updated.or(group.published).unwrap_or_else(Utc::now); let community: ApubCommunity = Community::insert_apub(&mut context.pool(), timestamp, &form) .await? .into(); diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index a123c85ba..754172fe2 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -39,7 +39,6 @@ use lemmy_db_schema::{ site::{Site, SiteInsertForm}, }, traits::Crud, - utils::naive_now, }; use lemmy_utils::{ error::{FederationError, LemmyError, LemmyResult}, @@ -163,7 +162,7 @@ impl Object for ApubSite { banner, description: apub.summary, actor_id: Some(apub.id.clone().into()), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), inbox_url: Some(apub.inbox.clone().into()), public_key: Some(apub.public_key.public_key_pem.clone()), private_key: None, diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 737579662..97b83c194 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -35,7 +35,6 @@ use lemmy_db_schema::{ person::{Person as DbPerson, PersonInsertForm, PersonUpdateForm}, }, traits::{ApubActor, Crud}, - utils::naive_now, }; use lemmy_utils::{ error::{LemmyError, LemmyResult}, @@ -176,7 +175,7 @@ impl Object for ApubPerson { bot_account: Some(person.kind == UserTypes::Service), private_key: None, public_key: person.public_key.public_key_pem, - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), inbox_url: Some( person .endpoints diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index b72fa1728..bcd1dbf8e 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -35,7 +35,6 @@ use lemmy_db_schema::{ post::{Post, PostInsertForm, PostUpdateForm}, }, traits::Crud, - utils::naive_now, }; use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_utils::{ @@ -260,7 +259,7 @@ impl Object for ApubPost { ..PostInsertForm::new(name, creator.id, community.id) }; - let timestamp = page.updated.or(page.published).unwrap_or_else(naive_now); + let timestamp = page.updated.or(page.published).unwrap_or_else(Utc::now); let post = Post::insert_apub(&mut context.pool(), timestamp, &form).await?; let post_ = post.clone(); let context_ = context.reset_request_count(); diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index f3a9f140c..9ada5f657 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -31,7 +31,6 @@ use lemmy_db_schema::{ private_message::{PrivateMessage, PrivateMessageInsertForm}, }, traits::Crud, - utils::naive_now, }; use lemmy_db_views::structs::LocalUserView; use lemmy_utils::{ @@ -161,7 +160,7 @@ impl Object for ApubPrivateMessage { ap_id: Some(note.id.into()), local: Some(false), }; - let timestamp = note.updated.or(note.published).unwrap_or_else(naive_now); + let timestamp = note.updated.or(note.published).unwrap_or_else(Utc::now); let pm = PrivateMessage::insert_apub(&mut context.pool(), timestamp, &form).await?; Ok(pm.into()) } diff --git a/crates/db_schema/src/aggregates/person_aggregates.rs b/crates/db_schema/src/aggregates/person_aggregates.rs index 62aa9b609..df7004d0e 100644 --- a/crates/db_schema/src/aggregates/person_aggregates.rs +++ b/crates/db_schema/src/aggregates/person_aggregates.rs @@ -65,11 +65,7 @@ mod tests { ); let inserted_post = Post::create(pool, &new_post).await?; - let post_like = PostLikeForm { - post_id: inserted_post.id, - person_id: inserted_person.id, - score: 1, - }; + let post_like = PostLikeForm::new(inserted_post.id, inserted_person.id, 1); let _inserted_post_like = PostLike::like(pool, &post_like).await?; let comment_form = CommentInsertForm::new( diff --git a/crates/db_schema/src/aggregates/post_aggregates.rs b/crates/db_schema/src/aggregates/post_aggregates.rs index 46747b076..c11ea6e05 100644 --- a/crates/db_schema/src/aggregates/post_aggregates.rs +++ b/crates/db_schema/src/aggregates/post_aggregates.rs @@ -113,11 +113,7 @@ mod tests { let inserted_child_comment = Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?; - let post_like = PostLikeForm { - post_id: inserted_post.id, - person_id: inserted_person.id, - score: 1, - }; + let post_like = PostLikeForm::new(inserted_post.id, inserted_person.id, 1); PostLike::like(pool, &post_like).await?; @@ -129,11 +125,7 @@ mod tests { assert_eq!(0, post_aggs_before_delete.downvotes); // Add a post dislike from the other person - let post_dislike = PostLikeForm { - post_id: inserted_post.id, - person_id: another_inserted_person.id, - score: -1, - }; + let post_dislike = PostLikeForm::new(inserted_post.id, another_inserted_person.id, -1); PostLike::like(pool, &post_dislike).await?; diff --git a/crates/db_schema/src/impls/comment.rs b/crates/db_schema/src/impls/comment.rs index 96ec70fa2..7dcc033a1 100644 --- a/crates/db_schema/src/impls/comment.rs +++ b/crates/db_schema/src/impls/comment.rs @@ -12,15 +12,7 @@ use crate::{ CommentUpdateForm, }, traits::{Crud, Likeable, Saveable}, - utils::{ - functions::coalesce, - get_conn, - naive_now, - now, - uplete, - DbPool, - DELETED_REPLACEMENT_TEXT, - }, + utils::{functions::coalesce, get_conn, now, uplete, DbPool, DELETED_REPLACEMENT_TEXT}, }; use chrono::{DateTime, Utc}; use diesel::{ @@ -46,7 +38,7 @@ impl Comment { .set(( comment::content.eq(DELETED_REPLACEMENT_TEXT), comment::deleted.eq(true), - comment::updated.eq(naive_now()), + comment::updated.eq(Utc::now()), )) .get_results::(conn) .await @@ -61,7 +53,7 @@ impl Comment { diesel::update(comment::table.filter(comment::creator_id.eq(for_creator_id))) .set(( comment::removed.eq(removed), - comment::updated.eq(naive_now()), + comment::updated.eq(Utc::now()), )) .get_results::(conn) .await diff --git a/crates/db_schema/src/impls/comment_report.rs b/crates/db_schema/src/impls/comment_report.rs index 19c12876f..4c6a1e0d0 100644 --- a/crates/db_schema/src/impls/comment_report.rs +++ b/crates/db_schema/src/impls/comment_report.rs @@ -6,8 +6,9 @@ use crate::{ }, source::comment_report::{CommentReport, CommentReportForm}, traits::Reportable, - utils::{get_conn, naive_now, DbPool}, + utils::{get_conn, DbPool}, }; +use chrono::Utc; use diesel::{ dsl::{insert_into, update}, result::Error, @@ -51,7 +52,7 @@ impl Reportable for CommentReport { .set(( resolved.eq(true), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await @@ -67,7 +68,7 @@ impl Reportable for CommentReport { .set(( resolved.eq(true), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await @@ -88,7 +89,7 @@ impl Reportable for CommentReport { .set(( resolved.eq(false), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await diff --git a/crates/db_schema/src/impls/instance.rs b/crates/db_schema/src/impls/instance.rs index 6c72b5e18..d638786fe 100644 --- a/crates/db_schema/src/impls/instance.rs +++ b/crates/db_schema/src/impls/instance.rs @@ -16,11 +16,11 @@ use crate::{ utils::{ functions::{coalesce, lower}, get_conn, - naive_now, now, DbPool, }, }; +use chrono::Utc; use diesel::{ dsl::{count_star, insert_into}, result::Error, @@ -52,7 +52,7 @@ impl Instance { None => { // Instance not in database yet, insert it let form = InstanceForm { - updated: Some(naive_now()), + updated: Some(Utc::now()), ..InstanceForm::new(domain_) }; insert_into(instance::table) diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 3ae355b87..fb8c96f04 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -10,8 +10,9 @@ use crate::{ PersonUpdateForm, }, traits::{ApubActor, Crud, Followable}, - utils::{action_query, functions::lower, get_conn, naive_now, now, uplete, DbPool}, + utils::{action_query, functions::lower, get_conn, now, uplete, DbPool}, }; +use chrono::Utc; use diesel::{ dsl::{insert_into, not}, expression::SelectableHelper, @@ -93,7 +94,7 @@ impl Person { person::bio.eq::>(None), person::matrix_user_id.eq::>(None), person::deleted.eq(true), - person::updated.eq(naive_now()), + person::updated.eq(Utc::now()), )) .get_result::(conn) .await diff --git a/crates/db_schema/src/impls/post.rs b/crates/db_schema/src/impls/post.rs index e60cd3a2b..6ecb5cebd 100644 --- a/crates/db_schema/src/impls/post.rs +++ b/crates/db_schema/src/impls/post.rs @@ -1,5 +1,5 @@ use crate::{ - diesel::{BoolExpressionMethods, OptionalExtension}, + diesel::{BoolExpressionMethods, NullableExpressionMethods, OptionalExtension}, newtypes::{CommunityId, DbUrl, PersonId, PostId}, schema::{community, person, post, post_actions}, source::post::{ @@ -19,7 +19,6 @@ use crate::{ utils::{ functions::coalesce, get_conn, - naive_now, now, uplete, DbPool, @@ -37,7 +36,6 @@ use diesel::{ result::Error, DecoratableTarget, ExpressionMethods, - NullableExpressionMethods, QueryDsl, TextExpressionMethods, }; @@ -138,7 +136,7 @@ impl Post { post::url.eq(Option::<&str>::None), post::body.eq(DELETED_REPLACEMENT_TEXT), post::deleted.eq(true), - post::updated.eq(naive_now()), + post::updated.eq(Utc::now()), )) .get_results::(conn) .await @@ -160,7 +158,7 @@ impl Post { } update - .set((post::removed.eq(removed), post::updated.eq(naive_now()))) + .set((post::removed.eq(removed), post::updated.eq(Utc::now()))) .get_results::(conn) .await } @@ -281,7 +279,6 @@ impl Likeable for PostLike { type IdType = PostId; async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result { let conn = &mut get_conn(pool).await?; - let post_like_form = (post_like_form, post_actions::liked.eq(now().nullable())); insert_into(post_actions::table) .values(post_like_form) .on_conflict((post_actions::post_id, post_actions::person_id)) @@ -310,7 +307,6 @@ impl Saveable for PostSaved { type Form = PostSavedForm; async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result { let conn = &mut get_conn(pool).await?; - let post_saved_form = (post_saved_form, post_actions::saved.eq(now().nullable())); insert_into(post_actions::table) .values(post_saved_form) .on_conflict((post_actions::post_id, post_actions::person_id)) @@ -335,28 +331,25 @@ impl Saveable for PostSaved { impl PostRead { pub async fn mark_as_read( pool: &mut DbPool<'_>, - post_id: PostId, - person_id: PersonId, + post_read_form: &PostReadForm, ) -> LemmyResult { - Self::mark_many_as_read(pool, &[post_id], person_id).await + Self::mark_many_as_read(pool, &[post_read_form.post_id], post_read_form.person_id).await } pub async fn mark_as_unread( pool: &mut DbPool<'_>, - post_id_: PostId, - person_id_: PersonId, - ) -> LemmyResult { + post_read_form: &PostReadForm, + ) -> Result { let conn = &mut get_conn(pool).await?; uplete::new( post_actions::table - .filter(post_actions::post_id.eq(post_id_)) - .filter(post_actions::person_id.eq(person_id_)), + .filter(post_actions::post_id.eq(post_read_form.post_id)) + .filter(post_actions::person_id.eq(post_read_form.person_id)), ) .set_null(post_actions::read) .get_result(conn) .await - .with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead) } pub async fn mark_many_as_read( @@ -368,16 +361,9 @@ impl PostRead { let forms = post_ids .iter() - .map(|post_id| { - ( - PostReadForm { - post_id: *post_id, - person_id, - }, - post_actions::read.eq(now().nullable()), - ) - }) + .map(|post_id| (PostReadForm::new(*post_id, person_id))) .collect::>(); + insert_into(post_actions::table) .values(forms) .on_conflict((post_actions::person_id, post_actions::post_id)) @@ -397,10 +383,7 @@ impl PostHide { ) -> Result { let conn = &mut get_conn(pool).await?; - let form = ( - &PostHideForm { post_id, person_id }, - post_actions::hidden.eq(now().nullable()), - ); + let form = &PostHideForm::new(post_id, person_id); insert_into(post_actions::table) .values(form) .on_conflict((post_actions::person_id, post_actions::post_id)) @@ -442,6 +425,7 @@ mod tests { PostLike, PostLikeForm, PostRead, + PostReadForm, PostSaved, PostSavedForm, PostUpdateForm, @@ -525,11 +509,7 @@ mod tests { }; // Post Like - let post_like_form = PostLikeForm { - post_id: inserted_post.id, - person_id: inserted_person.id, - score: 1, - }; + let post_like_form = PostLikeForm::new(inserted_post.id, inserted_person.id, 1); let inserted_post_like = PostLike::like(pool, &post_like_form).await?; @@ -541,10 +521,7 @@ mod tests { }; // Post Save - let post_saved_form = PostSavedForm { - post_id: inserted_post.id, - person_id: inserted_person.id, - }; + let post_saved_form = PostSavedForm::new(inserted_post.id, inserted_person.id); let inserted_post_saved = PostSaved::save(pool, &post_saved_form).await?; @@ -555,8 +532,10 @@ mod tests { }; // Mark 2 posts as read - PostRead::mark_as_read(pool, inserted_post.id, inserted_person.id).await?; - PostRead::mark_as_read(pool, inserted_post2.id, inserted_person.id).await?; + let post_read_form_1 = PostReadForm::new(inserted_post.id, inserted_person.id); + PostRead::mark_as_read(pool, &post_read_form_1).await?; + let post_read_form_2 = PostReadForm::new(inserted_post2.id, inserted_person.id); + PostRead::mark_as_read(pool, &post_read_form_2).await?; let read_post = Post::read(pool, inserted_post.id).await?; @@ -575,12 +554,12 @@ mod tests { let saved_removed = PostSaved::unsave(pool, &post_saved_form).await?; assert_eq!(uplete::Count::only_updated(1), saved_removed); - let read_removed_1 = - PostRead::mark_as_unread(pool, inserted_post.id, inserted_person.id).await?; + let read_remove_form_1 = PostReadForm::new(inserted_post.id, inserted_person.id); + let read_removed_1 = PostRead::mark_as_unread(pool, &read_remove_form_1).await?; assert_eq!(uplete::Count::only_deleted(1), read_removed_1); - let read_removed_2 = - PostRead::mark_as_unread(pool, inserted_post2.id, inserted_person.id).await?; + let read_remove_form_2 = PostReadForm::new(inserted_post2.id, inserted_person.id); + let read_removed_2 = PostRead::mark_as_unread(pool, &read_remove_form_2).await?; assert_eq!(uplete::Count::only_deleted(1), read_removed_2); let num_deleted = Post::delete(pool, inserted_post.id).await? diff --git a/crates/db_schema/src/impls/post_report.rs b/crates/db_schema/src/impls/post_report.rs index e7d27aee9..90ac030c1 100644 --- a/crates/db_schema/src/impls/post_report.rs +++ b/crates/db_schema/src/impls/post_report.rs @@ -6,8 +6,9 @@ use crate::{ }, source::post_report::{PostReport, PostReportForm}, traits::Reportable, - utils::{get_conn, naive_now, DbPool}, + utils::{get_conn, DbPool}, }; +use chrono::Utc; use diesel::{ dsl::{insert_into, update}, result::Error, @@ -40,7 +41,7 @@ impl Reportable for PostReport { .set(( resolved.eq(true), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await @@ -56,7 +57,7 @@ impl Reportable for PostReport { .set(( resolved.eq(true), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await @@ -72,7 +73,7 @@ impl Reportable for PostReport { .set(( resolved.eq(false), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await diff --git a/crates/db_schema/src/impls/private_message_report.rs b/crates/db_schema/src/impls/private_message_report.rs index 0d5876659..0a83bf637 100644 --- a/crates/db_schema/src/impls/private_message_report.rs +++ b/crates/db_schema/src/impls/private_message_report.rs @@ -3,8 +3,9 @@ use crate::{ schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated}, source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm}, traits::Reportable, - utils::{get_conn, naive_now, DbPool}, + utils::{get_conn, DbPool}, }; +use chrono::Utc; use diesel::{ dsl::{insert_into, update}, result::Error, @@ -40,7 +41,7 @@ impl Reportable for PrivateMessageReport { .set(( resolved.eq(true), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await @@ -65,7 +66,7 @@ impl Reportable for PrivateMessageReport { .set(( resolved.eq(false), resolver_id.eq(by_resolver_id), - updated.eq(naive_now()), + updated.eq(Utc::now()), )) .execute(conn) .await diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index be9aa7873..d4001807f 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -84,7 +84,7 @@ pub struct CommentInsertForm { pub struct CommentUpdateForm { pub content: Option, pub removed: Option, - // Don't use a default naive_now here, because the create function does a lot of comment updates + // Don't use a default Utc::now here, because the create function does a lot of comment updates pub updated: Option>>, pub deleted: Option, pub ap_id: Option, diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index bed659a10..306d79e70 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -165,7 +165,7 @@ pub struct PostLike { pub published: DateTime, } -#[derive(Clone)] +#[derive(Clone, derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))] pub struct PostLikeForm { @@ -173,6 +173,8 @@ pub struct PostLikeForm { pub person_id: PersonId, #[cfg_attr(feature = "full", diesel(column_name = like_score))] pub score: i16, + #[new(value = "Utc::now()")] + pub liked: DateTime, } #[derive(PartialEq, Eq, Debug)] @@ -192,11 +194,14 @@ pub struct PostSaved { pub published: DateTime, } +#[derive(derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))] pub struct PostSavedForm { pub post_id: PostId, pub person_id: PersonId, + #[new(value = "Utc::now()")] + pub saved: DateTime, } #[derive(PartialEq, Eq, Debug)] @@ -216,11 +221,14 @@ pub struct PostRead { pub published: DateTime, } +#[derive(derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))] -pub(crate) struct PostReadForm { +pub struct PostReadForm { pub post_id: PostId, pub person_id: PersonId, + #[new(value = "Utc::now()")] + pub read: DateTime, } #[derive(PartialEq, Eq, Debug)] @@ -240,9 +248,12 @@ pub struct PostHide { pub published: DateTime, } +#[derive(derive_new::new)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))] -pub(crate) struct PostHideForm { +pub struct PostHideForm { pub post_id: PostId, pub person_id: PersonId, + #[new(value = "Utc::now()")] + pub hidden: DateTime, } diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index bb7edb13f..791a19f65 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -1,7 +1,7 @@ pub mod uplete; use crate::{newtypes::DbUrl, CommentSortType, PostSortType}; -use chrono::{DateTime, TimeDelta, Utc}; +use chrono::TimeDelta; use deadpool::Runtime; use diesel::{ dsl, @@ -499,10 +499,6 @@ pub fn build_db_pool_for_tests() -> ActualDbPool { build_db_pool().expect("db pool missing") } -pub fn naive_now() -> DateTime { - Utc::now() -} - pub fn post_to_comment_sort_type(sort: PostSortType) -> CommentSortType { use PostSortType::*; match sort { diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 23f3a8134..f408ff0ec 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -641,6 +641,7 @@ mod tests { PostLike, PostLikeForm, PostRead, + PostReadForm, PostSaved, PostSavedForm, PostUpdateForm, @@ -994,11 +995,8 @@ mod tests { let pool = &mut pool.into(); let mut data = init_data(pool).await?; - let post_like_form = PostLikeForm { - post_id: data.inserted_post.id, - person_id: data.local_user_view.person.id, - score: 1, - }; + let post_like_form = + PostLikeForm::new(data.inserted_post.id, data.local_user_view.person.id, 1); let inserted_post_like = PostLike::like(pool, &post_like_form).await?; @@ -1054,18 +1052,12 @@ mod tests { // Like both the bot post, and your own // The liked_only should not show your own post - let post_like_form = PostLikeForm { - post_id: data.inserted_post.id, - person_id: data.local_user_view.person.id, - score: 1, - }; + let post_like_form = + PostLikeForm::new(data.inserted_post.id, data.local_user_view.person.id, 1); PostLike::like(pool, &post_like_form).await?; - let bot_post_like_form = PostLikeForm { - post_id: data.inserted_bot_post.id, - person_id: data.local_user_view.person.id, - score: 1, - }; + let bot_post_like_form = + PostLikeForm::new(data.inserted_bot_post.id, data.local_user_view.person.id, 1); PostLike::like(pool, &bot_post_like_form).await?; // Read the liked only @@ -1103,10 +1095,8 @@ mod tests { // Save only the bot post // The saved_only should only show the bot post - let post_save_form = PostSavedForm { - post_id: data.inserted_bot_post.id, - person_id: data.local_user_view.person.id, - }; + let post_save_form = + PostSavedForm::new(data.inserted_bot_post.id, data.local_user_view.person.id); PostSaved::save(pool, &post_save_form).await?; // Read the saved only @@ -1521,12 +1511,8 @@ mod tests { data.local_user_view.local_user.show_read_posts = false; // Mark a post as read - PostRead::mark_as_read( - pool, - data.inserted_bot_post.id, - data.local_user_view.person.id, - ) - .await?; + let read_form = PostReadForm::new(data.inserted_bot_post.id, data.local_user_view.person.id); + PostRead::mark_as_read(pool, &read_form).await?; // Make sure you don't see the read post in the results let post_listings_hide_read = data.default_post_query().list(&data.site, pool).await?; diff --git a/crates/db_views/src/vote_view.rs b/crates/db_views/src/vote_view.rs index 9af0bd756..827cd3cc9 100644 --- a/crates/db_views/src/vote_view.rs +++ b/crates/db_views/src/vote_view.rs @@ -134,19 +134,11 @@ mod tests { let inserted_comment = Comment::create(pool, &comment_form, None).await?; // Timmy upvotes his own post - let timmy_post_vote_form = PostLikeForm { - post_id: inserted_post.id, - person_id: inserted_timmy.id, - score: 1, - }; + let timmy_post_vote_form = PostLikeForm::new(inserted_post.id, inserted_timmy.id, 1); PostLike::like(pool, &timmy_post_vote_form).await?; // Sara downvotes timmy's post - let sara_post_vote_form = PostLikeForm { - post_id: inserted_post.id, - person_id: inserted_sara.id, - score: -1, - }; + let sara_post_vote_form = PostLikeForm::new(inserted_post.id, inserted_sara.id, -1); PostLike::like(pool, &sara_post_vote_form).await?; let expected_post_vote_views = [ diff --git a/crates/federate/src/worker.rs b/crates/federate/src/worker.rs index b0254ba0b..20cd51d1a 100644 --- a/crates/federate/src/worker.rs +++ b/crates/federate/src/worker.rs @@ -22,7 +22,7 @@ use lemmy_db_schema::{ federation_queue_state::FederationQueueState, instance::{Instance, InstanceForm}, }, - utils::{naive_now, ActualDbPool, DbPool}, + utils::{ActualDbPool, DbPool}, }; use std::{collections::BinaryHeap, ops::Add, time::Duration}; use tokio::{ @@ -291,7 +291,7 @@ impl InstanceWorker { self.instance.updated = Some(Utc::now()); let form = InstanceForm { - updated: Some(naive_now()), + updated: Some(Utc::now()), ..InstanceForm::new(self.instance.domain.clone()) }; Instance::update(&mut self.pool(), self.instance.id, form).await?; diff --git a/src/code_migrations.rs b/src/code_migrations.rs index 84af43ea7..1f7122aa6 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -1,5 +1,6 @@ // This is for db migrations that require code use activitypub_federation::http_signatures::generate_actor_keypair; +use chrono::Utc; use diesel::{ sql_types::{Nullable, Text}, ExpressionMethods, @@ -26,7 +27,7 @@ use lemmy_db_schema::{ site::{Site, SiteInsertForm, SiteUpdateForm}, }, traits::Crud, - utils::{get_conn, naive_now, DbPool}, + utils::{get_conn, DbPool}, }; use lemmy_utils::{error::LemmyResult, settings::structs::Settings}; use tracing::info; @@ -78,7 +79,7 @@ async fn user_updates_2020_04_02( )?), private_key: Some(Some(keypair.private_key)), public_key: Some(keypair.public_key), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), ..Default::default() }; @@ -118,7 +119,7 @@ async fn community_updates_2020_04_02( actor_id: Some(community_actor_id.clone()), private_key: Some(Some(keypair.private_key)), public_key: Some(keypair.public_key), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), ..Default::default() }; @@ -334,7 +335,7 @@ async fn instance_actor_2022_01_28( let actor_id = Url::parse(protocol_and_hostname)?; let site_form = SiteUpdateForm { actor_id: Some(actor_id.clone().into()), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), inbox_url: Some(generate_inbox_url()?), private_key: Some(Some(key_pair.private_key)), public_key: Some(key_pair.public_key), @@ -465,7 +466,7 @@ async fn initialize_local_site_2022_10_10( .unwrap_or_else(|| "New Site".to_string()); let site_form = SiteInsertForm { actor_id: Some(site_actor_id.clone().into()), - last_refreshed_at: Some(naive_now()), + last_refreshed_at: Some(Utc::now()), inbox_url: Some(generate_inbox_url()?), private_key: Some(site_key_pair.private_key), public_key: Some(site_key_pair.public_key), diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index 043d78d6b..dab2cbe3a 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -36,15 +36,7 @@ use lemmy_db_schema::{ post::{Post, PostUpdateForm}, }, traits::Crud, - utils::{ - find_action, - functions::coalesce, - get_conn, - naive_now, - now, - DbPool, - DELETED_REPLACEMENT_TEXT, - }, + utils::{find_action, functions::coalesce, get_conn, now, DbPool, DELETED_REPLACEMENT_TEXT}, }; use lemmy_routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}; use lemmy_utils::error::LemmyResult; @@ -558,7 +550,7 @@ async fn build_update_instance_form( // Activitypub). That's why we always need to mark instances as updated if they are // alive. let mut instance_form = InstanceForm { - updated: Some(naive_now()), + updated: Some(Utc::now()), ..InstanceForm::new(domain.to_string()) };