Cleanup post action forms (#5197)

* Removing a few SuccessResponses for PostHide and MarkPostAsRead.

- This also removes the pointless multiple post_ids. These can be done
  as individual calls on the front end anyway.
- Fixes #4755

* Fixing federation tests.

* Upgrading lemmy-js-client deps.

* Add ability to mark several posts as read.

Context:

- https://github.com/LemmyNet/lemmy/pull/5043
- https://github.com/LemmyNet/lemmy/issues/4755
- https://github.com/LemmyNet/lemmy/pull/5160

* Simplifying forms.

* Fixing forms.

* Cleanup post action forms by using derive_new defaults.

- Fixes #5195

* Fix ntfy to notify on success builds also.

* Removing pointless naive_now function.

* Running taplo fmt.
This commit is contained in:
Dessalines 2024-11-15 05:21:08 -05:00 committed by GitHub
parent 7f4e26e29e
commit 231cce9350
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 145 additions and 219 deletions

View file

@ -123,7 +123,10 @@ reqwest-tracing = "0.5.3"
clokwerk = "0.4.0" clokwerk = "0.4.0"
doku = { version = "0.21.1", features = ["url-2"] } doku = { version = "0.21.1", features = ["url-2"] }
bcrypt = "0.15.1" 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"] } serde_json = { version = "1.0.121", features = ["preserve_order"] }
base64 = "0.22.1" base64 = "0.22.1"
uuid = { version = "1.10.0", features = ["serde", "v4"] } uuid = { version = "1.10.0", features = ["serde", "v4"] }

View file

@ -10,7 +10,7 @@ use lemmy_api_common::{
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
local_site::LocalSite, local_site::LocalSite,
post::{PostLike, PostLikeForm, PostRead}, post::{PostLike, PostLikeForm, PostRead, PostReadForm},
}, },
traits::Likeable, traits::Likeable,
}; };
@ -47,11 +47,7 @@ pub async fn like_post(
) )
.await?; .await?;
let like_form = PostLikeForm { let like_form = PostLikeForm::new(data.post_id, local_user_view.person.id, data.score);
post_id: data.post_id,
person_id: local_user_view.person.id,
score: data.score,
};
// Remove any likes first // Remove any likes first
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
@ -67,7 +63,8 @@ pub async fn like_post(
} }
// Mark Post Read // 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( ActivityChannel::submit_activity(
SendActivityData::LikePostOrComment { SendActivityData::LikePostOrComment {

View file

@ -3,7 +3,7 @@ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
post::{MarkPostAsRead, PostResponse}, 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_db_views::structs::{LocalUserView, PostView};
use lemmy_utils::error::LemmyResult; use lemmy_utils::error::LemmyResult;
@ -17,10 +17,11 @@ pub async fn mark_post_as_read(
let post_id = data.post_id; let post_id = data.post_id;
// Mark the post as read / unread // Mark the post as read / unread
let form = PostReadForm::new(post_id, person_id);
if data.read { 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 { } 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( let post_view = PostView::read(
&mut context.pool(), &mut context.pool(),

View file

@ -4,7 +4,7 @@ use lemmy_api_common::{
post::{PostResponse, SavePost}, post::{PostResponse, SavePost},
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::post::{PostRead, PostSaved, PostSavedForm}, source::post::{PostRead, PostReadForm, PostSaved, PostSavedForm},
traits::Saveable, traits::Saveable,
}; };
use lemmy_db_views::structs::{LocalUserView, PostView}; use lemmy_db_views::structs::{LocalUserView, PostView};
@ -16,10 +16,7 @@ pub async fn save_post(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> LemmyResult<Json<PostResponse>> { ) -> LemmyResult<Json<PostResponse>> {
let post_saved_form = PostSavedForm { let post_saved_form = PostSavedForm::new(data.post_id, local_user_view.person.id);
post_id: data.post_id,
person_id: local_user_view.person.id,
};
if data.save { if data.save {
PostSaved::save(&mut context.pool(), &post_saved_form) PostSaved::save(&mut context.pool(), &post_saved_form)
@ -41,7 +38,8 @@ pub async fn save_post(
) )
.await?; .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 })) Ok(Json(PostResponse { post_view }))
} }

View file

@ -1,5 +1,6 @@
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
build_response::{build_comment_response, send_local_notifs}, build_response::{build_comment_response, send_local_notifs},
comment::{CommentResponse, EditComment}, comment::{CommentResponse, EditComment},
@ -19,7 +20,6 @@ use lemmy_db_schema::{
local_site::LocalSite, local_site::LocalSite,
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView}; use lemmy_db_views::structs::{CommentView, LocalUserView};
use lemmy_utils::{ use lemmy_utils::{
@ -74,7 +74,7 @@ pub async fn update_comment(
let form = CommentUpdateForm { let form = CommentUpdateForm {
content, content,
language_id: Some(language_id), language_id: Some(language_id),
updated: Some(Some(naive_now())), updated: Some(Some(Utc::now())),
..Default::default() ..Default::default()
}; };
let updated_comment = Comment::update(&mut context.pool(), comment_id, &form) let updated_comment = Comment::update(&mut context.pool(), comment_id, &form)

View file

@ -1,6 +1,7 @@
use super::check_community_visibility_allowed; use super::check_community_visibility_allowed;
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
build_response::build_community_response, build_response::build_community_response,
community::{CommunityResponse, EditCommunity}, community::{CommunityResponse, EditCommunity},
@ -22,7 +23,7 @@ use lemmy_db_schema::{
local_site::LocalSite, local_site::LocalSite,
}, },
traits::Crud, 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_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
@ -95,7 +96,7 @@ pub async fn update_community(
nsfw: data.nsfw, nsfw: data.nsfw,
posting_restricted_to_mods: data.posting_restricted_to_mods, posting_restricted_to_mods: data.posting_restricted_to_mods,
visibility: data.visibility, visibility: data.visibility,
updated: Some(Some(naive_now())), updated: Some(Some(Utc::now())),
..Default::default() ..Default::default()
}; };

View file

@ -1,10 +1,11 @@
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{context::LemmyContext, oauth_provider::EditOAuthProvider, utils::is_admin}; use lemmy_api_common::{context::LemmyContext, oauth_provider::EditOAuthProvider, utils::is_admin};
use lemmy_db_schema::{ use lemmy_db_schema::{
source::oauth_provider::{OAuthProvider, OAuthProviderUpdateForm}, source::oauth_provider::{OAuthProvider, OAuthProviderUpdateForm},
traits::Crud, 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_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyError;
@ -32,7 +33,7 @@ pub async fn update_oauth_provider(
auto_verify_email: data.auto_verify_email, auto_verify_email: data.auto_verify_email,
account_linking_enabled: data.account_linking_enabled, account_linking_enabled: data.account_linking_enabled,
enabled: data.enabled, enabled: data.enabled,
updated: Some(Some(naive_now())), updated: Some(Some(Utc::now())),
}; };
let update_result = let update_result =

View file

@ -20,7 +20,7 @@ use lemmy_db_schema::{
source::{ source::{
community::Community, community::Community,
local_site::LocalSite, local_site::LocalSite,
post::{Post, PostInsertForm, PostLike, PostLikeForm, PostRead}, post::{Post, PostInsertForm, PostLike, PostLikeForm, PostRead, PostReadForm},
}, },
traits::{Crud, Likeable}, traits::{Crud, Likeable},
utils::diesel_url_create, utils::diesel_url_create,
@ -142,17 +142,14 @@ pub async fn create_post(
// They like their own post by default // They like their own post by default
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let post_id = inserted_post.id; let post_id = inserted_post.id;
let like_form = PostLikeForm { let like_form = PostLikeForm::new(post_id, person_id, 1);
post_id,
person_id,
score: 1,
};
PostLike::like(&mut context.pool(), &like_form) PostLike::like(&mut context.pool(), &like_form)
.await .await
.with_lemmy_type(LemmyErrorType::CouldntLikePost)?; .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 build_post_response(&context, community_id, local_user_view, post_id).await
} }

View file

@ -7,7 +7,7 @@ use lemmy_api_common::{
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
comment::Comment, comment::Comment,
post::{Post, PostRead}, post::{Post, PostRead, PostReadForm},
}, },
traits::Crud, traits::Crud,
}; };
@ -65,7 +65,8 @@ pub async fn get_post(
let post_id = post_view.post.id; let post_id = post_view.post.id;
if let Some(person_id) = person_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( update_read_comments(
person_id, person_id,

View file

@ -1,6 +1,7 @@
use super::{convert_published_time, create::send_webmention}; use super::{convert_published_time, create::send_webmention};
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
build_response::build_post_response, build_response::build_post_response,
context::LemmyContext, context::LemmyContext,
@ -22,7 +23,7 @@ use lemmy_db_schema::{
post::{Post, PostUpdateForm}, post::{Post, PostUpdateForm},
}, },
traits::Crud, 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_db_views::structs::{LocalUserView, PostView};
use lemmy_utils::{ use lemmy_utils::{
@ -131,7 +132,7 @@ pub async fn update_post(
alt_text, alt_text,
nsfw: data.nsfw, nsfw: data.nsfw,
language_id: Some(language_id), language_id: Some(language_id),
updated: Some(Some(naive_now())), updated: Some(Some(Utc::now())),
scheduled_publish_time, scheduled_publish_time,
..Default::default() ..Default::default()
}; };

View file

@ -1,5 +1,6 @@
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
private_message::{EditPrivateMessage, PrivateMessageResponse}, private_message::{EditPrivateMessage, PrivateMessageResponse},
@ -12,7 +13,6 @@ use lemmy_db_schema::{
private_message::{PrivateMessage, PrivateMessageUpdateForm}, private_message::{PrivateMessage, PrivateMessageUpdateForm},
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_db_views::structs::{LocalUserView, PrivateMessageView}; use lemmy_db_views::structs::{LocalUserView, PrivateMessageView};
use lemmy_utils::{ use lemmy_utils::{
@ -47,7 +47,7 @@ pub async fn update_private_message(
private_message_id, private_message_id,
&PrivateMessageUpdateForm { &PrivateMessageUpdateForm {
content: Some(content), content: Some(content),
updated: Some(Some(naive_now())), updated: Some(Some(Utc::now())),
..Default::default() ..Default::default()
}, },
) )

View file

@ -2,6 +2,7 @@ use super::not_zero;
use crate::site::{application_question_check, site_default_post_listing_type_check}; use crate::site::{application_question_check, site_default_post_listing_type_check};
use activitypub_federation::{config::Data, http_signatures::generate_actor_keypair}; use activitypub_federation::{config::Data, http_signatures::generate_actor_keypair};
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
site::{CreateSite, SiteResponse}, site::{CreateSite, SiteResponse},
@ -23,7 +24,7 @@ use lemmy_db_schema::{
site::{Site, SiteUpdateForm}, site::{Site, SiteUpdateForm},
}, },
traits::Crud, 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_db_views::structs::{LocalUserView, SiteView};
use lemmy_utils::{ use lemmy_utils::{
@ -75,7 +76,7 @@ pub async fn create_site(
icon: Some(icon), icon: Some(icon),
banner: Some(banner), banner: Some(banner),
actor_id: Some(actor_id), actor_id: Some(actor_id),
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(Utc::now()),
inbox_url, inbox_url,
private_key: Some(Some(keypair.private_key)), private_key: Some(Some(keypair.private_key)),
public_key: Some(keypair.public_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()), legal_information: diesel_string_update(data.legal_information.as_deref()),
application_email_admins: data.application_email_admins, application_email_admins: data.application_email_admins,
hide_modlog_mod_names: data.hide_modlog_mod_names, 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()), slur_filter_regex: diesel_string_update(data.slur_filter_regex.as_deref()),
actor_name_max_length: data.actor_name_max_length, actor_name_max_length: data.actor_name_max_length,
federation_enabled: data.federation_enabled, federation_enabled: data.federation_enabled,

View file

@ -2,6 +2,7 @@ use super::not_zero;
use crate::site::{application_question_check, site_default_post_listing_type_check}; use crate::site::{application_question_check, site_default_post_listing_type_check};
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
request::replace_image, request::replace_image,
@ -27,7 +28,7 @@ use lemmy_db_schema::{
site::{Site, SiteUpdateForm}, site::{Site, SiteUpdateForm},
}, },
traits::Crud, traits::Crud,
utils::{diesel_string_update, diesel_url_update, naive_now}, utils::{diesel_string_update, diesel_url_update},
RegistrationMode, RegistrationMode,
}; };
use lemmy_db_views::structs::{LocalUserView, SiteView}; use lemmy_db_views::structs::{LocalUserView, SiteView};
@ -88,7 +89,7 @@ pub async fn update_site(
icon, icon,
banner, banner,
content_warning: diesel_string_update(data.content_warning.as_deref()), content_warning: diesel_string_update(data.content_warning.as_deref()),
updated: Some(Some(naive_now())), updated: Some(Some(Utc::now())),
..Default::default() ..Default::default()
}; };
@ -111,7 +112,7 @@ pub async fn update_site(
legal_information: diesel_string_update(data.legal_information.as_deref()), legal_information: diesel_string_update(data.legal_information.as_deref()),
application_email_admins: data.application_email_admins, application_email_admins: data.application_email_admins,
hide_modlog_mod_names: data.hide_modlog_mod_names, 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()), slur_filter_regex: diesel_string_update(data.slur_filter_regex.as_deref()),
actor_name_max_length: data.actor_name_max_length, actor_name_max_length: data.actor_name_max_length,
federation_enabled: data.federation_enabled, federation_enabled: data.federation_enabled,

View file

@ -1,5 +1,6 @@
use activitypub_federation::config::Data; use activitypub_federation::config::Data;
use actix_web::web::Json; use actix_web::web::Json;
use chrono::Utc;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
tagline::{TaglineResponse, UpdateTagline}, tagline::{TaglineResponse, UpdateTagline},
@ -11,7 +12,6 @@ use lemmy_db_schema::{
tagline::{Tagline, TaglineUpdateForm}, tagline::{Tagline, TaglineUpdateForm},
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyError;
@ -33,7 +33,7 @@ pub async fn update_tagline(
let tagline_form = TaglineUpdateForm { let tagline_form = TaglineUpdateForm {
content, content,
updated: naive_now(), updated: Utc::now(),
}; };
let tagline = Tagline::update(&mut context.pool(), data.id, &tagline_form).await?; let tagline = Tagline::update(&mut context.pool(), data.id, &tagline_form).await?;

View file

@ -17,6 +17,7 @@ use activitypub_federation::{
kinds::activity::UpdateType, kinds::activity::UpdateType,
traits::{ActivityHandler, Actor, Object}, traits::{ActivityHandler, Actor, Object},
}; };
use chrono::Utc;
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
@ -25,7 +26,6 @@ use lemmy_db_schema::{
person::Person, person::Person,
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_utils::error::{LemmyError, LemmyResult}; use lemmy_utils::error::{LemmyError, LemmyResult};
use url::Url; use url::Url;
@ -103,7 +103,7 @@ impl ActivityHandler for UpdateCommunity {
nsfw: Some(self.object.sensitive.unwrap_or(false)), nsfw: Some(self.object.sensitive.unwrap_or(false)),
actor_id: Some(self.object.id.into()), actor_id: Some(self.object.id.into()),
public_key: Some(self.object.public_key.public_key_pem), 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())), icon: Some(self.object.icon.map(|i| i.url.into())),
banner: Some(self.object.image.map(|i| i.url.into())), banner: Some(self.object.image.map(|i| i.url.into())),
followers_url: self.object.followers.map(Into::into), followers_url: self.object.followers.map(Into::into),

View file

@ -118,11 +118,7 @@ impl ActivityHandler for CreateOrUpdatePage {
let post = ApubPost::from_json(self.object, context).await?; let post = ApubPost::from_json(self.object, context).await?;
// author likes their own post by default // author likes their own post by default
let like_form = PostLikeForm { let like_form = PostLikeForm::new(post.id, post.creator_id, 1);
post_id: post.id,
person_id: post.creator_id,
score: 1,
};
PostLike::like(&mut context.pool(), &like_form).await?; PostLike::like(&mut context.pool(), &like_form).await?;
// Calculate initial hot_rank for post // Calculate initial hot_rank for post

View file

@ -79,11 +79,7 @@ async fn vote_post(
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> LemmyResult<()> { ) -> LemmyResult<()> {
let post_id = post.id; let post_id = post.id;
let like_form = PostLikeForm { let like_form = PostLikeForm::new(post.id, actor.id, vote_type.into());
post_id: post.id,
person_id: actor.id,
score: vote_type.into(),
};
let person_id = actor.id; let person_id = actor.id;
PostLike::remove(&mut context.pool(), person_id, post_id).await?; PostLike::remove(&mut context.pool(), person_id, post_id).await?;
PostLike::like(&mut context.pool(), &like_form).await?; PostLike::like(&mut context.pool(), &like_form).await?;

View file

@ -200,10 +200,7 @@ pub async fn import_settings(
&context, &context,
|(saved, context)| async move { |(saved, context)| async move {
let post = saved.dereference(&context).await?; let post = saved.dereference(&context).await?;
let form = PostSavedForm { let form = PostSavedForm::new(post.id, person_id);
person_id,
post_id: post.id,
};
PostSaved::save(&mut context.pool(), &form).await?; PostSaved::save(&mut context.pool(), &form).await?;
LemmyResult::Ok(()) LemmyResult::Ok(())
}, },

View file

@ -30,7 +30,6 @@ use lemmy_db_schema::{
post::Post, post::Post,
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_utils::{ use lemmy_utils::{
error::{FederationError, LemmyError, LemmyResult}, error::{FederationError, LemmyError, LemmyResult},
@ -204,7 +203,7 @@ impl Object for ApubComment {
language_id, language_id,
}; };
let parent_comment_path = parent_comment.map(|t| t.0.path); let parent_comment_path = parent_comment.map(|t| t.0.path);
let timestamp: DateTime<Utc> = note.updated.or(note.published).unwrap_or_else(naive_now); let timestamp: DateTime<Utc> = note.updated.or(note.published).unwrap_or_else(Utc::now);
let comment = Comment::insert_apub( let comment = Comment::insert_apub(
&mut context.pool(), &mut context.pool(),
Some(timestamp), Some(timestamp),

View file

@ -38,7 +38,6 @@ use lemmy_db_schema::{
local_site::LocalSite, local_site::LocalSite,
}, },
traits::{ApubActor, Crud}, traits::{ApubActor, Crud},
utils::naive_now,
CommunityVisibility, CommunityVisibility,
}; };
use lemmy_db_views_actor::structs::CommunityFollowerView; use lemmy_db_views_actor::structs::CommunityFollowerView;
@ -166,7 +165,7 @@ impl Object for ApubCommunity {
nsfw: Some(group.sensitive.unwrap_or(false)), nsfw: Some(group.sensitive.unwrap_or(false)),
actor_id: Some(group.id.into()), actor_id: Some(group.id.into()),
local: Some(false), local: Some(false),
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(Utc::now()),
icon, icon,
banner, banner,
sidebar, sidebar,
@ -193,7 +192,7 @@ impl Object for ApubCommunity {
let languages = let languages =
LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?; 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) let community: ApubCommunity = Community::insert_apub(&mut context.pool(), timestamp, &form)
.await? .await?
.into(); .into();

View file

@ -39,7 +39,6 @@ use lemmy_db_schema::{
site::{Site, SiteInsertForm}, site::{Site, SiteInsertForm},
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_utils::{ use lemmy_utils::{
error::{FederationError, LemmyError, LemmyResult}, error::{FederationError, LemmyError, LemmyResult},
@ -163,7 +162,7 @@ impl Object for ApubSite {
banner, banner,
description: apub.summary, description: apub.summary,
actor_id: Some(apub.id.clone().into()), 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()), inbox_url: Some(apub.inbox.clone().into()),
public_key: Some(apub.public_key.public_key_pem.clone()), public_key: Some(apub.public_key.public_key_pem.clone()),
private_key: None, private_key: None,

View file

@ -35,7 +35,6 @@ use lemmy_db_schema::{
person::{Person as DbPerson, PersonInsertForm, PersonUpdateForm}, person::{Person as DbPerson, PersonInsertForm, PersonUpdateForm},
}, },
traits::{ApubActor, Crud}, traits::{ApubActor, Crud},
utils::naive_now,
}; };
use lemmy_utils::{ use lemmy_utils::{
error::{LemmyError, LemmyResult}, error::{LemmyError, LemmyResult},
@ -176,7 +175,7 @@ impl Object for ApubPerson {
bot_account: Some(person.kind == UserTypes::Service), bot_account: Some(person.kind == UserTypes::Service),
private_key: None, private_key: None,
public_key: person.public_key.public_key_pem, public_key: person.public_key.public_key_pem,
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(Utc::now()),
inbox_url: Some( inbox_url: Some(
person person
.endpoints .endpoints

View file

@ -35,7 +35,6 @@ use lemmy_db_schema::{
post::{Post, PostInsertForm, PostUpdateForm}, post::{Post, PostInsertForm, PostUpdateForm},
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_db_views_actor::structs::CommunityModeratorView; use lemmy_db_views_actor::structs::CommunityModeratorView;
use lemmy_utils::{ use lemmy_utils::{
@ -260,7 +259,7 @@ impl Object for ApubPost {
..PostInsertForm::new(name, creator.id, community.id) ..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::insert_apub(&mut context.pool(), timestamp, &form).await?;
let post_ = post.clone(); let post_ = post.clone();
let context_ = context.reset_request_count(); let context_ = context.reset_request_count();

View file

@ -31,7 +31,6 @@ use lemmy_db_schema::{
private_message::{PrivateMessage, PrivateMessageInsertForm}, private_message::{PrivateMessage, PrivateMessageInsertForm},
}, },
traits::Crud, traits::Crud,
utils::naive_now,
}; };
use lemmy_db_views::structs::LocalUserView; use lemmy_db_views::structs::LocalUserView;
use lemmy_utils::{ use lemmy_utils::{
@ -161,7 +160,7 @@ impl Object for ApubPrivateMessage {
ap_id: Some(note.id.into()), ap_id: Some(note.id.into()),
local: Some(false), 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?; let pm = PrivateMessage::insert_apub(&mut context.pool(), timestamp, &form).await?;
Ok(pm.into()) Ok(pm.into())
} }

View file

@ -65,11 +65,7 @@ mod tests {
); );
let inserted_post = Post::create(pool, &new_post).await?; let inserted_post = Post::create(pool, &new_post).await?;
let post_like = PostLikeForm { let post_like = PostLikeForm::new(inserted_post.id, inserted_person.id, 1);
post_id: inserted_post.id,
person_id: inserted_person.id,
score: 1,
};
let _inserted_post_like = PostLike::like(pool, &post_like).await?; let _inserted_post_like = PostLike::like(pool, &post_like).await?;
let comment_form = CommentInsertForm::new( let comment_form = CommentInsertForm::new(

View file

@ -113,11 +113,7 @@ mod tests {
let inserted_child_comment = let inserted_child_comment =
Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?; Comment::create(pool, &child_comment_form, Some(&inserted_comment.path)).await?;
let post_like = PostLikeForm { let post_like = PostLikeForm::new(inserted_post.id, inserted_person.id, 1);
post_id: inserted_post.id,
person_id: inserted_person.id,
score: 1,
};
PostLike::like(pool, &post_like).await?; PostLike::like(pool, &post_like).await?;
@ -129,11 +125,7 @@ mod tests {
assert_eq!(0, post_aggs_before_delete.downvotes); assert_eq!(0, post_aggs_before_delete.downvotes);
// Add a post dislike from the other person // Add a post dislike from the other person
let post_dislike = PostLikeForm { let post_dislike = PostLikeForm::new(inserted_post.id, another_inserted_person.id, -1);
post_id: inserted_post.id,
person_id: another_inserted_person.id,
score: -1,
};
PostLike::like(pool, &post_dislike).await?; PostLike::like(pool, &post_dislike).await?;

View file

@ -12,15 +12,7 @@ use crate::{
CommentUpdateForm, CommentUpdateForm,
}, },
traits::{Crud, Likeable, Saveable}, traits::{Crud, Likeable, Saveable},
utils::{ utils::{functions::coalesce, get_conn, now, uplete, DbPool, DELETED_REPLACEMENT_TEXT},
functions::coalesce,
get_conn,
naive_now,
now,
uplete,
DbPool,
DELETED_REPLACEMENT_TEXT,
},
}; };
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use diesel::{ use diesel::{
@ -46,7 +38,7 @@ impl Comment {
.set(( .set((
comment::content.eq(DELETED_REPLACEMENT_TEXT), comment::content.eq(DELETED_REPLACEMENT_TEXT),
comment::deleted.eq(true), comment::deleted.eq(true),
comment::updated.eq(naive_now()), comment::updated.eq(Utc::now()),
)) ))
.get_results::<Self>(conn) .get_results::<Self>(conn)
.await .await
@ -61,7 +53,7 @@ impl Comment {
diesel::update(comment::table.filter(comment::creator_id.eq(for_creator_id))) diesel::update(comment::table.filter(comment::creator_id.eq(for_creator_id)))
.set(( .set((
comment::removed.eq(removed), comment::removed.eq(removed),
comment::updated.eq(naive_now()), comment::updated.eq(Utc::now()),
)) ))
.get_results::<Self>(conn) .get_results::<Self>(conn)
.await .await

View file

@ -6,8 +6,9 @@ use crate::{
}, },
source::comment_report::{CommentReport, CommentReportForm}, source::comment_report::{CommentReport, CommentReportForm},
traits::Reportable, traits::Reportable,
utils::{get_conn, naive_now, DbPool}, utils::{get_conn, DbPool},
}; };
use chrono::Utc;
use diesel::{ use diesel::{
dsl::{insert_into, update}, dsl::{insert_into, update},
result::Error, result::Error,
@ -51,7 +52,7 @@ impl Reportable for CommentReport {
.set(( .set((
resolved.eq(true), resolved.eq(true),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await
@ -67,7 +68,7 @@ impl Reportable for CommentReport {
.set(( .set((
resolved.eq(true), resolved.eq(true),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await
@ -88,7 +89,7 @@ impl Reportable for CommentReport {
.set(( .set((
resolved.eq(false), resolved.eq(false),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await

View file

@ -16,11 +16,11 @@ use crate::{
utils::{ utils::{
functions::{coalesce, lower}, functions::{coalesce, lower},
get_conn, get_conn,
naive_now,
now, now,
DbPool, DbPool,
}, },
}; };
use chrono::Utc;
use diesel::{ use diesel::{
dsl::{count_star, insert_into}, dsl::{count_star, insert_into},
result::Error, result::Error,
@ -52,7 +52,7 @@ impl Instance {
None => { None => {
// Instance not in database yet, insert it // Instance not in database yet, insert it
let form = InstanceForm { let form = InstanceForm {
updated: Some(naive_now()), updated: Some(Utc::now()),
..InstanceForm::new(domain_) ..InstanceForm::new(domain_)
}; };
insert_into(instance::table) insert_into(instance::table)

View file

@ -10,8 +10,9 @@ use crate::{
PersonUpdateForm, PersonUpdateForm,
}, },
traits::{ApubActor, Crud, Followable}, 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::{ use diesel::{
dsl::{insert_into, not}, dsl::{insert_into, not},
expression::SelectableHelper, expression::SelectableHelper,
@ -93,7 +94,7 @@ impl Person {
person::bio.eq::<Option<String>>(None), person::bio.eq::<Option<String>>(None),
person::matrix_user_id.eq::<Option<String>>(None), person::matrix_user_id.eq::<Option<String>>(None),
person::deleted.eq(true), person::deleted.eq(true),
person::updated.eq(naive_now()), person::updated.eq(Utc::now()),
)) ))
.get_result::<Self>(conn) .get_result::<Self>(conn)
.await .await

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
diesel::{BoolExpressionMethods, OptionalExtension}, diesel::{BoolExpressionMethods, NullableExpressionMethods, OptionalExtension},
newtypes::{CommunityId, DbUrl, PersonId, PostId}, newtypes::{CommunityId, DbUrl, PersonId, PostId},
schema::{community, person, post, post_actions}, schema::{community, person, post, post_actions},
source::post::{ source::post::{
@ -19,7 +19,6 @@ use crate::{
utils::{ utils::{
functions::coalesce, functions::coalesce,
get_conn, get_conn,
naive_now,
now, now,
uplete, uplete,
DbPool, DbPool,
@ -37,7 +36,6 @@ use diesel::{
result::Error, result::Error,
DecoratableTarget, DecoratableTarget,
ExpressionMethods, ExpressionMethods,
NullableExpressionMethods,
QueryDsl, QueryDsl,
TextExpressionMethods, TextExpressionMethods,
}; };
@ -138,7 +136,7 @@ impl Post {
post::url.eq(Option::<&str>::None), post::url.eq(Option::<&str>::None),
post::body.eq(DELETED_REPLACEMENT_TEXT), post::body.eq(DELETED_REPLACEMENT_TEXT),
post::deleted.eq(true), post::deleted.eq(true),
post::updated.eq(naive_now()), post::updated.eq(Utc::now()),
)) ))
.get_results::<Self>(conn) .get_results::<Self>(conn)
.await .await
@ -160,7 +158,7 @@ impl Post {
} }
update update
.set((post::removed.eq(removed), post::updated.eq(naive_now()))) .set((post::removed.eq(removed), post::updated.eq(Utc::now())))
.get_results::<Self>(conn) .get_results::<Self>(conn)
.await .await
} }
@ -281,7 +279,6 @@ impl Likeable for PostLike {
type IdType = PostId; type IdType = PostId;
async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result<Self, Error> { async fn like(pool: &mut DbPool<'_>, post_like_form: &PostLikeForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?; 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) insert_into(post_actions::table)
.values(post_like_form) .values(post_like_form)
.on_conflict((post_actions::post_id, post_actions::person_id)) .on_conflict((post_actions::post_id, post_actions::person_id))
@ -310,7 +307,6 @@ impl Saveable for PostSaved {
type Form = PostSavedForm; type Form = PostSavedForm;
async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> { async fn save(pool: &mut DbPool<'_>, post_saved_form: &PostSavedForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?; 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) insert_into(post_actions::table)
.values(post_saved_form) .values(post_saved_form)
.on_conflict((post_actions::post_id, post_actions::person_id)) .on_conflict((post_actions::post_id, post_actions::person_id))
@ -335,28 +331,25 @@ impl Saveable for PostSaved {
impl PostRead { impl PostRead {
pub async fn mark_as_read( pub async fn mark_as_read(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
post_id: PostId, post_read_form: &PostReadForm,
person_id: PersonId,
) -> LemmyResult<usize> { ) -> LemmyResult<usize> {
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( pub async fn mark_as_unread(
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
post_id_: PostId, post_read_form: &PostReadForm,
person_id_: PersonId, ) -> Result<uplete::Count, Error> {
) -> LemmyResult<uplete::Count> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
uplete::new( uplete::new(
post_actions::table post_actions::table
.filter(post_actions::post_id.eq(post_id_)) .filter(post_actions::post_id.eq(post_read_form.post_id))
.filter(post_actions::person_id.eq(person_id_)), .filter(post_actions::person_id.eq(post_read_form.person_id)),
) )
.set_null(post_actions::read) .set_null(post_actions::read)
.get_result(conn) .get_result(conn)
.await .await
.with_lemmy_type(LemmyErrorType::CouldntMarkPostAsRead)
} }
pub async fn mark_many_as_read( pub async fn mark_many_as_read(
@ -368,16 +361,9 @@ impl PostRead {
let forms = post_ids let forms = post_ids
.iter() .iter()
.map(|post_id| { .map(|post_id| (PostReadForm::new(*post_id, person_id)))
(
PostReadForm {
post_id: *post_id,
person_id,
},
post_actions::read.eq(now().nullable()),
)
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
insert_into(post_actions::table) insert_into(post_actions::table)
.values(forms) .values(forms)
.on_conflict((post_actions::person_id, post_actions::post_id)) .on_conflict((post_actions::person_id, post_actions::post_id))
@ -397,10 +383,7 @@ impl PostHide {
) -> Result<usize, Error> { ) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let form = ( let form = &PostHideForm::new(post_id, person_id);
&PostHideForm { post_id, person_id },
post_actions::hidden.eq(now().nullable()),
);
insert_into(post_actions::table) insert_into(post_actions::table)
.values(form) .values(form)
.on_conflict((post_actions::person_id, post_actions::post_id)) .on_conflict((post_actions::person_id, post_actions::post_id))
@ -442,6 +425,7 @@ mod tests {
PostLike, PostLike,
PostLikeForm, PostLikeForm,
PostRead, PostRead,
PostReadForm,
PostSaved, PostSaved,
PostSavedForm, PostSavedForm,
PostUpdateForm, PostUpdateForm,
@ -525,11 +509,7 @@ mod tests {
}; };
// Post Like // Post Like
let post_like_form = PostLikeForm { let post_like_form = PostLikeForm::new(inserted_post.id, inserted_person.id, 1);
post_id: inserted_post.id,
person_id: inserted_person.id,
score: 1,
};
let inserted_post_like = PostLike::like(pool, &post_like_form).await?; let inserted_post_like = PostLike::like(pool, &post_like_form).await?;
@ -541,10 +521,7 @@ mod tests {
}; };
// Post Save // Post Save
let post_saved_form = PostSavedForm { let post_saved_form = PostSavedForm::new(inserted_post.id, inserted_person.id);
post_id: inserted_post.id,
person_id: inserted_person.id,
};
let inserted_post_saved = PostSaved::save(pool, &post_saved_form).await?; let inserted_post_saved = PostSaved::save(pool, &post_saved_form).await?;
@ -555,8 +532,10 @@ mod tests {
}; };
// Mark 2 posts as read // Mark 2 posts as read
PostRead::mark_as_read(pool, inserted_post.id, inserted_person.id).await?; let post_read_form_1 = PostReadForm::new(inserted_post.id, inserted_person.id);
PostRead::mark_as_read(pool, inserted_post2.id, inserted_person.id).await?; 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?; 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?; let saved_removed = PostSaved::unsave(pool, &post_saved_form).await?;
assert_eq!(uplete::Count::only_updated(1), saved_removed); assert_eq!(uplete::Count::only_updated(1), saved_removed);
let read_removed_1 = let read_remove_form_1 = PostReadForm::new(inserted_post.id, inserted_person.id);
PostRead::mark_as_unread(pool, inserted_post.id, inserted_person.id).await?; let read_removed_1 = PostRead::mark_as_unread(pool, &read_remove_form_1).await?;
assert_eq!(uplete::Count::only_deleted(1), read_removed_1); assert_eq!(uplete::Count::only_deleted(1), read_removed_1);
let read_removed_2 = let read_remove_form_2 = PostReadForm::new(inserted_post2.id, inserted_person.id);
PostRead::mark_as_unread(pool, inserted_post2.id, inserted_person.id).await?; let read_removed_2 = PostRead::mark_as_unread(pool, &read_remove_form_2).await?;
assert_eq!(uplete::Count::only_deleted(1), read_removed_2); assert_eq!(uplete::Count::only_deleted(1), read_removed_2);
let num_deleted = Post::delete(pool, inserted_post.id).await? let num_deleted = Post::delete(pool, inserted_post.id).await?

View file

@ -6,8 +6,9 @@ use crate::{
}, },
source::post_report::{PostReport, PostReportForm}, source::post_report::{PostReport, PostReportForm},
traits::Reportable, traits::Reportable,
utils::{get_conn, naive_now, DbPool}, utils::{get_conn, DbPool},
}; };
use chrono::Utc;
use diesel::{ use diesel::{
dsl::{insert_into, update}, dsl::{insert_into, update},
result::Error, result::Error,
@ -40,7 +41,7 @@ impl Reportable for PostReport {
.set(( .set((
resolved.eq(true), resolved.eq(true),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await
@ -56,7 +57,7 @@ impl Reportable for PostReport {
.set(( .set((
resolved.eq(true), resolved.eq(true),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await
@ -72,7 +73,7 @@ impl Reportable for PostReport {
.set(( .set((
resolved.eq(false), resolved.eq(false),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await

View file

@ -3,8 +3,9 @@ use crate::{
schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated}, schema::private_message_report::dsl::{private_message_report, resolved, resolver_id, updated},
source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm}, source::private_message_report::{PrivateMessageReport, PrivateMessageReportForm},
traits::Reportable, traits::Reportable,
utils::{get_conn, naive_now, DbPool}, utils::{get_conn, DbPool},
}; };
use chrono::Utc;
use diesel::{ use diesel::{
dsl::{insert_into, update}, dsl::{insert_into, update},
result::Error, result::Error,
@ -40,7 +41,7 @@ impl Reportable for PrivateMessageReport {
.set(( .set((
resolved.eq(true), resolved.eq(true),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await
@ -65,7 +66,7 @@ impl Reportable for PrivateMessageReport {
.set(( .set((
resolved.eq(false), resolved.eq(false),
resolver_id.eq(by_resolver_id), resolver_id.eq(by_resolver_id),
updated.eq(naive_now()), updated.eq(Utc::now()),
)) ))
.execute(conn) .execute(conn)
.await .await

View file

@ -84,7 +84,7 @@ pub struct CommentInsertForm {
pub struct CommentUpdateForm { pub struct CommentUpdateForm {
pub content: Option<String>, pub content: Option<String>,
pub removed: Option<bool>, pub removed: Option<bool>,
// 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<Option<DateTime<Utc>>>, pub updated: Option<Option<DateTime<Utc>>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub ap_id: Option<DbUrl>, pub ap_id: Option<DbUrl>,

View file

@ -165,7 +165,7 @@ pub struct PostLike {
pub published: DateTime<Utc>, pub published: DateTime<Utc>,
} }
#[derive(Clone)] #[derive(Clone, derive_new::new)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = post_actions))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))]
pub struct PostLikeForm { pub struct PostLikeForm {
@ -173,6 +173,8 @@ pub struct PostLikeForm {
pub person_id: PersonId, pub person_id: PersonId,
#[cfg_attr(feature = "full", diesel(column_name = like_score))] #[cfg_attr(feature = "full", diesel(column_name = like_score))]
pub score: i16, pub score: i16,
#[new(value = "Utc::now()")]
pub liked: DateTime<Utc>,
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
@ -192,11 +194,14 @@ pub struct PostSaved {
pub published: DateTime<Utc>, pub published: DateTime<Utc>,
} }
#[derive(derive_new::new)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = post_actions))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))]
pub struct PostSavedForm { pub struct PostSavedForm {
pub post_id: PostId, pub post_id: PostId,
pub person_id: PersonId, pub person_id: PersonId,
#[new(value = "Utc::now()")]
pub saved: DateTime<Utc>,
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
@ -216,11 +221,14 @@ pub struct PostRead {
pub published: DateTime<Utc>, pub published: DateTime<Utc>,
} }
#[derive(derive_new::new)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = post_actions))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))]
pub(crate) struct PostReadForm { pub struct PostReadForm {
pub post_id: PostId, pub post_id: PostId,
pub person_id: PersonId, pub person_id: PersonId,
#[new(value = "Utc::now()")]
pub read: DateTime<Utc>,
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
@ -240,9 +248,12 @@ pub struct PostHide {
pub published: DateTime<Utc>, pub published: DateTime<Utc>,
} }
#[derive(derive_new::new)]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = post_actions))] #[cfg_attr(feature = "full", diesel(table_name = post_actions))]
pub(crate) struct PostHideForm { pub struct PostHideForm {
pub post_id: PostId, pub post_id: PostId,
pub person_id: PersonId, pub person_id: PersonId,
#[new(value = "Utc::now()")]
pub hidden: DateTime<Utc>,
} }

View file

@ -1,7 +1,7 @@
pub mod uplete; pub mod uplete;
use crate::{newtypes::DbUrl, CommentSortType, PostSortType}; use crate::{newtypes::DbUrl, CommentSortType, PostSortType};
use chrono::{DateTime, TimeDelta, Utc}; use chrono::TimeDelta;
use deadpool::Runtime; use deadpool::Runtime;
use diesel::{ use diesel::{
dsl, dsl,
@ -499,10 +499,6 @@ pub fn build_db_pool_for_tests() -> ActualDbPool {
build_db_pool().expect("db pool missing") build_db_pool().expect("db pool missing")
} }
pub fn naive_now() -> DateTime<Utc> {
Utc::now()
}
pub fn post_to_comment_sort_type(sort: PostSortType) -> CommentSortType { pub fn post_to_comment_sort_type(sort: PostSortType) -> CommentSortType {
use PostSortType::*; use PostSortType::*;
match sort { match sort {

View file

@ -641,6 +641,7 @@ mod tests {
PostLike, PostLike,
PostLikeForm, PostLikeForm,
PostRead, PostRead,
PostReadForm,
PostSaved, PostSaved,
PostSavedForm, PostSavedForm,
PostUpdateForm, PostUpdateForm,
@ -994,11 +995,8 @@ mod tests {
let pool = &mut pool.into(); let pool = &mut pool.into();
let mut data = init_data(pool).await?; let mut data = init_data(pool).await?;
let post_like_form = PostLikeForm { let post_like_form =
post_id: data.inserted_post.id, PostLikeForm::new(data.inserted_post.id, data.local_user_view.person.id, 1);
person_id: data.local_user_view.person.id,
score: 1,
};
let inserted_post_like = PostLike::like(pool, &post_like_form).await?; 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 // Like both the bot post, and your own
// The liked_only should not show your own post // The liked_only should not show your own post
let post_like_form = PostLikeForm { let post_like_form =
post_id: data.inserted_post.id, PostLikeForm::new(data.inserted_post.id, data.local_user_view.person.id, 1);
person_id: data.local_user_view.person.id,
score: 1,
};
PostLike::like(pool, &post_like_form).await?; PostLike::like(pool, &post_like_form).await?;
let bot_post_like_form = PostLikeForm { let bot_post_like_form =
post_id: data.inserted_bot_post.id, PostLikeForm::new(data.inserted_bot_post.id, data.local_user_view.person.id, 1);
person_id: data.local_user_view.person.id,
score: 1,
};
PostLike::like(pool, &bot_post_like_form).await?; PostLike::like(pool, &bot_post_like_form).await?;
// Read the liked only // Read the liked only
@ -1103,10 +1095,8 @@ mod tests {
// Save only the bot post // Save only the bot post
// The saved_only should only show the bot post // The saved_only should only show the bot post
let post_save_form = PostSavedForm { let post_save_form =
post_id: data.inserted_bot_post.id, PostSavedForm::new(data.inserted_bot_post.id, data.local_user_view.person.id);
person_id: data.local_user_view.person.id,
};
PostSaved::save(pool, &post_save_form).await?; PostSaved::save(pool, &post_save_form).await?;
// Read the saved only // Read the saved only
@ -1521,12 +1511,8 @@ mod tests {
data.local_user_view.local_user.show_read_posts = false; data.local_user_view.local_user.show_read_posts = false;
// Mark a post as read // Mark a post as read
PostRead::mark_as_read( let read_form = PostReadForm::new(data.inserted_bot_post.id, data.local_user_view.person.id);
pool, PostRead::mark_as_read(pool, &read_form).await?;
data.inserted_bot_post.id,
data.local_user_view.person.id,
)
.await?;
// Make sure you don't see the read post in the results // 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?; let post_listings_hide_read = data.default_post_query().list(&data.site, pool).await?;

View file

@ -134,19 +134,11 @@ mod tests {
let inserted_comment = Comment::create(pool, &comment_form, None).await?; let inserted_comment = Comment::create(pool, &comment_form, None).await?;
// Timmy upvotes his own post // Timmy upvotes his own post
let timmy_post_vote_form = PostLikeForm { let timmy_post_vote_form = PostLikeForm::new(inserted_post.id, inserted_timmy.id, 1);
post_id: inserted_post.id,
person_id: inserted_timmy.id,
score: 1,
};
PostLike::like(pool, &timmy_post_vote_form).await?; PostLike::like(pool, &timmy_post_vote_form).await?;
// Sara downvotes timmy's post // Sara downvotes timmy's post
let sara_post_vote_form = PostLikeForm { let sara_post_vote_form = PostLikeForm::new(inserted_post.id, inserted_sara.id, -1);
post_id: inserted_post.id,
person_id: inserted_sara.id,
score: -1,
};
PostLike::like(pool, &sara_post_vote_form).await?; PostLike::like(pool, &sara_post_vote_form).await?;
let expected_post_vote_views = [ let expected_post_vote_views = [

View file

@ -22,7 +22,7 @@ use lemmy_db_schema::{
federation_queue_state::FederationQueueState, federation_queue_state::FederationQueueState,
instance::{Instance, InstanceForm}, instance::{Instance, InstanceForm},
}, },
utils::{naive_now, ActualDbPool, DbPool}, utils::{ActualDbPool, DbPool},
}; };
use std::{collections::BinaryHeap, ops::Add, time::Duration}; use std::{collections::BinaryHeap, ops::Add, time::Duration};
use tokio::{ use tokio::{
@ -291,7 +291,7 @@ impl InstanceWorker {
self.instance.updated = Some(Utc::now()); self.instance.updated = Some(Utc::now());
let form = InstanceForm { let form = InstanceForm {
updated: Some(naive_now()), updated: Some(Utc::now()),
..InstanceForm::new(self.instance.domain.clone()) ..InstanceForm::new(self.instance.domain.clone())
}; };
Instance::update(&mut self.pool(), self.instance.id, form).await?; Instance::update(&mut self.pool(), self.instance.id, form).await?;

View file

@ -1,5 +1,6 @@
// This is for db migrations that require code // This is for db migrations that require code
use activitypub_federation::http_signatures::generate_actor_keypair; use activitypub_federation::http_signatures::generate_actor_keypair;
use chrono::Utc;
use diesel::{ use diesel::{
sql_types::{Nullable, Text}, sql_types::{Nullable, Text},
ExpressionMethods, ExpressionMethods,
@ -26,7 +27,7 @@ use lemmy_db_schema::{
site::{Site, SiteInsertForm, SiteUpdateForm}, site::{Site, SiteInsertForm, SiteUpdateForm},
}, },
traits::Crud, traits::Crud,
utils::{get_conn, naive_now, DbPool}, utils::{get_conn, DbPool},
}; };
use lemmy_utils::{error::LemmyResult, settings::structs::Settings}; use lemmy_utils::{error::LemmyResult, settings::structs::Settings};
use tracing::info; use tracing::info;
@ -78,7 +79,7 @@ async fn user_updates_2020_04_02(
)?), )?),
private_key: Some(Some(keypair.private_key)), private_key: Some(Some(keypair.private_key)),
public_key: Some(keypair.public_key), public_key: Some(keypair.public_key),
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(Utc::now()),
..Default::default() ..Default::default()
}; };
@ -118,7 +119,7 @@ async fn community_updates_2020_04_02(
actor_id: Some(community_actor_id.clone()), actor_id: Some(community_actor_id.clone()),
private_key: Some(Some(keypair.private_key)), private_key: Some(Some(keypair.private_key)),
public_key: Some(keypair.public_key), public_key: Some(keypair.public_key),
last_refreshed_at: Some(naive_now()), last_refreshed_at: Some(Utc::now()),
..Default::default() ..Default::default()
}; };
@ -334,7 +335,7 @@ async fn instance_actor_2022_01_28(
let actor_id = Url::parse(protocol_and_hostname)?; let actor_id = Url::parse(protocol_and_hostname)?;
let site_form = SiteUpdateForm { let site_form = SiteUpdateForm {
actor_id: Some(actor_id.clone().into()), 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()?), inbox_url: Some(generate_inbox_url()?),
private_key: Some(Some(key_pair.private_key)), private_key: Some(Some(key_pair.private_key)),
public_key: Some(key_pair.public_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()); .unwrap_or_else(|| "New Site".to_string());
let site_form = SiteInsertForm { let site_form = SiteInsertForm {
actor_id: Some(site_actor_id.clone().into()), 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()?), inbox_url: Some(generate_inbox_url()?),
private_key: Some(site_key_pair.private_key), private_key: Some(site_key_pair.private_key),
public_key: Some(site_key_pair.public_key), public_key: Some(site_key_pair.public_key),

View file

@ -36,15 +36,7 @@ use lemmy_db_schema::{
post::{Post, PostUpdateForm}, post::{Post, PostUpdateForm},
}, },
traits::Crud, traits::Crud,
utils::{ utils::{find_action, functions::coalesce, get_conn, now, DbPool, DELETED_REPLACEMENT_TEXT},
find_action,
functions::coalesce,
get_conn,
naive_now,
now,
DbPool,
DELETED_REPLACEMENT_TEXT,
},
}; };
use lemmy_routes::nodeinfo::{NodeInfo, NodeInfoWellKnown}; use lemmy_routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
use lemmy_utils::error::LemmyResult; 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 // Activitypub). That's why we always need to mark instances as updated if they are
// alive. // alive.
let mut instance_form = InstanceForm { let mut instance_form = InstanceForm {
updated: Some(naive_now()), updated: Some(Utc::now()),
..InstanceForm::new(domain.to_string()) ..InstanceForm::new(domain.to_string())
}; };