Merge remote-tracking branch 'origin/main' into persistent-queue

This commit is contained in:
phiresky 2023-08-24 15:50:09 +00:00
commit 10e494020c
101 changed files with 1915 additions and 1290 deletions

1546
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -68,7 +68,7 @@ lemmy_routes = { version = "=0.18.1", path = "./crates/routes" }
lemmy_db_views = { version = "=0.18.1", path = "./crates/db_views" } lemmy_db_views = { version = "=0.18.1", path = "./crates/db_views" }
lemmy_db_views_actor = { version = "=0.18.1", path = "./crates/db_views_actor" } lemmy_db_views_actor = { version = "=0.18.1", path = "./crates/db_views_actor" }
lemmy_db_views_moderator = { version = "=0.18.1", path = "./crates/db_views_moderator" } lemmy_db_views_moderator = { version = "=0.18.1", path = "./crates/db_views_moderator" }
activitypub_federation = { version = "0.4.6", default-features = false, features = [ activitypub_federation = { version = "0.5.0-beta.1", default-features = false, features = [
"actix-web", "actix-web",
], git = "https://github.com/phiresky/activitypub-federation-rust/", branch = "raw-sending" } ], git = "https://github.com/phiresky/activitypub-federation-rust/", branch = "raw-sending" }
diesel = "2.1.0" diesel = "2.1.0"

View File

@ -27,7 +27,7 @@ pub async fn list_comment_reports(
page, page,
limit, limit,
} }
.list(&mut context.pool(), &local_user_view.person) .list(&mut context.pool(), &local_user_view)
.await?; .await?;
Ok(Json(ListCommentReportsResponse { comment_reports })) Ok(Json(ListCommentReportsResponse { comment_reports }))

View File

@ -28,7 +28,7 @@ pub async fn add_mod_to_community(
// Verify that only mods or admins can add mod // Verify that only mods or admins can add mod
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?; is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
let community = Community::read(&mut context.pool(), community_id).await?; let community = Community::read(&mut context.pool(), community_id).await?;
if local_user_view.person.admin && !community.local { if local_user_view.local_user.admin && !community.local {
return Err(LemmyErrorType::NotAModerator)?; return Err(LemmyErrorType::NotAModerator)?;
} }

View File

@ -7,8 +7,8 @@ use lemmy_api_common::{
}; };
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{ source::{
local_user::{LocalUser, LocalUserUpdateForm},
moderator::{ModAdd, ModAddForm}, moderator::{ModAdd, ModAddForm},
person::{Person, PersonUpdateForm},
}, },
traits::Crud, traits::Crud,
}; };
@ -27,13 +27,11 @@ impl Perform for AddAdmin {
// Make sure user is an admin // Make sure user is an admin
is_admin(&local_user_view)?; is_admin(&local_user_view)?;
let added = data.added; let added_admin = LocalUser::update(
let added_person_id = data.person_id;
let added_admin = Person::update(
&mut context.pool(), &mut context.pool(),
added_person_id, data.local_user_id,
&PersonUpdateForm { &LocalUserUpdateForm {
admin: Some(added), admin: Some(data.added),
..Default::default() ..Default::default()
}, },
) )
@ -43,7 +41,7 @@ impl Perform for AddAdmin {
// Mod tables // Mod tables
let form = ModAddForm { let form = ModAddForm {
mod_person_id: local_user_view.person.id, mod_person_id: local_user_view.person.id,
other_person_id: added_admin.id, other_person_id: added_admin.person_id,
removed: Some(!data.added), removed: Some(!data.added),
}; };

View File

@ -9,6 +9,7 @@ use lemmy_db_schema::{
source::person_block::{PersonBlock, PersonBlockForm}, source::person_block::{PersonBlock, PersonBlockForm},
traits::Blockable, traits::Blockable,
}; };
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView; use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType}; use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
@ -34,9 +35,8 @@ impl Perform for BlockPerson {
target_id, target_id,
}; };
let target_person_view = PersonView::read(&mut context.pool(), target_id).await?; let target_user = LocalUserView::read_person(&mut context.pool(), target_id).await;
if target_user.map(|t| t.local_user.admin) == Ok(true) {
if target_person_view.person.admin {
return Err(LemmyErrorType::CantBlockAdmin)?; return Err(LemmyErrorType::CantBlockAdmin)?;
} }
@ -50,8 +50,9 @@ impl Perform for BlockPerson {
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?; .with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
} }
let person_view = PersonView::read(&mut context.pool(), target_id).await?;
Ok(BlockPersonResponse { Ok(BlockPersonResponse {
person_view: target_person_view, person_view,
blocked: data.block, blocked: data.block,
}) })
} }

View File

@ -47,7 +47,7 @@ impl Perform for Login {
// Check if the user's email is verified if email verification is turned on // Check if the user's email is verified if email verification is turned on
// However, skip checking verification if the user is an admin // However, skip checking verification if the user is an admin
if !local_user_view.person.admin if !local_user_view.local_user.admin
&& site_view.local_site.require_email_verification && site_view.local_site.require_email_verification
&& !local_user_view.local_user.email_verified && !local_user_view.local_user.email_verified
{ {

View File

@ -21,7 +21,7 @@ impl Perform for GetReportCount {
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?; let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
let person_id = local_user_view.person.id; let person_id = local_user_view.person.id;
let admin = local_user_view.person.admin; let admin = local_user_view.local_user.admin;
let community_id = data.community_id; let community_id = data.community_id;
let comment_reports = let comment_reports =

View File

@ -33,7 +33,7 @@ impl Perform for ListPostReports {
page, page,
limit, limit,
} }
.list(&mut context.pool(), &local_user_view.person) .list(&mut context.pool(), &local_user_view)
.await?; .await?;
Ok(ListPostReportsResponse { post_reports }) Ok(ListPostReportsResponse { post_reports })

View File

@ -9,8 +9,8 @@ use lemmy_db_schema::{
source::{ source::{
actor_language::SiteLanguage, actor_language::SiteLanguage,
language::Language, language::Language,
local_user::{LocalUser, LocalUserUpdateForm},
moderator::{ModAdd, ModAddForm}, moderator::{ModAdd, ModAddForm},
person::{Person, PersonUpdateForm},
tagline::Tagline, tagline::Tagline,
}, },
traits::Crud, traits::Crud,
@ -39,11 +39,10 @@ impl Perform for LeaveAdmin {
return Err(LemmyErrorType::CannotLeaveAdmin)?; return Err(LemmyErrorType::CannotLeaveAdmin)?;
} }
let person_id = local_user_view.person.id; LocalUser::update(
Person::update(
&mut context.pool(), &mut context.pool(),
person_id, local_user_view.local_user.id,
&PersonUpdateForm { &LocalUserUpdateForm {
admin: Some(false), admin: Some(false),
..Default::default() ..Default::default()
}, },
@ -51,6 +50,7 @@ impl Perform for LeaveAdmin {
.await?; .await?;
// Mod tables // Mod tables
let person_id = local_user_view.person.id;
let form = ModAddForm { let form = ModAddForm {
mod_person_id: person_id, mod_person_id: person_id,
other_person_id: person_id, other_person_id: person_id,

View File

@ -1,6 +1,6 @@
use crate::sensitive::Sensitive; use crate::sensitive::Sensitive;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId}, newtypes::{CommentReplyId, CommunityId, LanguageId, LocalUserId, PersonId, PersonMentionId},
CommentSortType, CommentSortType,
ListingType, ListingType,
SortType, SortType,
@ -207,7 +207,7 @@ pub struct MarkAllAsRead {
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// Adds an admin to a site. /// Adds an admin to a site.
pub struct AddAdmin { pub struct AddAdmin {
pub person_id: PersonId, pub local_user_id: LocalUserId,
pub added: bool, pub added: bool,
pub auth: Sensitive<String>, pub auth: Sensitive<String>,
} }

View File

@ -5,7 +5,7 @@ use crate::{
site::FederatedInstances, site::FederatedInstances,
}; };
use anyhow::Context; use anyhow::Context;
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_db_schema::{ use lemmy_db_schema::{
impls::person::is_banned, impls::person::is_banned,
newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId}, newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId},
@ -78,8 +78,8 @@ pub async fn is_mod_or_admin_opt(
} }
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> { pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
if !local_user_view.person.admin { if !local_user_view.local_user.admin {
Err(LemmyErrorType::NotAnAdmin)?; return Err(LemmyErrorType::NotAnAdmin)?;
} }
Ok(()) Ok(())
} }
@ -163,7 +163,7 @@ pub async fn local_user_view_from_jwt_opt(
/// Checks if user's token was issued before user's password reset. /// Checks if user's token was issued before user's password reset.
pub fn check_validator_time( pub fn check_validator_time(
validator_time: &NaiveDateTime, validator_time: &DateTime<Utc>,
claims: &Claims, claims: &Claims,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let user_validation_time = validator_time.timestamp(); let user_validation_time = validator_time.timestamp();
@ -176,7 +176,7 @@ pub fn check_validator_time(
pub fn check_user_valid( pub fn check_user_valid(
banned: bool, banned: bool,
ban_expires: Option<NaiveDateTime>, ban_expires: Option<DateTime<Utc>>,
deleted: bool, deleted: bool,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
// Check for a site ban // Check for a site ban
@ -500,7 +500,7 @@ pub async fn check_registration_application(
if (local_site.registration_mode == RegistrationMode::RequireApplication if (local_site.registration_mode == RegistrationMode::RequireApplication
|| local_site.registration_mode == RegistrationMode::Closed) || local_site.registration_mode == RegistrationMode::Closed)
&& !local_user_view.local_user.accepted_application && !local_user_view.local_user.accepted_application
&& !local_user_view.person.admin && !local_user_view.local_user.admin
{ {
// Fetch the registration, see if its denied // Fetch the registration, see if its denied
let local_user_id = local_user_view.local_user.id; let local_user_id = local_user_view.local_user.id;

View File

@ -115,8 +115,6 @@ pub async fn register(
.public_key(actor_keypair.public_key) .public_key(actor_keypair.public_key)
.inbox_url(Some(generate_inbox_url(&actor_id)?)) .inbox_url(Some(generate_inbox_url(&actor_id)?))
.shared_inbox_url(Some(generate_shared_inbox_url(&actor_id)?)) .shared_inbox_url(Some(generate_shared_inbox_url(&actor_id)?))
// If its the initial site setup, they are an admin
.admin(Some(!local_site.site_setup))
.instance_id(site_view.site.instance_id) .instance_id(site_view.site.instance_id)
.build(); .build();
@ -137,6 +135,8 @@ pub async fn register(
.show_nsfw(Some(data.show_nsfw)) .show_nsfw(Some(data.show_nsfw))
.accepted_application(accepted_application) .accepted_application(accepted_application)
.default_listing_type(Some(local_site.default_post_listing_type)) .default_listing_type(Some(local_site.default_post_listing_type))
// If its the initial site setup, they are an admin
.admin(Some(!local_site.site_setup))
.build(); .build();
let inserted_local_user = LocalUser::create(&mut context.pool(), &local_user_form).await?; let inserted_local_user = LocalUser::create(&mut context.pool(), &local_user_form).await?;

View File

@ -8,6 +8,6 @@
"type": "Block", "type": "Block",
"removeData": true, "removeData": true,
"summary": "spam post", "summary": "spam post",
"expires": "2021-11-01T12:23:50.151874+00:00", "expires": "2021-11-01T12:23:50.151874Z",
"id": "http://enterprise.lemmy.ml/activities/block/5d42fffb-0903-4625-86d4-0b39bb344fc2" "id": "http://enterprise.lemmy.ml/activities/block/5d42fffb-0903-4625-86d4-0b39bb344fc2"
} }

View File

@ -11,7 +11,7 @@
"type": "Block", "type": "Block",
"removeData": true, "removeData": true,
"summary": "spam post", "summary": "spam post",
"expires": "2021-11-01T12:23:50.151874+00:00", "expires": "2021-11-01T12:23:50.151874Z",
"id": "http://enterprise.lemmy.ml/activities/block/726f43ab-bd0e-4ab3-89c8-627e976f553c" "id": "http://enterprise.lemmy.ml/activities/block/726f43ab-bd0e-4ab3-89c8-627e976f553c"
}, },
"cc": ["http://enterprise.lemmy.ml/c/main"], "cc": ["http://enterprise.lemmy.ml/c/main"],

View File

@ -17,7 +17,7 @@
"commentsEnabled": true, "commentsEnabled": true,
"sensitive": false, "sensitive": false,
"stickied": false, "stickied": false,
"published": "2021-11-01T12:11:22.871846+00:00" "published": "2021-11-01T12:11:22.871846Z"
}, },
"cc": ["http://enterprise.lemmy.ml/c/main"], "cc": ["http://enterprise.lemmy.ml/c/main"],
"type": "Create", "type": "Create",

View File

@ -35,8 +35,8 @@
"name": "Deutsch" "name": "Deutsch"
} }
], ],
"published": "2021-10-29T15:05:51.476984+00:00", "published": "2021-10-29T15:05:51.476984Z",
"updated": "2021-11-01T12:23:50.151874+00:00" "updated": "2021-11-01T12:23:50.151874Z"
}, },
"cc": ["http://enterprise.lemmy.ml/c/main"], "cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "http://enterprise.lemmy.ml/u/main", "audience": "http://enterprise.lemmy.ml/u/main",

View File

@ -18,7 +18,7 @@
"mediaType": "text/markdown" "mediaType": "text/markdown"
}, },
"inReplyTo": "http://ds9.lemmy.ml/post/1", "inReplyTo": "http://ds9.lemmy.ml/post/1",
"published": "2021-11-01T11:45:49.794920+00:00" "published": "2021-11-01T11:45:49.794920Z"
}, },
"cc": [ "cc": [
"http://enterprise.lemmy.ml/c/main", "http://enterprise.lemmy.ml/c/main",

View File

@ -29,7 +29,7 @@
"identifier": "ko", "identifier": "ko",
"name": "한국어" "name": "한국어"
}, },
"published": "2021-10-29T15:10:51.557399+00:00" "published": "2021-10-29T15:10:51.557399Z"
}, },
"cc": ["http://enterprise.lemmy.ml/c/main"], "cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "https://enterprise.lemmy.ml/c/main", "audience": "https://enterprise.lemmy.ml/c/main",

View File

@ -13,7 +13,7 @@
"content": "hello", "content": "hello",
"mediaType": "text/markdown" "mediaType": "text/markdown"
}, },
"published": "2021-10-29T15:31:56.058289+00:00" "published": "2021-10-29T15:31:56.058289Z"
}, },
"type": "Create" "type": "Create"
} }

View File

@ -25,8 +25,8 @@
], ],
"commentsEnabled": true, "commentsEnabled": true,
"sensitive": false, "sensitive": false,
"published": "2021-10-29T15:10:51.557399+00:00", "published": "2021-10-29T15:10:51.557399Z",
"updated": "2021-10-29T15:11:35.976374+00:00" "updated": "2021-10-29T15:11:35.976374Z"
}, },
"cc": ["http://enterprise.lemmy.ml/c/main"], "cc": ["http://enterprise.lemmy.ml/c/main"],
"audience": "https://enterprise.lemmy.ml/c/main", "audience": "https://enterprise.lemmy.ml/c/main",

View File

@ -17,7 +17,7 @@
"attachment": [], "attachment": [],
"commentsEnabled": true, "commentsEnabled": true,
"sensitive": false, "sensitive": false,
"published": "2023-02-06T06:42:41.939437+00:00", "published": "2023-02-06T06:42:41.939437Z",
"language": { "language": {
"identifier": "de", "identifier": "de",
"name": "Deutsch" "name": "Deutsch"
@ -38,7 +38,7 @@
"attachment": [], "attachment": [],
"commentsEnabled": true, "commentsEnabled": true,
"sensitive": false, "sensitive": false,
"published": "2023-02-06T06:42:37.119567+00:00", "published": "2023-02-06T06:42:37.119567Z",
"language": { "language": {
"identifier": "de", "identifier": "de",
"name": "Deutsch" "name": "Deutsch"

View File

@ -25,7 +25,7 @@
"commentsEnabled": true, "commentsEnabled": true,
"sensitive": false, "sensitive": false,
"stickied": false, "stickied": false,
"published": "2021-11-18T17:19:45.895163+00:00" "published": "2021-11-18T17:19:45.895163Z"
} }
}, },
"cc": ["https://ds9.lemmy.ml/c/testcom/followers"], "cc": ["https://ds9.lemmy.ml/c/testcom/followers"],
@ -54,7 +54,7 @@
"commentsEnabled": true, "commentsEnabled": true,
"sensitive": false, "sensitive": false,
"stickied": false, "stickied": false,
"published": "2021-11-18T17:19:05.763109+00:00" "published": "2021-11-18T17:19:05.763109Z"
} }
}, },
"cc": ["https://ds9.lemmy.ml/c/testcom/followers"], "cc": ["https://ds9.lemmy.ml/c/testcom/followers"],

View File

@ -9,5 +9,5 @@
"content": "Hello hello, testing", "content": "Hello hello, testing",
"mediaType": "text/markdown" "mediaType": "text/markdown"
}, },
"published": "2021-10-21T10:13:14.597721+00:00" "published": "2021-10-21T10:13:14.597721Z"
} }

View File

@ -41,6 +41,6 @@
"name": "Deutsch" "name": "Deutsch"
} }
], ],
"published": "2019-06-02T16:43:50.799554+00:00", "published": "2019-06-02T16:43:50.799554Z",
"updated": "2021-03-10T17:18:10.498868+00:00" "updated": "2021-03-10T17:18:10.498868Z"
} }

View File

@ -26,5 +26,5 @@
"name": "Español" "name": "Español"
} }
], ],
"published": "2022-01-19T21:52:11.110741+00:00" "published": "2022-01-19T21:52:11.110741Z"
} }

View File

@ -27,6 +27,6 @@
"identifier": "fr", "identifier": "fr",
"name": "Français" "name": "Français"
}, },
"published": "2021-03-01T13:42:43.966208+00:00", "published": "2021-03-01T13:42:43.966208Z",
"updated": "2021-03-01T13:43:03.955787+00:00" "updated": "2021-03-01T13:43:03.955787Z"
} }

View File

@ -30,5 +30,5 @@
"identifier": "fr", "identifier": "fr",
"name": "Français" "name": "Français"
}, },
"published": "2021-02-26T12:35:34.292626+00:00" "published": "2021-02-26T12:35:34.292626Z"
} }

View File

@ -22,8 +22,8 @@
"endpoints": { "endpoints": {
"sharedInbox": "https://enterprise.lemmy.ml/inbox" "sharedInbox": "https://enterprise.lemmy.ml/inbox"
}, },
"published": "2020-01-17T01:38:22.348392+00:00", "published": "2020-01-17T01:38:22.348392Z",
"updated": "2021-08-13T00:11:15.941990+00:00", "updated": "2021-08-13T00:11:15.941990Z",
"publicKey": { "publicKey": {
"id": "https://enterprise.lemmy.ml/u/picard#main-key", "id": "https://enterprise.lemmy.ml/u/picard#main-key",
"owner": "https://enterprise.lemmy.ml/u/picard", "owner": "https://enterprise.lemmy.ml/u/picard",

View File

@ -20,7 +20,7 @@ use activitypub_federation::{
traits::{ActivityHandler, Actor}, traits::{ActivityHandler, Actor},
}; };
use anyhow::anyhow; use anyhow::anyhow;
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{remove_user_data, remove_user_data_in_community, sanitize_html_opt}, utils::{remove_user_data, remove_user_data_in_community, sanitize_html_opt},
@ -39,7 +39,7 @@ use lemmy_db_schema::{
}, },
traits::{Bannable, Crud, Followable}, traits::{Bannable, Crud, Followable},
}; };
use lemmy_utils::{error::LemmyError, utils::time::convert_datetime}; use lemmy_utils::error::LemmyError;
use url::Url; use url::Url;
impl BlockUser { impl BlockUser {
@ -49,7 +49,7 @@ impl BlockUser {
mod_: &ApubPerson, mod_: &ApubPerson,
remove_data: Option<bool>, remove_data: Option<bool>,
reason: Option<String>, reason: Option<String>,
expires: Option<NaiveDateTime>, expires: Option<DateTime<Utc>>,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<BlockUser, LemmyError> { ) -> Result<BlockUser, LemmyError> {
let audience = if let SiteOrCommunity::Community(c) = target { let audience = if let SiteOrCommunity::Community(c) = target {
@ -71,7 +71,7 @@ impl BlockUser {
&context.settings().get_protocol_and_hostname(), &context.settings().get_protocol_and_hostname(),
)?, )?,
audience, audience,
expires: expires.map(convert_datetime), expires,
}) })
} }
@ -82,7 +82,7 @@ impl BlockUser {
mod_: &ApubPerson, mod_: &ApubPerson,
remove_data: bool, remove_data: bool,
reason: Option<String>, reason: Option<String>,
expires: Option<NaiveDateTime>, expires: Option<DateTime<Utc>>,
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> Result<(), LemmyError> { ) -> Result<(), LemmyError> {
let block = BlockUser::new( let block = BlockUser::new(
@ -149,7 +149,7 @@ impl ActivityHandler for BlockUser {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
let expires = self.expires.map(|u| u.naive_local()); let expires = self.expires.map(Into::into);
let mod_person = self.actor.dereference(context).await?; let mod_person = self.actor.dereference(context).await?;
let blocked_person = self.object.dereference(context).await?; let blocked_person = self.object.dereference(context).await?;
let target = self.target.dereference(context).await?; let target = self.target.dereference(context).await?;

View File

@ -10,7 +10,7 @@ use activitypub_federation::{
fetch::object_id::ObjectId, fetch::object_id::ObjectId,
traits::{Actor, Object}, traits::{Actor, Object},
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{community::BanFromCommunity, context::LemmyContext, person::BanPerson}; use lemmy_api_common::{community::BanFromCommunity, context::LemmyContext, person::BanPerson};
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::CommunityId, newtypes::CommunityId,
@ -49,7 +49,7 @@ impl Object for SiteOrCommunity {
type Error = LemmyError; type Error = LemmyError;
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(match self { Some(match self {
SiteOrCommunity::Site(i) => i.last_refreshed_at, SiteOrCommunity::Site(i) => i.last_refreshed_at,
SiteOrCommunity::Community(c) => c.last_refreshed_at, SiteOrCommunity::Community(c) => c.last_refreshed_at,

View File

@ -98,7 +98,7 @@ impl ActivityHandler for UndoBlockUser {
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> { async fn receive(self, context: &Data<LemmyContext>) -> Result<(), LemmyError> {
let expires = self.object.expires.map(|u| u.naive_local()); let expires = self.object.expires.map(Into::into);
let mod_person = self.actor.dereference(context).await?; let mod_person = self.actor.dereference(context).await?;
let blocked_person = self.object.object.dereference(context).await?; let blocked_person = self.object.object.dereference(context).await?;
match self.object.target.dereference(context).await? { match self.object.target.dereference(context).await? {

View File

@ -6,7 +6,7 @@ use crate::{
}, },
}; };
use activitypub_federation::{config::Data, traits::Object}; use activitypub_federation::{config::Data, traits::Object};
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{community::Community, post::Post}, source::{community::Community, post::Post},
@ -35,7 +35,7 @@ impl Object for PostOrComment {
type Kind = PageOrNote; type Kind = PageOrNote;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None None
} }

View File

@ -7,7 +7,7 @@ use activitypub_federation::{
fetch::{object_id::ObjectId, webfinger::webfinger_resolve_actor}, fetch::{object_id::ObjectId, webfinger::webfinger_resolve_actor},
traits::Object, traits::Object,
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::{LemmyError, LemmyErrorType}; use lemmy_utils::error::{LemmyError, LemmyErrorType};
use serde::Deserialize; use serde::Deserialize;
@ -80,7 +80,7 @@ impl Object for SearchableObjects {
type Kind = SearchableKinds; type Kind = SearchableKinds;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
match self { match self {
SearchableObjects::Person(p) => p.last_refreshed_at(), SearchableObjects::Person(p) => p.last_refreshed_at(),
SearchableObjects::Community(c) => c.last_refreshed_at(), SearchableObjects::Community(c) => c.last_refreshed_at(),

View File

@ -7,7 +7,7 @@ use activitypub_federation::{
config::Data, config::Data,
traits::{Actor, Object}, traits::{Actor, Object},
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::source::activity::ActorType; use lemmy_db_schema::source::activity::ActorType;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyError;
@ -39,7 +39,7 @@ impl Object for UserOrCommunity {
type Kind = PersonOrGroup; type Kind = PersonOrGroup;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(match self { Some(match self {
UserOrCommunity::User(p) => p.last_refreshed_at, UserOrCommunity::User(p) => p.last_refreshed_at,
UserOrCommunity::Community(p) => p.last_refreshed_at, UserOrCommunity::Community(p) => p.last_refreshed_at,

View File

@ -1,5 +1,6 @@
use crate::fetcher::post_or_comment::PostOrComment; use crate::fetcher::post_or_comment::PostOrComment;
use activitypub_federation::config::{Data, UrlVerifier}; use activitypub_federation::config::{Data, UrlVerifier};
use anyhow::anyhow;
use async_trait::async_trait; use async_trait::async_trait;
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{ use lemmy_db_schema::{
@ -38,7 +39,7 @@ pub struct VerifyUrlData(pub ActualDbPool);
#[async_trait] #[async_trait]
impl UrlVerifier for VerifyUrlData { impl UrlVerifier for VerifyUrlData {
async fn verify(&self, url: &Url) -> Result<(), &'static str> { async fn verify(&self, url: &Url) -> Result<(), anyhow::Error> {
let local_site_data = local_site_data_cached(&mut (&self.0).into()) let local_site_data = local_site_data_cached(&mut (&self.0).into())
.await .await
.expect("read local site data"); .expect("read local site data");
@ -46,16 +47,16 @@ impl UrlVerifier for VerifyUrlData {
LemmyError { LemmyError {
error_type: LemmyErrorType::FederationDisabled, error_type: LemmyErrorType::FederationDisabled,
.. ..
} => "Federation disabled", } => anyhow!("Federation disabled"),
LemmyError { LemmyError {
error_type: LemmyErrorType::DomainBlocked(_), error_type: LemmyErrorType::DomainBlocked(_),
.. ..
} => "Domain is blocked", } => anyhow!("Domain is blocked"),
LemmyError { LemmyError {
error_type: LemmyErrorType::DomainNotInAllowList(_), error_type: LemmyErrorType::DomainNotInAllowList(_),
.. ..
} => "Domain is not in allowlist", } => anyhow!("Domain is not in allowlist"),
_ => "Failed validating apub id", _ => anyhow!("Failed validating apub id"),
})?; })?;
Ok(()) Ok(())
} }

View File

@ -15,7 +15,7 @@ use activitypub_federation::{
protocol::{values::MediaTypeMarkdownOrHtml, verification::verify_domains_match}, protocol::{values::MediaTypeMarkdownOrHtml, verification::verify_domains_match},
traits::Object, traits::Object,
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{local_site_opt_to_slur_regex, sanitize_html}, utils::{local_site_opt_to_slur_regex, sanitize_html},
@ -59,7 +59,7 @@ impl Object for ApubComment {
type Kind = Note; type Kind = Note;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None None
} }
@ -170,8 +170,8 @@ impl Object for ApubComment {
post_id: post.id, post_id: post.id,
content, content,
removed: None, removed: None,
published: note.published.map(|u| u.naive_local()), published: note.published.map(Into::into),
updated: note.updated.map(|u| u.naive_local()), updated: note.updated.map(Into::into),
deleted: Some(false), deleted: Some(false),
ap_id: Some(note.id.into()), ap_id: Some(note.id.into()),
distinguished: note.distinguished, distinguished: note.distinguished,

View File

@ -14,7 +14,7 @@ use activitypub_federation::{
kinds::actor::GroupType, kinds::actor::GroupType,
traits::{Actor, Object}, traits::{Actor, Object},
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{generate_featured_url, generate_moderators_url, generate_outbox_url}, utils::{generate_featured_url, generate_moderators_url, generate_outbox_url},
@ -58,7 +58,7 @@ impl Object for ApubCommunity {
type Kind = Group; type Kind = Group;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(self.last_refreshed_at) Some(self.last_refreshed_at)
} }

View File

@ -16,7 +16,7 @@ use activitypub_federation::{
protocol::{values::MediaTypeHtml, verification::verify_domains_match}, protocol::{values::MediaTypeHtml, verification::verify_domains_match},
traits::{Actor, Object}, traits::{Actor, Object},
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{local_site_opt_to_slur_regex, sanitize_html_opt}, utils::{local_site_opt_to_slur_regex, sanitize_html_opt},
@ -66,7 +66,7 @@ impl Object for ApubSite {
type Kind = Instance; type Kind = Instance;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(self.last_refreshed_at) Some(self.last_refreshed_at)
} }
@ -141,7 +141,7 @@ impl Object for ApubSite {
let site_form = SiteInsertForm { let site_form = SiteInsertForm {
name: apub.name.clone(), name: apub.name.clone(),
sidebar, sidebar,
updated: apub.updated.map(|u| u.clone().naive_local()), updated: apub.updated,
icon: apub.icon.clone().map(|i| i.url.into()), icon: apub.icon.clone().map(|i| i.url.into()),
banner: apub.image.clone().map(|i| i.url.into()), banner: apub.image.clone().map(|i| i.url.into()),
description, description,

View File

@ -17,7 +17,7 @@ use activitypub_federation::{
protocol::verification::verify_domains_match, protocol::verification::verify_domains_match,
traits::{Actor, Object}, traits::{Actor, Object},
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{generate_outbox_url, local_site_opt_to_slur_regex, sanitize_html, sanitize_html_opt}, utils::{generate_outbox_url, local_site_opt_to_slur_regex, sanitize_html, sanitize_html_opt},
@ -63,7 +63,7 @@ impl Object for ApubPerson {
type Kind = Person; type Kind = Person;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
Some(self.last_refreshed_at) Some(self.last_refreshed_at)
} }
@ -162,12 +162,11 @@ impl Object for ApubPerson {
deleted: Some(false), deleted: Some(false),
avatar: person.icon.map(|i| i.url.into()), avatar: person.icon.map(|i| i.url.into()),
banner: person.image.map(|i| i.url.into()), banner: person.image.map(|i| i.url.into()),
published: person.published.map(|u| u.naive_local()), published: person.published.map(Into::into),
updated: person.updated.map(|u| u.naive_local()), updated: person.updated.map(Into::into),
actor_id: Some(person.id.into()), actor_id: Some(person.id.into()),
bio, bio,
local: Some(false), local: Some(false),
admin: Some(false),
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,

View File

@ -20,7 +20,7 @@ use activitypub_federation::{
traits::Object, traits::Object,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use html2md::parse_html; use html2md::parse_html;
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
@ -80,7 +80,7 @@ impl Object for ApubPost {
type Kind = Page; type Kind = Page;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None None
} }
@ -249,8 +249,8 @@ impl Object for ApubPost {
community_id: community.id, community_id: community.id,
removed: None, removed: None,
locked: page.comments_enabled.map(|e| !e), locked: page.comments_enabled.map(|e| !e),
published: page.published.map(|u| u.naive_local()), published: page.published.map(Into::into),
updated: page.updated.map(|u| u.naive_local()), updated: page.updated.map(Into::into),
deleted: Some(false), deleted: Some(false),
nsfw: page.sensitive, nsfw: page.sensitive,
embed_title, embed_title,
@ -271,7 +271,7 @@ impl Object for ApubPost {
.community_id(community.id) .community_id(community.id)
.ap_id(Some(page.id.clone().into())) .ap_id(Some(page.id.clone().into()))
.locked(page.comments_enabled.map(|e| !e)) .locked(page.comments_enabled.map(|e| !e))
.updated(page.updated.map(|u| u.naive_local())) .updated(page.updated.map(Into::into))
.build() .build()
}; };

View File

@ -11,7 +11,7 @@ use activitypub_federation::{
protocol::{values::MediaTypeHtml, verification::verify_domains_match}, protocol::{values::MediaTypeHtml, verification::verify_domains_match},
traits::Object, traits::Object,
}; };
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{check_person_block, sanitize_html}, utils::{check_person_block, sanitize_html},
@ -52,7 +52,7 @@ impl Object for ApubPrivateMessage {
type Kind = ChatMessage; type Kind = ChatMessage;
type Error = LemmyError; type Error = LemmyError;
fn last_refreshed_at(&self) -> Option<NaiveDateTime> { fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
None None
} }
@ -130,8 +130,8 @@ impl Object for ApubPrivateMessage {
creator_id: creator.id, creator_id: creator.id,
recipient_id: recipient.id, recipient_id: recipient.id,
content, content,
published: note.published.map(|u| u.naive_local()), published: note.published.map(Into::into),
updated: note.updated.map(|u| u.naive_local()), updated: note.updated.map(Into::into),
deleted: Some(false), deleted: Some(false),
read: None, read: None,
ap_id: Some(note.id.into()), ap_id: Some(note.id.into()),

View File

@ -10,7 +10,7 @@ use activitypub_federation::{
protocol::helpers::deserialize_one_or_many, protocol::helpers::deserialize_one_or_many,
}; };
use anyhow::anyhow; use anyhow::anyhow;
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_utils::error::LemmyError; use lemmy_utils::error::LemmyError;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -38,7 +38,7 @@ pub struct BlockUser {
pub(crate) remove_data: Option<bool>, pub(crate) remove_data: Option<bool>,
/// block reason, written to mod log /// block reason, written to mod log
pub(crate) summary: Option<String>, pub(crate) summary: Option<String>,
pub(crate) expires: Option<DateTime<FixedOffset>>, pub(crate) expires: Option<DateTime<Utc>>,
} }
#[async_trait::async_trait] #[async_trait::async_trait]

View File

@ -9,7 +9,7 @@ use activitypub_federation::{
values::MediaTypeHtml, values::MediaTypeHtml,
}, },
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
@ -27,8 +27,8 @@ pub struct ChatMessage {
pub(crate) media_type: Option<MediaTypeHtml>, pub(crate) media_type: Option<MediaTypeHtml>,
#[serde(deserialize_with = "deserialize_skip_error", default)] #[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) source: Option<Source>, pub(crate) source: Option<Source>,
pub(crate) published: Option<DateTime<FixedOffset>>, pub(crate) published: Option<DateTime<Utc>>,
pub(crate) updated: Option<DateTime<FixedOffset>>, pub(crate) updated: Option<DateTime<Utc>>,
} }
/// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages /// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages

View File

@ -22,7 +22,7 @@ use activitypub_federation::{
verification::verify_domains_match, verification::verify_domains_match,
}, },
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use lemmy_api_common::{ use lemmy_api_common::{
context::LemmyContext, context::LemmyContext,
utils::{local_site_opt_to_slur_regex, sanitize_html, sanitize_html_opt}, utils::{local_site_opt_to_slur_regex, sanitize_html, sanitize_html_opt},
@ -73,8 +73,8 @@ pub struct Group {
pub(crate) featured: Option<CollectionId<ApubCommunityFeatured>>, pub(crate) featured: Option<CollectionId<ApubCommunityFeatured>>,
#[serde(default)] #[serde(default)]
pub(crate) language: Vec<LanguageTag>, pub(crate) language: Vec<LanguageTag>,
pub(crate) published: Option<DateTime<FixedOffset>>, pub(crate) published: Option<DateTime<Utc>>,
pub(crate) updated: Option<DateTime<FixedOffset>>, pub(crate) updated: Option<DateTime<Utc>>,
} }
impl Group { impl Group {
@ -107,8 +107,8 @@ impl Group {
title, title,
description, description,
removed: None, removed: None,
published: self.published.map(|u| u.naive_local()), published: self.published,
updated: self.updated.map(|u| u.naive_local()), updated: self.updated,
deleted: Some(false), deleted: Some(false),
nsfw: Some(self.sensitive.unwrap_or(false)), nsfw: Some(self.sensitive.unwrap_or(false)),
actor_id: Some(self.id.into()), actor_id: Some(self.id.into()),
@ -138,8 +138,8 @@ impl Group {
&self.source, &self.source,
)), )),
removed: None, removed: None,
published: self.published.map(|u| u.naive_local()), published: self.published.map(Into::into),
updated: Some(self.updated.map(|u| u.naive_local())), updated: Some(self.updated.map(Into::into)),
deleted: None, deleted: None,
nsfw: Some(self.sensitive.unwrap_or(false)), nsfw: Some(self.sensitive.unwrap_or(false)),
actor_id: Some(self.id.into()), actor_id: Some(self.id.into()),

View File

@ -7,7 +7,7 @@ use activitypub_federation::{
kinds::actor::ApplicationType, kinds::actor::ApplicationType,
protocol::{helpers::deserialize_skip_error, public_key::PublicKey, values::MediaTypeHtml}, protocol::{helpers::deserialize_skip_error, public_key::PublicKey, values::MediaTypeHtml},
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url; use url::Url;
@ -39,6 +39,6 @@ pub struct Instance {
pub(crate) image: Option<ImageObject>, pub(crate) image: Option<ImageObject>,
#[serde(default)] #[serde(default)]
pub(crate) language: Vec<LanguageTag>, pub(crate) language: Vec<LanguageTag>,
pub(crate) published: DateTime<FixedOffset>, pub(crate) published: DateTime<Utc>,
pub(crate) updated: Option<DateTime<FixedOffset>>, pub(crate) updated: Option<DateTime<Utc>>,
} }

View File

@ -14,7 +14,7 @@ use activitypub_federation::{
values::MediaTypeMarkdownOrHtml, values::MediaTypeMarkdownOrHtml,
}, },
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{ use lemmy_db_schema::{
source::{community::Community, post::Post}, source::{community::Community, post::Post},
@ -43,8 +43,8 @@ pub struct Note {
pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>, pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>,
#[serde(deserialize_with = "deserialize_skip_error", default)] #[serde(deserialize_with = "deserialize_skip_error", default)]
pub(crate) source: Option<Source>, pub(crate) source: Option<Source>,
pub(crate) published: Option<DateTime<FixedOffset>>, pub(crate) published: Option<DateTime<Utc>>,
pub(crate) updated: Option<DateTime<FixedOffset>>, pub(crate) updated: Option<DateTime<Utc>>,
#[serde(default)] #[serde(default)]
pub(crate) tag: Vec<MentionOrValue>, pub(crate) tag: Vec<MentionOrValue>,
// lemmy extension // lemmy extension

View File

@ -17,7 +17,7 @@ use activitypub_federation::{
}, },
traits::{ActivityHandler, Object}, traits::{ActivityHandler, Object},
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use itertools::Itertools; use itertools::Itertools;
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::newtypes::DbUrl; use lemmy_db_schema::newtypes::DbUrl;
@ -63,8 +63,8 @@ pub struct Page {
pub(crate) image: Option<ImageObject>, pub(crate) image: Option<ImageObject>,
pub(crate) comments_enabled: Option<bool>, pub(crate) comments_enabled: Option<bool>,
pub(crate) sensitive: Option<bool>, pub(crate) sensitive: Option<bool>,
pub(crate) published: Option<DateTime<FixedOffset>>, pub(crate) published: Option<DateTime<Utc>>,
pub(crate) updated: Option<DateTime<FixedOffset>>, pub(crate) updated: Option<DateTime<Utc>>,
pub(crate) language: Option<LanguageTag>, pub(crate) language: Option<LanguageTag>,
pub(crate) audience: Option<ObjectId<ApubCommunity>>, pub(crate) audience: Option<ObjectId<ApubCommunity>>,
} }

View File

@ -6,7 +6,7 @@ use activitypub_federation::{
fetch::object_id::ObjectId, fetch::object_id::ObjectId,
protocol::{helpers::deserialize_skip_error, public_key::PublicKey}, protocol::{helpers::deserialize_skip_error, public_key::PublicKey},
}; };
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use url::Url; use url::Url;
@ -43,6 +43,6 @@ pub struct Person {
pub(crate) image: Option<ImageObject>, pub(crate) image: Option<ImageObject>,
pub(crate) matrix_user_id: Option<String>, pub(crate) matrix_user_id: Option<String>,
pub(crate) endpoints: Option<Endpoints>, pub(crate) endpoints: Option<Endpoints>,
pub(crate) published: Option<DateTime<FixedOffset>>, pub(crate) published: Option<DateTime<Utc>>,
pub(crate) updated: Option<DateTime<FixedOffset>>, pub(crate) updated: Option<DateTime<Utc>>,
} }

View File

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

View File

@ -14,7 +14,7 @@ index 255c6422..f2ccf5e2 100644
#[diesel(postgres_type(name = "registration_mode_enum"))] #[diesel(postgres_type(name = "registration_mode_enum"))]
pub struct RegistrationModeEnum; pub struct RegistrationModeEnum;
@@ -76,13 +76,13 @@ diesel::table! { @@ -76,13 +76,13 @@ diesel::table! {
published -> Timestamp, published -> Timestamptz,
} }
} }

View File

@ -13,7 +13,9 @@ use diesel::{
dsl::{now, IntervalDsl}, dsl::{now, IntervalDsl},
insert_into, insert_into,
result::Error, result::Error,
sql_types::Timestamptz,
ExpressionMethods, ExpressionMethods,
IntoSql,
QueryDsl, QueryDsl,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -31,7 +33,7 @@ impl EmailVerification {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
email_verification email_verification
.filter(verification_token.eq(token)) .filter(verification_token.eq(token))
.filter(published.gt(now - 7.days())) .filter(published.gt(now.into_sql::<Timestamptz>() - 7.days()))
.first::<Self>(conn) .first::<Self>(conn)
.await .await
} }

View File

@ -3,12 +3,12 @@ use crate::{
newtypes::InstanceId, newtypes::InstanceId,
schema::{federation_allowlist, federation_blocklist, instance, local_site, site}, schema::{federation_allowlist, federation_blocklist, instance, local_site, site},
source::instance::{Instance, InstanceForm}, source::instance::{Instance, InstanceForm},
utils::{functions::lower, get_conn, naive_now, DbPool}, utils::{functions::lower, get_conn, naive_now, now, DbPool},
}; };
use diesel::{ use diesel::{
dsl::{count_star, insert_into, now}, dsl::{count_star, insert_into, now},
result::Error, result::Error,
sql_types::{Nullable, Timestamp}, sql_types::{Nullable, Timestamptz},
ExpressionMethods, ExpressionMethods,
NullableExpressionMethods, NullableExpressionMethods,
QueryDsl, QueryDsl,
@ -68,7 +68,7 @@ impl Instance {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
instance::table instance::table
.select(instance::domain) .select(instance::domain)
.filter(coalesce(instance::updated, instance::published).lt(now - 3.days())) .filter(coalesce(instance::updated, instance::published).lt(now() - 3.days()))
.get_results(conn) .get_results(conn)
.await .await
} }
@ -142,4 +142,4 @@ impl Instance {
} }
} }
sql_function! { fn coalesce(x: Nullable<Timestamp>, y: Timestamp) -> Timestamp; } sql_function! { fn coalesce(x: Nullable<Timestamptz>, y: Timestamptz) -> Timestamptz; }

View File

@ -8,7 +8,9 @@ use crate::{
use diesel::{ use diesel::{
dsl::{insert_into, now, IntervalDsl}, dsl::{insert_into, now, IntervalDsl},
result::Error, result::Error,
sql_types::Timestamptz,
ExpressionMethods, ExpressionMethods,
IntoSql,
QueryDsl, QueryDsl,
}; };
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -59,7 +61,7 @@ impl PasswordResetRequest {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
password_reset_request password_reset_request
.filter(token.eq(token_)) .filter(token.eq(token_))
.filter(published.gt(now - 1.days())) .filter(published.gt(now.into_sql::<Timestamptz>() - 1.days()))
.first::<Self>(conn) .first::<Self>(conn)
.await .await
} }
@ -71,7 +73,7 @@ impl PasswordResetRequest {
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
password_reset_request password_reset_request
.filter(local_user_id.eq(user_id)) .filter(local_user_id.eq(user_id))
.filter(published.gt(now - 1.days())) .filter(published.gt(now.into_sql::<Timestamptz>() - 1.days()))
.count() .count()
.get_result(conn) .get_result(conn)
.await .await

View File

@ -11,6 +11,7 @@ use crate::{
traits::{ApubActor, Crud, Followable}, traits::{ApubActor, Crud, Followable},
utils::{functions::lower, get_conn, naive_now, DbPool}, utils::{functions::lower, get_conn, naive_now, DbPool},
}; };
use chrono::{DateTime, Utc};
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
@ -89,7 +90,7 @@ impl Person {
} }
} }
pub fn is_banned(banned_: bool, expires: Option<chrono::NaiveDateTime>) -> bool { pub fn is_banned(banned_: bool, expires: Option<DateTime<Utc>>) -> bool {
if let Some(expires) = expires { if let Some(expires) = expires {
banned_ && expires.gt(&naive_now()) banned_ && expires.gt(&naive_now())
} else { } else {
@ -240,7 +241,6 @@ mod tests {
bio: None, bio: None,
local: true, local: true,
bot_account: false, bot_account: false,
admin: false,
private_key: None, private_key: None,
public_key: "nada".to_owned(), public_key: "nada".to_owned(),
last_refreshed_at: inserted_person.published, last_refreshed_at: inserted_person.published,

View File

@ -24,7 +24,7 @@ diesel::table! {
admin_person_id -> Int4, admin_person_id -> Int4,
post_id -> Int4, post_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -33,7 +33,7 @@ diesel::table! {
id -> Int4, id -> Int4,
admin_person_id -> Int4, admin_person_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -42,7 +42,7 @@ diesel::table! {
id -> Int4, id -> Int4,
admin_person_id -> Int4, admin_person_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -52,7 +52,7 @@ diesel::table! {
admin_person_id -> Int4, admin_person_id -> Int4,
community_id -> Int4, community_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -61,7 +61,7 @@ diesel::table! {
id -> Int4, id -> Int4,
uuid -> Uuid, uuid -> Uuid,
answer -> Text, answer -> Text,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -75,8 +75,8 @@ diesel::table! {
post_id -> Int4, post_id -> Int4,
content -> Text, content -> Text,
removed -> Bool, removed -> Bool,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
deleted -> Bool, deleted -> Bool,
#[max_length = 255] #[max_length = 255]
ap_id -> Varchar, ap_id -> Varchar,
@ -94,7 +94,7 @@ diesel::table! {
score -> Int8, score -> Int8,
upvotes -> Int8, upvotes -> Int8,
downvotes -> Int8, downvotes -> Int8,
published -> Timestamp, published -> Timestamptz,
child_count -> Int4, child_count -> Int4,
hot_rank -> Int4, hot_rank -> Int4,
controversy_rank -> Float8, controversy_rank -> Float8,
@ -108,7 +108,7 @@ diesel::table! {
comment_id -> Int4, comment_id -> Int4,
post_id -> Int4, post_id -> Int4,
score -> Int2, score -> Int2,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -118,7 +118,7 @@ diesel::table! {
recipient_id -> Int4, recipient_id -> Int4,
comment_id -> Int4, comment_id -> Int4,
read -> Bool, read -> Bool,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -131,8 +131,8 @@ diesel::table! {
reason -> Text, reason -> Text,
resolved -> Bool, resolved -> Bool,
resolver_id -> Nullable<Int4>, resolver_id -> Nullable<Int4>,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -141,7 +141,7 @@ diesel::table! {
id -> Int4, id -> Int4,
comment_id -> Int4, comment_id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -154,8 +154,8 @@ diesel::table! {
title -> Varchar, title -> Varchar,
description -> Nullable<Text>, description -> Nullable<Text>,
removed -> Bool, removed -> Bool,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
deleted -> Bool, deleted -> Bool,
nsfw -> Bool, nsfw -> Bool,
#[max_length = 255] #[max_length = 255]
@ -163,7 +163,7 @@ diesel::table! {
local -> Bool, local -> Bool,
private_key -> Nullable<Text>, private_key -> Nullable<Text>,
public_key -> Text, public_key -> Text,
last_refreshed_at -> Timestamp, last_refreshed_at -> Timestamptz,
icon -> Nullable<Text>, icon -> Nullable<Text>,
banner -> Nullable<Text>, banner -> Nullable<Text>,
#[max_length = 255] #[max_length = 255]
@ -189,7 +189,7 @@ diesel::table! {
subscribers -> Int8, subscribers -> Int8,
posts -> Int8, posts -> Int8,
comments -> Int8, comments -> Int8,
published -> Timestamp, published -> Timestamptz,
users_active_day -> Int8, users_active_day -> Int8,
users_active_week -> Int8, users_active_week -> Int8,
users_active_month -> Int8, users_active_month -> Int8,
@ -203,7 +203,7 @@ diesel::table! {
id -> Int4, id -> Int4,
person_id -> Int4, person_id -> Int4,
community_id -> Int4, community_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -212,7 +212,7 @@ diesel::table! {
id -> Int4, id -> Int4,
community_id -> Int4, community_id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
pending -> Bool, pending -> Bool,
} }
} }
@ -230,7 +230,7 @@ diesel::table! {
id -> Int4, id -> Int4,
community_id -> Int4, community_id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -239,8 +239,8 @@ diesel::table! {
id -> Int4, id -> Int4,
community_id -> Int4, community_id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
expires -> Nullable<Timestamp>, expires -> Nullable<Timestamptz>,
} }
} }
@ -253,8 +253,8 @@ diesel::table! {
image_url -> Text, image_url -> Text,
alt_text -> Text, alt_text -> Text,
category -> Text, category -> Text,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -273,7 +273,7 @@ diesel::table! {
local_user_id -> Int4, local_user_id -> Int4,
email -> Text, email -> Text,
verification_token -> Text, verification_token -> Text,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -281,8 +281,8 @@ diesel::table! {
federation_allowlist (id) { federation_allowlist (id) {
id -> Int4, id -> Int4,
instance_id -> Int4, instance_id -> Int4,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -290,8 +290,8 @@ diesel::table! {
federation_blocklist (id) { federation_blocklist (id) {
id -> Int4, id -> Int4,
instance_id -> Int4, instance_id -> Int4,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -311,8 +311,8 @@ diesel::table! {
id -> Int4, id -> Int4,
#[max_length = 255] #[max_length = 255]
domain -> Varchar, domain -> Varchar,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
#[max_length = 255] #[max_length = 255]
software -> Nullable<Varchar>, software -> Nullable<Varchar>,
#[max_length = 255] #[max_length = 255]
@ -355,8 +355,8 @@ diesel::table! {
captcha_enabled -> Bool, captcha_enabled -> Bool,
#[max_length = 255] #[max_length = 255]
captcha_difficulty -> Varchar, captcha_difficulty -> Varchar,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
registration_mode -> RegistrationModeEnum, registration_mode -> RegistrationModeEnum,
reports_email_admins -> Bool, reports_email_admins -> Bool,
} }
@ -378,8 +378,8 @@ diesel::table! {
comment_per_second -> Int4, comment_per_second -> Int4,
search -> Int4, search -> Int4,
search_per_second -> Int4, search_per_second -> Int4,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -401,7 +401,7 @@ diesel::table! {
interface_language -> Varchar, interface_language -> Varchar,
show_avatars -> Bool, show_avatars -> Bool,
send_notifications_to_email -> Bool, send_notifications_to_email -> Bool,
validator_time -> Timestamp, validator_time -> Timestamptz,
show_scores -> Bool, show_scores -> Bool,
show_bot_accounts -> Bool, show_bot_accounts -> Bool,
show_read_posts -> Bool, show_read_posts -> Bool,
@ -411,9 +411,10 @@ diesel::table! {
totp_2fa_secret -> Nullable<Text>, totp_2fa_secret -> Nullable<Text>,
totp_2fa_url -> Nullable<Text>, totp_2fa_url -> Nullable<Text>,
open_links_in_new_tab -> Bool, open_links_in_new_tab -> Bool,
infinite_scroll_enabled -> Bool,
blur_nsfw -> Bool, blur_nsfw -> Bool,
auto_expand -> Bool, auto_expand -> Bool,
infinite_scroll_enabled -> Bool,
admin -> Bool,
} }
} }
@ -431,7 +432,7 @@ diesel::table! {
mod_person_id -> Int4, mod_person_id -> Int4,
other_person_id -> Int4, other_person_id -> Int4,
removed -> Bool, removed -> Bool,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -442,7 +443,7 @@ diesel::table! {
other_person_id -> Int4, other_person_id -> Int4,
community_id -> Int4, community_id -> Int4,
removed -> Bool, removed -> Bool,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -453,8 +454,8 @@ diesel::table! {
other_person_id -> Int4, other_person_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
banned -> Bool, banned -> Bool,
expires -> Nullable<Timestamp>, expires -> Nullable<Timestamptz>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -466,8 +467,8 @@ diesel::table! {
community_id -> Int4, community_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
banned -> Bool, banned -> Bool,
expires -> Nullable<Timestamp>, expires -> Nullable<Timestamptz>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -477,7 +478,7 @@ diesel::table! {
mod_person_id -> Int4, mod_person_id -> Int4,
post_id -> Int4, post_id -> Int4,
featured -> Bool, featured -> Bool,
when_ -> Timestamp, when_ -> Timestamptz,
is_featured_community -> Bool, is_featured_community -> Bool,
} }
} }
@ -487,7 +488,7 @@ diesel::table! {
id -> Int4, id -> Int4,
community_id -> Int4, community_id -> Int4,
mod_person_id -> Int4, mod_person_id -> Int4,
when_ -> Timestamp, when_ -> Timestamptz,
reason -> Nullable<Text>, reason -> Nullable<Text>,
hidden -> Bool, hidden -> Bool,
} }
@ -499,7 +500,7 @@ diesel::table! {
mod_person_id -> Int4, mod_person_id -> Int4,
post_id -> Int4, post_id -> Int4,
locked -> Bool, locked -> Bool,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -510,7 +511,7 @@ diesel::table! {
comment_id -> Int4, comment_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
removed -> Bool, removed -> Bool,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -521,8 +522,8 @@ diesel::table! {
community_id -> Int4, community_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
removed -> Bool, removed -> Bool,
expires -> Nullable<Timestamp>, expires -> Nullable<Timestamptz>,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -533,7 +534,7 @@ diesel::table! {
post_id -> Int4, post_id -> Int4,
reason -> Nullable<Text>, reason -> Nullable<Text>,
removed -> Bool, removed -> Bool,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -543,7 +544,7 @@ diesel::table! {
mod_person_id -> Int4, mod_person_id -> Int4,
other_person_id -> Int4, other_person_id -> Int4,
community_id -> Int4, community_id -> Int4,
when_ -> Timestamp, when_ -> Timestamptz,
} }
} }
@ -551,7 +552,7 @@ diesel::table! {
password_reset_request (id) { password_reset_request (id) {
id -> Int4, id -> Int4,
token -> Text, token -> Text,
published -> Timestamp, published -> Timestamptz,
local_user_id -> Int4, local_user_id -> Int4,
} }
} }
@ -565,15 +566,15 @@ diesel::table! {
display_name -> Nullable<Varchar>, display_name -> Nullable<Varchar>,
avatar -> Nullable<Text>, avatar -> Nullable<Text>,
banned -> Bool, banned -> Bool,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
#[max_length = 255] #[max_length = 255]
actor_id -> Varchar, actor_id -> Varchar,
bio -> Nullable<Text>, bio -> Nullable<Text>,
local -> Bool, local -> Bool,
private_key -> Nullable<Text>, private_key -> Nullable<Text>,
public_key -> Text, public_key -> Text,
last_refreshed_at -> Timestamp, last_refreshed_at -> Timestamptz,
banner -> Nullable<Text>, banner -> Nullable<Text>,
deleted -> Bool, deleted -> Bool,
#[max_length = 255] #[max_length = 255]
@ -581,9 +582,8 @@ diesel::table! {
#[max_length = 255] #[max_length = 255]
shared_inbox_url -> Nullable<Varchar>, shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>, matrix_user_id -> Nullable<Text>,
admin -> Bool,
bot_account -> Bool, bot_account -> Bool,
ban_expires -> Nullable<Timestamp>, ban_expires -> Nullable<Timestamptz>,
instance_id -> Int4, instance_id -> Int4,
} }
} }
@ -603,7 +603,7 @@ diesel::table! {
person_ban (id) { person_ban (id) {
id -> Int4, id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -612,7 +612,7 @@ diesel::table! {
id -> Int4, id -> Int4,
person_id -> Int4, person_id -> Int4,
target_id -> Int4, target_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -621,7 +621,7 @@ diesel::table! {
id -> Int4, id -> Int4,
person_id -> Int4, person_id -> Int4,
follower_id -> Int4, follower_id -> Int4,
published -> Timestamp, published -> Timestamptz,
pending -> Bool, pending -> Bool,
} }
} }
@ -632,7 +632,7 @@ diesel::table! {
recipient_id -> Int4, recipient_id -> Int4,
comment_id -> Int4, comment_id -> Int4,
read -> Bool, read -> Bool,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -642,7 +642,7 @@ diesel::table! {
person_id -> Int4, person_id -> Int4,
post_id -> Int4, post_id -> Int4,
read_comments -> Int8, read_comments -> Int8,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -658,8 +658,8 @@ diesel::table! {
community_id -> Int4, community_id -> Int4,
removed -> Bool, removed -> Bool,
locked -> Bool, locked -> Bool,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
deleted -> Bool, deleted -> Bool,
nsfw -> Bool, nsfw -> Bool,
embed_title -> Nullable<Text>, embed_title -> Nullable<Text>,
@ -683,9 +683,9 @@ diesel::table! {
score -> Int8, score -> Int8,
upvotes -> Int8, upvotes -> Int8,
downvotes -> Int8, downvotes -> Int8,
published -> Timestamp, published -> Timestamptz,
newest_comment_time_necro -> Timestamp, newest_comment_time_necro -> Timestamptz,
newest_comment_time -> Timestamp, newest_comment_time -> Timestamptz,
featured_community -> Bool, featured_community -> Bool,
featured_local -> Bool, featured_local -> Bool,
hot_rank -> Int4, hot_rank -> Int4,
@ -702,7 +702,7 @@ diesel::table! {
post_id -> Int4, post_id -> Int4,
person_id -> Int4, person_id -> Int4,
score -> Int2, score -> Int2,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -711,7 +711,7 @@ diesel::table! {
id -> Int4, id -> Int4,
post_id -> Int4, post_id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -727,8 +727,8 @@ diesel::table! {
reason -> Text, reason -> Text,
resolved -> Bool, resolved -> Bool,
resolver_id -> Nullable<Int4>, resolver_id -> Nullable<Int4>,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -737,7 +737,7 @@ diesel::table! {
id -> Int4, id -> Int4,
post_id -> Int4, post_id -> Int4,
person_id -> Int4, person_id -> Int4,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -749,8 +749,8 @@ diesel::table! {
content -> Text, content -> Text,
deleted -> Bool, deleted -> Bool,
read -> Bool, read -> Bool,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
#[max_length = 255] #[max_length = 255]
ap_id -> Varchar, ap_id -> Varchar,
local -> Bool, local -> Bool,
@ -766,8 +766,8 @@ diesel::table! {
reason -> Text, reason -> Text,
resolved -> Bool, resolved -> Bool,
resolver_id -> Nullable<Int4>, resolver_id -> Nullable<Int4>,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }
@ -775,7 +775,7 @@ diesel::table! {
received_activity (id) { received_activity (id) {
id -> Int8, id -> Int8,
ap_id -> Text, ap_id -> Text,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -786,7 +786,7 @@ diesel::table! {
answer -> Text, answer -> Text,
admin_id -> Nullable<Int4>, admin_id -> Nullable<Int4>,
deny_reason -> Nullable<Text>, deny_reason -> Nullable<Text>,
published -> Timestamp, published -> Timestamptz,
} }
} }
@ -806,7 +806,7 @@ diesel::table! {
ap_id -> Text, ap_id -> Text,
data -> Json, data -> Json,
sensitive -> Bool, sensitive -> Bool,
published -> Timestamp, published -> Timestamptz,
send_inboxes -> Array<Nullable<Text>>, send_inboxes -> Array<Nullable<Text>>,
send_community_followers_of -> Nullable<Int4>, send_community_followers_of -> Nullable<Int4>,
send_all_instances -> Bool, send_all_instances -> Bool,
@ -821,15 +821,15 @@ diesel::table! {
#[max_length = 20] #[max_length = 20]
name -> Varchar, name -> Varchar,
sidebar -> Nullable<Text>, sidebar -> Nullable<Text>,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
icon -> Nullable<Text>, icon -> Nullable<Text>,
banner -> Nullable<Text>, banner -> Nullable<Text>,
#[max_length = 150] #[max_length = 150]
description -> Nullable<Varchar>, description -> Nullable<Varchar>,
#[max_length = 255] #[max_length = 255]
actor_id -> Varchar, actor_id -> Varchar,
last_refreshed_at -> Timestamp, last_refreshed_at -> Timestamptz,
#[max_length = 255] #[max_length = 255]
inbox_url -> Varchar, inbox_url -> Varchar,
private_key -> Nullable<Text>, private_key -> Nullable<Text>,
@ -866,8 +866,8 @@ diesel::table! {
id -> Int4, id -> Int4,
local_site_id -> Int4, local_site_id -> Int4,
content -> Text, content -> Text,
published -> Timestamp, published -> Timestamptz,
updated -> Nullable<Timestamp>, updated -> Nullable<Timestamptz>,
} }
} }

View File

@ -2,6 +2,7 @@ use crate::{
newtypes::{CommunityId, DbUrl}, newtypes::{CommunityId, DbUrl},
schema::sent_activity, schema::sent_activity,
}; };
use chrono::{DateTime, Utc};
use diesel::{ use diesel::{
deserialize::FromSql, deserialize::FromSql,
pg::{Pg, PgValue}, pg::{Pg, PgValue},
@ -74,7 +75,7 @@ pub struct SentActivity {
pub ap_id: DbUrl, pub ap_id: DbUrl,
pub data: Value, pub data: Value,
pub sensitive: bool, pub sensitive: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub send_inboxes: Vec<Option<DbUrl>>, pub send_inboxes: Vec<Option<DbUrl>>,
pub send_community_followers_of: Option<CommunityId>, pub send_community_followers_of: Option<CommunityId>,
pub send_all_instances: bool, pub send_all_instances: bool,
@ -108,7 +109,7 @@ pub enum ActorType {
pub struct ReceivedActivity { pub struct ReceivedActivity {
pub id: i64, pub id: i64,
pub ap_id: DbUrl, pub ap_id: DbUrl,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
// https://vasilakisfil.social/blog/2020/05/09/rust-diesel-jsonb/ // https://vasilakisfil.social/blog/2020/05/09/rust-diesel-jsonb/

View File

@ -1,5 +1,6 @@
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::captcha_answer; use crate::schema::captcha_answer;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use uuid::Uuid; use uuid::Uuid;
@ -12,7 +13,7 @@ pub struct CaptchaAnswer {
pub id: i32, pub id: i32,
pub uuid: Uuid, pub uuid: Uuid,
pub answer: String, pub answer: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[skip_serializing_none] #[skip_serializing_none]

View File

@ -3,6 +3,7 @@ use crate::newtypes::LtreeDef;
use crate::newtypes::{CommentId, DbUrl, LanguageId, PersonId, PostId}; use crate::newtypes::{CommentId, DbUrl, LanguageId, PersonId, PostId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::{comment, comment_like, comment_saved}; use crate::schema::{comment, comment_like, comment_saved};
use chrono::{DateTime, Utc};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use diesel_ltree::Ltree; use diesel_ltree::Ltree;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -25,8 +26,8 @@ pub struct Comment {
pub content: String, pub content: String,
/// Whether the comment has been removed. /// Whether the comment has been removed.
pub removed: bool, pub removed: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
/// Whether the comment has been deleted by its creator. /// Whether the comment has been deleted by its creator.
pub deleted: bool, pub deleted: bool,
/// The federated activity id / ap_id. /// The federated activity id / ap_id.
@ -57,8 +58,8 @@ pub struct CommentInsertForm {
#[builder(!default)] #[builder(!default)]
pub content: String, pub content: String,
pub removed: Option<bool>, pub removed: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub ap_id: Option<DbUrl>, pub ap_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
@ -73,7 +74,7 @@ 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 naive_now here, because the create function does a lot of comment updates
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub ap_id: Option<DbUrl>, pub ap_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
@ -91,7 +92,7 @@ pub struct CommentLike {
pub comment_id: CommentId, pub comment_id: CommentId,
pub post_id: PostId, // TODO this is redundant pub post_id: PostId, // TODO this is redundant
pub score: i16, pub score: i16,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[derive(Clone)] #[derive(Clone)]
@ -112,7 +113,7 @@ pub struct CommentSaved {
pub id: i32, pub id: i32,
pub comment_id: CommentId, pub comment_id: CommentId,
pub person_id: PersonId, pub person_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{CommentId, CommentReplyId, PersonId}; use crate::newtypes::{CommentId, CommentReplyId, PersonId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::comment_reply; use crate::schema::comment_reply;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use ts_rs::TS; use ts_rs::TS;
@ -16,7 +17,7 @@ pub struct CommentReply {
pub recipient_id: PersonId, pub recipient_id: PersonId,
pub comment_id: CommentId, pub comment_id: CommentId,
pub read: bool, pub read: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{CommentId, CommentReportId, PersonId}; use crate::newtypes::{CommentId, CommentReportId, PersonId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::comment_report; use crate::schema::comment_report;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -21,8 +22,8 @@ pub struct CommentReport {
pub reason: String, pub reason: String,
pub resolved: bool, pub resolved: bool,
pub resolver_id: Option<PersonId>, pub resolver_id: Option<PersonId>,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone)] #[derive(Clone)]

View File

@ -4,6 +4,7 @@ use crate::{
newtypes::{CommunityId, DbUrl, InstanceId, PersonId}, newtypes::{CommunityId, DbUrl, InstanceId, PersonId},
source::placeholder_apub_url, source::placeholder_apub_url,
}; };
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -25,8 +26,8 @@ pub struct Community {
pub description: Option<String>, pub description: Option<String>,
/// Whether the community is removed by a mod. /// Whether the community is removed by a mod.
pub removed: bool, pub removed: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
/// Whether the community has been deleted by its creator. /// Whether the community has been deleted by its creator.
pub deleted: bool, pub deleted: bool,
/// Whether its an NSFW community. /// Whether its an NSFW community.
@ -40,7 +41,7 @@ pub struct Community {
#[serde(skip)] #[serde(skip)]
pub public_key: String, pub public_key: String,
#[serde(skip)] #[serde(skip)]
pub last_refreshed_at: chrono::NaiveDateTime, pub last_refreshed_at: DateTime<Utc>,
/// A URL for an icon. /// A URL for an icon.
pub icon: Option<DbUrl>, pub icon: Option<DbUrl>,
/// A URL for a banner. /// A URL for a banner.
@ -75,15 +76,15 @@ pub struct CommunityInsertForm {
pub title: String, pub title: String,
pub description: Option<String>, pub description: Option<String>,
pub removed: Option<bool>, pub removed: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub nsfw: Option<bool>, pub nsfw: Option<bool>,
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
pub private_key: Option<String>, pub private_key: Option<String>,
pub public_key: String, pub public_key: String,
pub last_refreshed_at: Option<chrono::NaiveDateTime>, pub last_refreshed_at: Option<DateTime<Utc>>,
pub icon: Option<DbUrl>, pub icon: Option<DbUrl>,
pub banner: Option<DbUrl>, pub banner: Option<DbUrl>,
pub followers_url: Option<DbUrl>, pub followers_url: Option<DbUrl>,
@ -104,15 +105,15 @@ pub struct CommunityUpdateForm {
pub title: Option<String>, pub title: Option<String>,
pub description: Option<Option<String>>, pub description: Option<Option<String>>,
pub removed: Option<bool>, pub removed: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub nsfw: Option<bool>, pub nsfw: Option<bool>,
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
pub public_key: Option<String>, pub public_key: Option<String>,
pub private_key: Option<Option<String>>, pub private_key: Option<Option<String>>,
pub last_refreshed_at: Option<chrono::NaiveDateTime>, pub last_refreshed_at: Option<DateTime<Utc>>,
pub icon: Option<Option<DbUrl>>, pub icon: Option<Option<DbUrl>>,
pub banner: Option<Option<DbUrl>>, pub banner: Option<Option<DbUrl>>,
pub followers_url: Option<DbUrl>, pub followers_url: Option<DbUrl>,
@ -135,7 +136,7 @@ pub struct CommunityModerator {
pub id: i32, pub id: i32,
pub community_id: CommunityId, pub community_id: CommunityId,
pub person_id: PersonId, pub person_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[derive(Clone)] #[derive(Clone)]
@ -157,8 +158,8 @@ pub struct CommunityPersonBan {
pub id: i32, pub id: i32,
pub community_id: CommunityId, pub community_id: CommunityId,
pub person_id: PersonId, pub person_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
} }
#[derive(Clone)] #[derive(Clone)]
@ -167,7 +168,7 @@ pub struct CommunityPersonBan {
pub struct CommunityPersonBanForm { pub struct CommunityPersonBanForm {
pub community_id: CommunityId, pub community_id: CommunityId,
pub person_id: PersonId, pub person_id: PersonId,
pub expires: Option<Option<chrono::NaiveDateTime>>, pub expires: Option<Option<DateTime<Utc>>>,
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
@ -181,7 +182,7 @@ pub struct CommunityFollower {
pub id: i32, pub id: i32,
pub community_id: CommunityId, pub community_id: CommunityId,
pub person_id: PersonId, pub person_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub pending: bool, pub pending: bool,
} }

View File

@ -1,6 +1,7 @@
use crate::newtypes::{CommunityBlockId, CommunityId, PersonId}; use crate::newtypes::{CommunityBlockId, CommunityId, PersonId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::community_block; use crate::schema::community_block;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
@ -14,7 +15,7 @@ pub struct CommunityBlock {
pub id: CommunityBlockId, pub id: CommunityBlockId,
pub person_id: PersonId, pub person_id: PersonId,
pub community_id: CommunityId, pub community_id: CommunityId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{CustomEmojiId, DbUrl, LocalSiteId}; use crate::newtypes::{CustomEmojiId, DbUrl, LocalSiteId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::custom_emoji; use crate::schema::custom_emoji;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -24,8 +25,8 @@ pub struct CustomEmoji {
pub image_url: DbUrl, pub image_url: DbUrl,
pub alt_text: String, pub alt_text: String,
pub category: String, pub category: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Debug, Clone, TypedBuilder)] #[derive(Debug, Clone, TypedBuilder)]

View File

@ -1,6 +1,7 @@
use crate::newtypes::LocalUserId; use crate::newtypes::LocalUserId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::email_verification; use crate::schema::email_verification;
use chrono::{DateTime, Utc};
#[derive(Clone)] #[derive(Clone)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
@ -10,7 +11,7 @@ pub struct EmailVerification {
pub local_user_id: LocalUserId, pub local_user_id: LocalUserId,
pub email: String, pub email: String,
pub verification_code: String, pub verification_code: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::InstanceId; use crate::newtypes::InstanceId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::federation_allowlist; use crate::schema::federation_allowlist;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::Debug; use std::fmt::Debug;
@ -14,8 +15,8 @@ use std::fmt::Debug;
pub struct FederationAllowList { pub struct FederationAllowList {
pub id: i32, pub id: i32,
pub instance_id: InstanceId, pub instance_id: InstanceId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -23,5 +24,5 @@ pub struct FederationAllowList {
#[cfg_attr(feature = "full", diesel(table_name = federation_allowlist))] #[cfg_attr(feature = "full", diesel(table_name = federation_allowlist))]
pub struct FederationAllowListForm { pub struct FederationAllowListForm {
pub instance_id: InstanceId, pub instance_id: InstanceId,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }

View File

@ -1,6 +1,7 @@
use crate::newtypes::InstanceId; use crate::newtypes::InstanceId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::federation_blocklist; use crate::schema::federation_blocklist;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::Debug; use std::fmt::Debug;
@ -14,8 +15,8 @@ use std::fmt::Debug;
pub struct FederationBlockList { pub struct FederationBlockList {
pub id: i32, pub id: i32,
pub instance_id: InstanceId, pub instance_id: InstanceId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -23,5 +24,5 @@ pub struct FederationBlockList {
#[cfg_attr(feature = "full", diesel(table_name = federation_blocklist))] #[cfg_attr(feature = "full", diesel(table_name = federation_blocklist))]
pub struct FederationBlockListForm { pub struct FederationBlockListForm {
pub instance_id: InstanceId, pub instance_id: InstanceId,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }

View File

@ -1,6 +1,7 @@
use crate::newtypes::InstanceId; use crate::newtypes::InstanceId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::instance; use crate::schema::instance;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
use std::fmt::Debug; use std::fmt::Debug;
@ -17,8 +18,8 @@ use typed_builder::TypedBuilder;
pub struct Instance { pub struct Instance {
pub id: InstanceId, pub id: InstanceId,
pub domain: String, pub domain: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub software: Option<String>, pub software: Option<String>,
pub version: Option<String>, pub version: Option<String>,
} }
@ -32,5 +33,5 @@ pub struct InstanceForm {
pub domain: String, pub domain: String,
pub software: Option<String>, pub software: Option<String>,
pub version: Option<String>, pub version: Option<String>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }

View File

@ -5,6 +5,7 @@ use crate::{
ListingType, ListingType,
RegistrationMode, RegistrationMode,
}; };
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -54,8 +55,8 @@ pub struct LocalSite {
pub captcha_enabled: bool, pub captcha_enabled: bool,
/// The captcha difficulty. /// The captcha difficulty.
pub captcha_difficulty: String, pub captcha_difficulty: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub registration_mode: RegistrationMode, pub registration_mode: RegistrationMode,
/// Whether to email admins on new reports. /// Whether to email admins on new reports.
pub reports_email_admins: bool, pub reports_email_admins: bool,
@ -112,5 +113,5 @@ pub struct LocalSiteUpdateForm {
pub captcha_difficulty: Option<String>, pub captcha_difficulty: Option<String>,
pub registration_mode: Option<RegistrationMode>, pub registration_mode: Option<RegistrationMode>,
pub reports_email_admins: Option<bool>, pub reports_email_admins: Option<bool>,
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
} }

View File

@ -1,6 +1,7 @@
use crate::newtypes::LocalSiteId; use crate::newtypes::LocalSiteId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::local_site_rate_limit; use crate::schema::local_site_rate_limit;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -32,8 +33,8 @@ pub struct LocalSiteRateLimit {
pub comment_per_second: i32, pub comment_per_second: i32,
pub search: i32, pub search: i32,
pub search_per_second: i32, pub search_per_second: i32,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone, TypedBuilder)] #[derive(Clone, TypedBuilder)]
@ -73,5 +74,5 @@ pub struct LocalSiteRateLimitUpdateForm {
pub comment_per_second: Option<i32>, pub comment_per_second: Option<i32>,
pub search: Option<i32>, pub search: Option<i32>,
pub search_per_second: Option<i32>, pub search_per_second: Option<i32>,
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
} }

View File

@ -5,6 +5,7 @@ use crate::{
ListingType, ListingType,
SortType, SortType,
}; };
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -34,7 +35,7 @@ pub struct LocalUser {
pub show_avatars: bool, pub show_avatars: bool,
pub send_notifications_to_email: bool, pub send_notifications_to_email: bool,
/// A validation ID used in logging out sessions. /// A validation ID used in logging out sessions.
pub validator_time: chrono::NaiveDateTime, pub validator_time: DateTime<Utc>,
/// Whether to show comment / post scores. /// Whether to show comment / post scores.
pub show_scores: bool, pub show_scores: bool,
/// Whether to show bot accounts. /// Whether to show bot accounts.
@ -57,6 +58,8 @@ pub struct LocalUser {
pub auto_expand: bool, pub auto_expand: bool,
/// Whether infinite scroll is enabled. /// Whether infinite scroll is enabled.
pub infinite_scroll_enabled: bool, pub infinite_scroll_enabled: bool,
/// Whether the person is an admin.
pub admin: bool,
} }
#[derive(Clone, TypedBuilder)] #[derive(Clone, TypedBuilder)]
@ -88,6 +91,7 @@ pub struct LocalUserInsertForm {
pub blur_nsfw: Option<bool>, pub blur_nsfw: Option<bool>,
pub auto_expand: Option<bool>, pub auto_expand: Option<bool>,
pub infinite_scroll_enabled: Option<bool>, pub infinite_scroll_enabled: Option<bool>,
pub admin: Option<bool>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -115,4 +119,5 @@ pub struct LocalUserUpdateForm {
pub blur_nsfw: Option<bool>, pub blur_nsfw: Option<bool>,
pub auto_expand: Option<bool>, pub auto_expand: Option<bool>,
pub infinite_scroll_enabled: Option<bool>, pub infinite_scroll_enabled: Option<bool>,
pub admin: Option<bool>,
} }

View File

@ -17,6 +17,7 @@ use crate::schema::{
mod_remove_post, mod_remove_post,
mod_transfer_community, mod_transfer_community,
}; };
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -34,7 +35,7 @@ pub struct ModRemovePost {
pub post_id: PostId, pub post_id: PostId,
pub reason: Option<String>, pub reason: Option<String>,
pub removed: bool, pub removed: bool,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -56,7 +57,7 @@ pub struct ModLockPost {
pub mod_person_id: PersonId, pub mod_person_id: PersonId,
pub post_id: PostId, pub post_id: PostId,
pub locked: bool, pub locked: bool,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -77,7 +78,7 @@ pub struct ModFeaturePost {
pub mod_person_id: PersonId, pub mod_person_id: PersonId,
pub post_id: PostId, pub post_id: PostId,
pub featured: bool, pub featured: bool,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
pub is_featured_community: bool, pub is_featured_community: bool,
} }
@ -102,7 +103,7 @@ pub struct ModRemoveComment {
pub comment_id: CommentId, pub comment_id: CommentId,
pub reason: Option<String>, pub reason: Option<String>,
pub removed: bool, pub removed: bool,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -126,8 +127,8 @@ pub struct ModRemoveCommunity {
pub community_id: CommunityId, pub community_id: CommunityId,
pub reason: Option<String>, pub reason: Option<String>,
pub removed: bool, pub removed: bool,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -137,7 +138,7 @@ pub struct ModRemoveCommunityForm {
pub community_id: CommunityId, pub community_id: CommunityId,
pub reason: Option<String>, pub reason: Option<String>,
pub removed: Option<bool>, pub removed: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -153,8 +154,8 @@ pub struct ModBanFromCommunity {
pub community_id: CommunityId, pub community_id: CommunityId,
pub reason: Option<String>, pub reason: Option<String>,
pub banned: bool, pub banned: bool,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -165,7 +166,7 @@ pub struct ModBanFromCommunityForm {
pub community_id: CommunityId, pub community_id: CommunityId,
pub reason: Option<String>, pub reason: Option<String>,
pub banned: Option<bool>, pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
} }
#[skip_serializing_none] #[skip_serializing_none]
@ -180,8 +181,8 @@ pub struct ModBan {
pub other_person_id: PersonId, pub other_person_id: PersonId,
pub reason: Option<String>, pub reason: Option<String>,
pub banned: bool, pub banned: bool,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -203,7 +204,7 @@ pub struct ModHideCommunity {
pub id: i32, pub id: i32,
pub community_id: CommunityId, pub community_id: CommunityId,
pub mod_person_id: PersonId, pub mod_person_id: PersonId,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
pub reason: Option<String>, pub reason: Option<String>,
pub hidden: bool, pub hidden: bool,
} }
@ -215,7 +216,7 @@ pub struct ModBanForm {
pub other_person_id: PersonId, pub other_person_id: PersonId,
pub reason: Option<String>, pub reason: Option<String>,
pub banned: Option<bool>, pub banned: Option<bool>,
pub expires: Option<chrono::NaiveDateTime>, pub expires: Option<DateTime<Utc>>,
} }
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
@ -229,7 +230,7 @@ pub struct ModAddCommunity {
pub other_person_id: PersonId, pub other_person_id: PersonId,
pub community_id: CommunityId, pub community_id: CommunityId,
pub removed: bool, pub removed: bool,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -251,7 +252,7 @@ pub struct ModTransferCommunity {
pub mod_person_id: PersonId, pub mod_person_id: PersonId,
pub other_person_id: PersonId, pub other_person_id: PersonId,
pub community_id: CommunityId, pub community_id: CommunityId,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -272,7 +273,7 @@ pub struct ModAdd {
pub mod_person_id: PersonId, pub mod_person_id: PersonId,
pub other_person_id: PersonId, pub other_person_id: PersonId,
pub removed: bool, pub removed: bool,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -293,7 +294,7 @@ pub struct AdminPurgePerson {
pub id: i32, pub id: i32,
pub admin_person_id: PersonId, pub admin_person_id: PersonId,
pub reason: Option<String>, pub reason: Option<String>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -313,7 +314,7 @@ pub struct AdminPurgeCommunity {
pub id: i32, pub id: i32,
pub admin_person_id: PersonId, pub admin_person_id: PersonId,
pub reason: Option<String>, pub reason: Option<String>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -334,7 +335,7 @@ pub struct AdminPurgePost {
pub admin_person_id: PersonId, pub admin_person_id: PersonId,
pub community_id: CommunityId, pub community_id: CommunityId,
pub reason: Option<String>, pub reason: Option<String>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -356,7 +357,7 @@ pub struct AdminPurgeComment {
pub admin_person_id: PersonId, pub admin_person_id: PersonId,
pub post_id: PostId, pub post_id: PostId,
pub reason: Option<String>, pub reason: Option<String>,
pub when_: chrono::NaiveDateTime, pub when_: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::LocalUserId; use crate::newtypes::LocalUserId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::password_reset_request; use crate::schema::password_reset_request;
use chrono::{DateTime, Utc};
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
#[cfg_attr(feature = "full", derive(Queryable, Identifiable))] #[cfg_attr(feature = "full", derive(Queryable, Identifiable))]
@ -8,7 +9,7 @@ use crate::schema::password_reset_request;
pub struct PasswordResetRequest { pub struct PasswordResetRequest {
pub id: i32, pub id: i32,
pub token: String, pub token: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub local_user_id: LocalUserId, pub local_user_id: LocalUserId,
} }

View File

@ -4,6 +4,7 @@ use crate::{
newtypes::{DbUrl, InstanceId, PersonId}, newtypes::{DbUrl, InstanceId, PersonId},
source::placeholder_apub_url, source::placeholder_apub_url,
}; };
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -25,8 +26,8 @@ pub struct Person {
pub avatar: Option<DbUrl>, pub avatar: Option<DbUrl>,
/// Whether the person is banned. /// Whether the person is banned.
pub banned: bool, pub banned: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
/// The federated actor_id. /// The federated actor_id.
pub actor_id: DbUrl, pub actor_id: DbUrl,
/// An optional bio, in markdown. /// An optional bio, in markdown.
@ -38,7 +39,7 @@ pub struct Person {
#[serde(skip)] #[serde(skip)]
pub public_key: String, pub public_key: String,
#[serde(skip)] #[serde(skip)]
pub last_refreshed_at: chrono::NaiveDateTime, pub last_refreshed_at: DateTime<Utc>,
/// A URL for a banner. /// A URL for a banner.
pub banner: Option<DbUrl>, pub banner: Option<DbUrl>,
/// Whether the person is deleted. /// Whether the person is deleted.
@ -49,12 +50,10 @@ pub struct Person {
pub shared_inbox_url: Option<DbUrl>, pub shared_inbox_url: Option<DbUrl>,
/// A matrix id, usually given an @person:matrix.org /// A matrix id, usually given an @person:matrix.org
pub matrix_user_id: Option<String>, pub matrix_user_id: Option<String>,
/// Whether the person is an admin.
pub admin: bool,
/// Whether the person is a bot account. /// Whether the person is a bot account.
pub bot_account: bool, pub bot_account: bool,
/// When their ban, if it exists, expires, if at all. /// When their ban, if it exists, expires, if at all.
pub ban_expires: Option<chrono::NaiveDateTime>, pub ban_expires: Option<DateTime<Utc>>,
pub instance_id: InstanceId, pub instance_id: InstanceId,
} }
@ -72,21 +71,20 @@ pub struct PersonInsertForm {
pub display_name: Option<String>, pub display_name: Option<String>,
pub avatar: Option<DbUrl>, pub avatar: Option<DbUrl>,
pub banned: Option<bool>, pub banned: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
pub bio: Option<String>, pub bio: Option<String>,
pub local: Option<bool>, pub local: Option<bool>,
pub private_key: Option<String>, pub private_key: Option<String>,
pub last_refreshed_at: Option<chrono::NaiveDateTime>, pub last_refreshed_at: Option<DateTime<Utc>>,
pub banner: Option<DbUrl>, pub banner: Option<DbUrl>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub inbox_url: Option<DbUrl>, pub inbox_url: Option<DbUrl>,
pub shared_inbox_url: Option<DbUrl>, pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>, pub matrix_user_id: Option<String>,
pub admin: Option<bool>,
pub bot_account: Option<bool>, pub bot_account: Option<bool>,
pub ban_expires: Option<chrono::NaiveDateTime>, pub ban_expires: Option<DateTime<Utc>>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -96,21 +94,20 @@ pub struct PersonUpdateForm {
pub display_name: Option<Option<String>>, pub display_name: Option<Option<String>>,
pub avatar: Option<Option<DbUrl>>, pub avatar: Option<Option<DbUrl>>,
pub banned: Option<bool>, pub banned: Option<bool>,
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
pub bio: Option<Option<String>>, pub bio: Option<Option<String>>,
pub local: Option<bool>, pub local: Option<bool>,
pub public_key: Option<String>, pub public_key: Option<String>,
pub private_key: Option<Option<String>>, pub private_key: Option<Option<String>>,
pub last_refreshed_at: Option<chrono::NaiveDateTime>, pub last_refreshed_at: Option<DateTime<Utc>>,
pub banner: Option<Option<DbUrl>>, pub banner: Option<Option<DbUrl>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub inbox_url: Option<DbUrl>, pub inbox_url: Option<DbUrl>,
pub shared_inbox_url: Option<Option<DbUrl>>, pub shared_inbox_url: Option<Option<DbUrl>>,
pub matrix_user_id: Option<Option<String>>, pub matrix_user_id: Option<Option<String>>,
pub admin: Option<bool>,
pub bot_account: Option<bool>, pub bot_account: Option<bool>,
pub ban_expires: Option<Option<chrono::NaiveDateTime>>, pub ban_expires: Option<Option<DateTime<Utc>>>,
} }
#[derive(PartialEq, Eq, Debug)] #[derive(PartialEq, Eq, Debug)]
@ -121,7 +118,7 @@ pub struct PersonFollower {
pub id: i32, pub id: i32,
pub person_id: PersonId, pub person_id: PersonId,
pub follower_id: PersonId, pub follower_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub pending: bool, pub pending: bool,
} }

View File

@ -1,6 +1,7 @@
use crate::newtypes::{PersonBlockId, PersonId}; use crate::newtypes::{PersonBlockId, PersonId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::person_block; use crate::schema::person_block;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
@ -11,7 +12,7 @@ pub struct PersonBlock {
pub id: PersonBlockId, pub id: PersonBlockId,
pub person_id: PersonId, pub person_id: PersonId,
pub target_id: PersonId, pub target_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{CommentId, PersonId, PersonMentionId}; use crate::newtypes::{CommentId, PersonId, PersonMentionId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::person_mention; use crate::schema::person_mention;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use ts_rs::TS; use ts_rs::TS;
@ -16,7 +17,7 @@ pub struct PersonMention {
pub recipient_id: PersonId, pub recipient_id: PersonId,
pub comment_id: CommentId, pub comment_id: CommentId,
pub read: bool, pub read: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId}; use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::{post, post_like, post_read, post_saved}; use crate::schema::{post, post_like, post_read, post_saved};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -27,8 +28,8 @@ pub struct Post {
pub removed: bool, pub removed: bool,
/// Whether the post is locked. /// Whether the post is locked.
pub locked: bool, pub locked: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
/// Whether the post is deleted. /// Whether the post is deleted.
pub deleted: bool, pub deleted: bool,
/// Whether the post is NSFW. /// Whether the post is NSFW.
@ -71,8 +72,8 @@ pub struct PostInsertForm {
pub body: Option<String>, pub body: Option<String>,
pub removed: Option<bool>, pub removed: Option<bool>,
pub locked: Option<bool>, pub locked: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub embed_title: Option<String>, pub embed_title: Option<String>,
pub embed_description: Option<String>, pub embed_description: Option<String>,
@ -95,8 +96,8 @@ pub struct PostUpdateForm {
pub body: Option<Option<String>>, pub body: Option<Option<String>>,
pub removed: Option<bool>, pub removed: Option<bool>,
pub locked: Option<bool>, pub locked: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub embed_title: Option<Option<String>>, pub embed_title: Option<Option<String>>,
pub embed_description: Option<Option<String>>, pub embed_description: Option<Option<String>>,
@ -118,7 +119,7 @@ pub struct PostLike {
pub post_id: PostId, pub post_id: PostId,
pub person_id: PersonId, pub person_id: PersonId,
pub score: i16, pub score: i16,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[derive(Clone)] #[derive(Clone)]
@ -138,7 +139,7 @@ pub struct PostSaved {
pub id: i32, pub id: i32,
pub post_id: PostId, pub post_id: PostId,
pub person_id: PersonId, pub person_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
@ -156,7 +157,7 @@ pub struct PostRead {
pub id: i32, pub id: i32,
pub post_id: PostId, pub post_id: PostId,
pub person_id: PersonId, pub person_id: PersonId,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{DbUrl, PersonId, PostId, PostReportId}; use crate::newtypes::{DbUrl, PersonId, PostId, PostReportId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::post_report; use crate::schema::post_report;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -26,8 +27,8 @@ pub struct PostReport {
pub reason: String, pub reason: String,
pub resolved: bool, pub resolved: bool,
pub resolver_id: Option<PersonId>, pub resolver_id: Option<PersonId>,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{DbUrl, PersonId, PrivateMessageId}; use crate::newtypes::{DbUrl, PersonId, PrivateMessageId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::private_message; use crate::schema::private_message;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -24,8 +25,8 @@ pub struct PrivateMessage {
pub content: String, pub content: String,
pub deleted: bool, pub deleted: bool,
pub read: bool, pub read: bool,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub ap_id: DbUrl, pub ap_id: DbUrl,
pub local: bool, pub local: bool,
} }
@ -43,8 +44,8 @@ pub struct PrivateMessageInsertForm {
pub content: String, pub content: String,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub read: Option<bool>, pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub ap_id: Option<DbUrl>, pub ap_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
} }
@ -56,8 +57,8 @@ pub struct PrivateMessageUpdateForm {
pub content: Option<String>, pub content: Option<String>,
pub deleted: Option<bool>, pub deleted: Option<bool>,
pub read: Option<bool>, pub read: Option<bool>,
pub published: Option<chrono::NaiveDateTime>, pub published: Option<DateTime<Utc>>,
pub updated: Option<Option<chrono::NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
pub ap_id: Option<DbUrl>, pub ap_id: Option<DbUrl>,
pub local: Option<bool>, pub local: Option<bool>,
} }

View File

@ -1,6 +1,7 @@
use crate::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId}; use crate::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::private_message_report; use crate::schema::private_message_report;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -25,8 +26,8 @@ pub struct PrivateMessageReport {
pub reason: String, pub reason: String,
pub resolved: bool, pub resolved: bool,
pub resolver_id: Option<PersonId>, pub resolver_id: Option<PersonId>,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone)] #[derive(Clone)]

View File

@ -1,6 +1,7 @@
use crate::newtypes::{LocalUserId, PersonId}; use crate::newtypes::{LocalUserId, PersonId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::registration_application; use crate::schema::registration_application;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -18,7 +19,7 @@ pub struct RegistrationApplication {
pub answer: String, pub answer: String,
pub admin_id: Option<PersonId>, pub admin_id: Option<PersonId>,
pub deny_reason: Option<String>, pub deny_reason: Option<String>,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
} }
#[cfg_attr(feature = "full", derive(Insertable))] #[cfg_attr(feature = "full", derive(Insertable))]

View File

@ -1,7 +1,7 @@
use crate::newtypes::{DbUrl, InstanceId, SiteId}; use crate::newtypes::{DbUrl, InstanceId, SiteId};
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::site; use crate::schema::site;
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -19,8 +19,8 @@ pub struct Site {
pub name: String, pub name: String,
/// A sidebar for the site in markdown. /// A sidebar for the site in markdown.
pub sidebar: Option<String>, pub sidebar: Option<String>,
pub published: NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
/// An icon URL. /// An icon URL.
pub icon: Option<DbUrl>, pub icon: Option<DbUrl>,
/// A banner url. /// A banner url.
@ -30,7 +30,7 @@ pub struct Site {
/// The federated actor_id. /// The federated actor_id.
pub actor_id: DbUrl, pub actor_id: DbUrl,
/// The time the site was last refreshed. /// The time the site was last refreshed.
pub last_refreshed_at: NaiveDateTime, pub last_refreshed_at: DateTime<Utc>,
/// The site inbox /// The site inbox
pub inbox_url: DbUrl, pub inbox_url: DbUrl,
pub private_key: Option<String>, pub private_key: Option<String>,
@ -46,12 +46,12 @@ pub struct SiteInsertForm {
#[builder(!default)] #[builder(!default)]
pub name: String, pub name: String,
pub sidebar: Option<String>, pub sidebar: Option<String>,
pub updated: Option<NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
pub icon: Option<DbUrl>, pub icon: Option<DbUrl>,
pub banner: Option<DbUrl>, pub banner: Option<DbUrl>,
pub description: Option<String>, pub description: Option<String>,
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
pub last_refreshed_at: Option<NaiveDateTime>, pub last_refreshed_at: Option<DateTime<Utc>>,
pub inbox_url: Option<DbUrl>, pub inbox_url: Option<DbUrl>,
pub private_key: Option<String>, pub private_key: Option<String>,
pub public_key: Option<String>, pub public_key: Option<String>,
@ -65,13 +65,13 @@ pub struct SiteInsertForm {
pub struct SiteUpdateForm { pub struct SiteUpdateForm {
pub name: Option<String>, pub name: Option<String>,
pub sidebar: Option<Option<String>>, pub sidebar: Option<Option<String>>,
pub updated: Option<Option<NaiveDateTime>>, pub updated: Option<Option<DateTime<Utc>>>,
// when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column. // when you want to null out a column, you have to send Some(None)), since sending None means you just don't want to update that column.
pub icon: Option<Option<DbUrl>>, pub icon: Option<Option<DbUrl>>,
pub banner: Option<Option<DbUrl>>, pub banner: Option<Option<DbUrl>>,
pub description: Option<Option<String>>, pub description: Option<Option<String>>,
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
pub last_refreshed_at: Option<NaiveDateTime>, pub last_refreshed_at: Option<DateTime<Utc>>,
pub inbox_url: Option<DbUrl>, pub inbox_url: Option<DbUrl>,
pub private_key: Option<Option<String>>, pub private_key: Option<Option<String>>,
pub public_key: Option<String>, pub public_key: Option<String>,

View File

@ -1,6 +1,7 @@
use crate::newtypes::LocalSiteId; use crate::newtypes::LocalSiteId;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use crate::schema::tagline; use crate::schema::tagline;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
@ -20,8 +21,8 @@ pub struct Tagline {
pub id: i32, pub id: i32,
pub local_site_id: LocalSiteId, pub local_site_id: LocalSiteId,
pub content: String, pub content: String,
pub published: chrono::NaiveDateTime, pub published: DateTime<Utc>,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
@ -30,5 +31,5 @@ pub struct Tagline {
pub struct TaglineForm { pub struct TaglineForm {
pub local_site_id: LocalSiteId, pub local_site_id: LocalSiteId,
pub content: String, pub content: String,
pub updated: Option<chrono::NaiveDateTime>, pub updated: Option<DateTime<Utc>>,
} }

View File

@ -8,15 +8,17 @@ use crate::{
SortType, SortType,
}; };
use activitypub_federation::{fetch::object_id::ObjectId, traits::Object}; use activitypub_federation::{fetch::object_id::ObjectId, traits::Object};
use chrono::NaiveDateTime; use chrono::{DateTime, Utc};
use deadpool::Runtime; use deadpool::Runtime;
use diesel::{ use diesel::{
backend::Backend, backend::Backend,
deserialize::FromSql, deserialize::FromSql,
helper_types::AsExprOf,
pg::Pg, pg::Pg,
result::{ConnectionError, ConnectionResult, Error as DieselError, Error::QueryBuilderError}, result::{ConnectionError, ConnectionResult, Error as DieselError, Error::QueryBuilderError},
serialize::{Output, ToSql}, serialize::{Output, ToSql},
sql_types::Text, sql_types::{Text, Timestamptz},
IntoSql,
PgConnection, PgConnection,
}; };
use diesel_async::{ use diesel_async::{
@ -340,8 +342,8 @@ pub fn get_database_url(settings: Option<&Settings>) -> String {
} }
} }
pub fn naive_now() -> NaiveDateTime { pub fn naive_now() -> DateTime<Utc> {
chrono::prelude::Utc::now().naive_utc() chrono::prelude::Utc::now()
} }
pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType { pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType {
@ -380,10 +382,10 @@ static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
}); });
pub mod functions { pub mod functions {
use diesel::sql_types::{BigInt, Text, Timestamp}; use diesel::sql_types::{BigInt, Text, Timestamptz};
sql_function! { sql_function! {
fn hot_rank(score: BigInt, time: Timestamp) -> Integer; fn hot_rank(score: BigInt, time: Timestamptz) -> Integer;
} }
sql_function! { sql_function! {
@ -424,6 +426,11 @@ where
} }
} }
pub fn now() -> AsExprOf<diesel::dsl::now, diesel::sql_types::Timestamptz> {
// https://github.com/diesel-rs/diesel/issues/1514
diesel::dsl::now.into_sql::<Timestamptz>()
}
pub type ResultFuture<'a, T> = BoxFuture<'a, Result<T, DieselError>>; pub type ResultFuture<'a, T> = BoxFuture<'a, Result<T, DieselError>>;
pub trait ReadFn<'a, T: JoinView, Args>: pub trait ReadFn<'a, T: JoinView, Args>:

View File

@ -1,4 +1,4 @@
use crate::structs::CommentReportView; use crate::structs::{CommentReportView, LocalUserView};
use diesel::{ use diesel::{
dsl::now, dsl::now,
pg::Pg, pg::Pg,
@ -38,7 +38,7 @@ use lemmy_db_schema::{
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, CommentReportView, (CommentReportId, PersonId)>, impl ReadFn<'a, CommentReportView, (CommentReportId, PersonId)>,
impl ListFn<'a, CommentReportView, (CommentReportQuery, &'a Person)>, impl ListFn<'a, CommentReportView, (CommentReportQuery, &'a LocalUserView)>,
> { > {
let all_joins = |query: comment_report::BoxedQuery<'a, Pg>, my_person_id: PersonId| { let all_joins = |query: comment_report::BoxedQuery<'a, Pg>, my_person_id: PersonId| {
query query
@ -93,8 +93,9 @@ fn queries<'a>() -> Queries<
.await .await
}; };
let list = move |mut conn: DbConn<'a>, (options, my_person): (CommentReportQuery, &'a Person)| async move { let list = move |mut conn: DbConn<'a>,
let mut query = all_joins(comment_report::table.into_boxed(), my_person.id) (options, user): (CommentReportQuery, &'a LocalUserView)| async move {
let mut query = all_joins(comment_report::table.into_boxed(), user.person.id)
.left_join( .left_join(
community_person_ban::table.on( community_person_ban::table.on(
community::id community::id
@ -125,13 +126,13 @@ fn queries<'a>() -> Queries<
.offset(offset); .offset(offset);
// If its not an admin, get only the ones you mod // If its not an admin, get only the ones you mod
if !my_person.admin { if !user.local_user.admin {
query query
.inner_join( .inner_join(
community_moderator::table.on( community_moderator::table.on(
community_moderator::community_id community_moderator::community_id
.eq(post::community_id) .eq(post::community_id)
.and(community_moderator::person_id.eq(my_person.id)), .and(community_moderator::person_id.eq(user.person.id)),
), ),
) )
.load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn) .load::<<CommentReportView as JoinView>::JoinTuple>(&mut conn)
@ -213,9 +214,9 @@ impl CommentReportQuery {
pub async fn list( pub async fn list(
self, self,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
my_person: &Person, user: &LocalUserView,
) -> Result<Vec<CommentReportView>, Error> { ) -> Result<Vec<CommentReportView>, Error> {
queries().list(pool, (self, my_person)).await queries().list(pool, (self, user)).await
} }
} }
@ -254,7 +255,10 @@ mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]
#![allow(clippy::indexing_slicing)] #![allow(clippy::indexing_slicing)]
use crate::comment_report_view::{CommentReportQuery, CommentReportView}; use crate::{
comment_report_view::{CommentReportQuery, CommentReportView},
structs::LocalUserView,
};
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::CommentAggregates, aggregates::structs::CommentAggregates,
source::{ source::{
@ -262,6 +266,7 @@ mod tests {
comment_report::{CommentReport, CommentReportForm}, comment_report::{CommentReport, CommentReportForm},
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm}, community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
instance::Instance, instance::Instance,
local_user::{LocalUser, LocalUserInsertForm},
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
post::{Post, PostInsertForm}, post::{Post, PostInsertForm},
}, },
@ -288,6 +293,17 @@ mod tests {
let inserted_timmy = Person::create(pool, &new_person).await.unwrap(); let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
let new_local_user = LocalUserInsertForm::builder()
.person_id(inserted_timmy.id)
.password_encrypted("123".to_string())
.build();
let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap();
let timmy_view = LocalUserView {
local_user: timmy_local_user,
person: inserted_timmy.clone(),
counts: Default::default(),
};
let new_person_2 = PersonInsertForm::builder() let new_person_2 = PersonInsertForm::builder()
.name("sara_crv".into()) .name("sara_crv".into())
.public_key("pubkey".to_string()) .public_key("pubkey".to_string())
@ -412,7 +428,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -436,7 +451,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -480,7 +494,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -497,7 +510,7 @@ mod tests {
// Do a batch read of timmys reports // Do a batch read of timmys reports
let reports = CommentReportQuery::default() let reports = CommentReportQuery::default()
.list(pool, &inserted_timmy) .list(pool, &timmy_view)
.await .await
.unwrap(); .unwrap();
@ -546,7 +559,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -572,7 +584,7 @@ mod tests {
unresolved_only: (true), unresolved_only: (true),
..Default::default() ..Default::default()
} }
.list(pool, &inserted_timmy) .list(pool, &timmy_view)
.await .await
.unwrap(); .unwrap();
assert_eq!(reports_after_resolve[0], expected_sara_report_view); assert_eq!(reports_after_resolve[0], expected_sara_report_view);

View File

@ -205,7 +205,10 @@ fn queries<'a>() -> Queries<
query = query.filter(comment::deleted.eq(false)); query = query.filter(comment::deleted.eq(false));
} }
let is_admin = options.local_user.map(|l| l.person.admin).unwrap_or(false); let is_admin = options
.local_user
.map(|l| l.local_user.admin)
.unwrap_or(false);
// only show removed comments to admin when viewing user profile // only show removed comments to admin when viewing user profile
if !(options.is_profile_view && is_admin) { if !(options.is_profile_view && is_admin) {
query = query.filter(comment::removed.eq(false)); query = query.filter(comment::removed.eq(false));
@ -847,7 +850,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,

View File

@ -62,7 +62,7 @@ fn queries<'a>(
ListMode::AdminsWithEmails => { ListMode::AdminsWithEmails => {
local_user::table local_user::table
.filter(local_user::email.is_not_null()) .filter(local_user::email.is_not_null())
.filter(person::admin.eq(true)) .filter(local_user::admin.eq(true))
.inner_join(person::table) .inner_join(person::table)
.inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id))) .inner_join(person_aggregates::table.on(person::id.eq(person_aggregates::person_id)))
.select(selection) .select(selection)

View File

@ -1,4 +1,4 @@
use crate::structs::PostReportView; use crate::structs::{LocalUserView, PostReportView};
use diesel::{ use diesel::{
pg::Pg, pg::Pg,
result::Error, result::Error,
@ -42,7 +42,7 @@ type PostReportViewTuple = (
fn queries<'a>() -> Queries< fn queries<'a>() -> Queries<
impl ReadFn<'a, PostReportView, (PostReportId, PersonId)>, impl ReadFn<'a, PostReportView, (PostReportId, PersonId)>,
impl ListFn<'a, PostReportView, (PostReportQuery, &'a Person)>, impl ListFn<'a, PostReportView, (PostReportQuery, &'a LocalUserView)>,
> { > {
let all_joins = |query: post_report::BoxedQuery<'a, Pg>, my_person_id: PersonId| { let all_joins = |query: post_report::BoxedQuery<'a, Pg>, my_person_id: PersonId| {
query query
@ -91,8 +91,8 @@ fn queries<'a>() -> Queries<
.await .await
}; };
let list = move |mut conn: DbConn<'a>, (options, my_person): (PostReportQuery, &'a Person)| async move { let list = move |mut conn: DbConn<'a>, (options, user): (PostReportQuery, &'a LocalUserView)| async move {
let mut query = all_joins(post_report::table.into_boxed(), my_person.id); let mut query = all_joins(post_report::table.into_boxed(), user.person.id);
if let Some(community_id) = options.community_id { if let Some(community_id) = options.community_id {
query = query.filter(post::community_id.eq(community_id)); query = query.filter(post::community_id.eq(community_id));
@ -110,13 +110,13 @@ fn queries<'a>() -> Queries<
.offset(offset); .offset(offset);
// If its not an admin, get only the ones you mod // If its not an admin, get only the ones you mod
if !my_person.admin { if !user.local_user.admin {
query query
.inner_join( .inner_join(
community_moderator::table.on( community_moderator::table.on(
community_moderator::community_id community_moderator::community_id
.eq(post::community_id) .eq(post::community_id)
.and(community_moderator::person_id.eq(my_person.id)), .and(community_moderator::person_id.eq(user.person.id)),
), ),
) )
.load::<PostReportViewTuple>(&mut conn) .load::<PostReportViewTuple>(&mut conn)
@ -193,9 +193,9 @@ impl PostReportQuery {
pub async fn list( pub async fn list(
self, self,
pool: &mut DbPool<'_>, pool: &mut DbPool<'_>,
my_person: &Person, user: &LocalUserView,
) -> Result<Vec<PostReportView>, Error> { ) -> Result<Vec<PostReportView>, Error> {
queries().list(pool, (self, my_person)).await queries().list(pool, (self, user)).await
} }
} }
@ -221,12 +221,16 @@ mod tests {
#![allow(clippy::unwrap_used)] #![allow(clippy::unwrap_used)]
#![allow(clippy::indexing_slicing)] #![allow(clippy::indexing_slicing)]
use crate::post_report_view::{PostReportQuery, PostReportView}; use crate::{
post_report_view::{PostReportQuery, PostReportView},
structs::LocalUserView,
};
use lemmy_db_schema::{ use lemmy_db_schema::{
aggregates::structs::PostAggregates, aggregates::structs::PostAggregates,
source::{ source::{
community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm}, community::{Community, CommunityInsertForm, CommunityModerator, CommunityModeratorForm},
instance::Instance, instance::Instance,
local_user::{LocalUser, LocalUserInsertForm},
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
post::{Post, PostInsertForm}, post::{Post, PostInsertForm},
post_report::{PostReport, PostReportForm}, post_report::{PostReport, PostReportForm},
@ -254,6 +258,17 @@ mod tests {
let inserted_timmy = Person::create(pool, &new_person).await.unwrap(); let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
let new_local_user = LocalUserInsertForm::builder()
.person_id(inserted_timmy.id)
.password_encrypted("123".to_string())
.build();
let timmy_local_user = LocalUser::create(pool, &new_local_user).await.unwrap();
let timmy_view = LocalUserView {
local_user: timmy_local_user,
person: inserted_timmy.clone(),
counts: Default::default(),
};
let new_person_2 = PersonInsertForm::builder() let new_person_2 = PersonInsertForm::builder()
.name("sara_prv".into()) .name("sara_prv".into())
.public_key("pubkey".to_string()) .public_key("pubkey".to_string())
@ -369,7 +384,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -393,7 +407,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -445,7 +458,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -462,7 +474,7 @@ mod tests {
// Do a batch read of timmys reports // Do a batch read of timmys reports
let reports = PostReportQuery::default() let reports = PostReportQuery::default()
.list(pool, &inserted_timmy) .list(pool, &timmy_view)
.await .await
.unwrap(); .unwrap();
@ -509,7 +521,6 @@ mod tests {
local: true, local: true,
banned: false, banned: false,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -535,7 +546,7 @@ mod tests {
unresolved_only: (true), unresolved_only: (true),
..Default::default() ..Default::default()
} }
.list(pool, &inserted_timmy) .list(pool, &timmy_view)
.await .await
.unwrap(); .unwrap();
assert_eq!(reports_after_resolve[0], expected_sara_report_view); assert_eq!(reports_after_resolve[0], expected_sara_report_view);

View File

@ -1,13 +1,14 @@
use crate::structs::{LocalUserView, PostView}; use crate::structs::{LocalUserView, PostView};
use diesel::{ use diesel::{
debug_query, debug_query,
dsl::{now, IntervalDsl}, dsl::IntervalDsl,
pg::Pg, pg::Pg,
result::Error, result::Error,
sql_function, sql_function,
sql_types, sql_types::{self, Timestamptz},
BoolExpressionMethods, BoolExpressionMethods,
ExpressionMethods, ExpressionMethods,
IntoSql,
JoinOnDsl, JoinOnDsl,
NullableExpressionMethods, NullableExpressionMethods,
PgTextExpressionMethods, PgTextExpressionMethods,
@ -217,7 +218,10 @@ fn queries<'a>() -> Queries<
.filter(post::deleted.eq(false)); .filter(post::deleted.eq(false));
} }
let is_admin = options.local_user.map(|l| l.person.admin).unwrap_or(false); let is_admin = options
.local_user
.map(|l| l.local_user.admin)
.unwrap_or(false);
// only show removed posts to admin when viewing user profile // only show removed posts to admin when viewing user profile
if !(options.is_profile_view && is_admin) { if !(options.is_profile_view && is_admin) {
query = query query = query
@ -324,6 +328,7 @@ fn queries<'a>() -> Queries<
query = query.filter(person_block::person_id.is_null()); query = query.filter(person_block::person_id.is_null());
} }
} }
let now = diesel::dsl::now.into_sql::<Timestamptz>();
query = match options.sort.unwrap_or(SortType::Hot) { query = match options.sort.unwrap_or(SortType::Hot) {
SortType::Active => query SortType::Active => query
@ -945,7 +950,7 @@ mod tests {
assert_eq!(1, post_listings_no_admin.len()); assert_eq!(1, post_listings_no_admin.len());
// Removed post is shown to admins on profile page // Removed post is shown to admins on profile page
data.local_user_view.person.admin = true; data.local_user_view.local_user.admin = true;
let post_listings_is_admin = PostQuery { let post_listings_is_admin = PostQuery {
sort: Some(SortType::New), sort: Some(SortType::New),
local_user: Some(&data.local_user_view), local_user: Some(&data.local_user_view),
@ -1071,7 +1076,6 @@ mod tests {
avatar: None, avatar: None,
actor_id: inserted_person.actor_id.clone(), actor_id: inserted_person.actor_id.clone(),
local: true, local: true,
admin: false,
bot_account: false, bot_account: false,
banned: false, banned: false,
deleted: false, deleted: false,

View File

@ -178,7 +178,6 @@ mod tests {
let timmy_form = PersonInsertForm::builder() let timmy_form = PersonInsertForm::builder()
.name("timmy_rav".into()) .name("timmy_rav".into())
.admin(Some(true))
.public_key("pubkey".to_string()) .public_key("pubkey".to_string())
.instance_id(instance.id) .instance_id(instance.id)
.build(); .build();

View File

@ -184,7 +184,6 @@ mod tests {
let timmy_person_form = PersonInsertForm::builder() let timmy_person_form = PersonInsertForm::builder()
.name("timmy_rav".into()) .name("timmy_rav".into())
.admin(Some(true))
.public_key("pubkey".to_string()) .public_key("pubkey".to_string())
.instance_id(inserted_instance.id) .instance_id(inserted_instance.id)
.build(); .build();
@ -194,6 +193,7 @@ mod tests {
let timmy_local_user_form = LocalUserInsertForm::builder() let timmy_local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_timmy_person.id) .person_id(inserted_timmy_person.id)
.password_encrypted("nada".to_string()) .password_encrypted("nada".to_string())
.admin(Some(true))
.build(); .build();
let _inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form) let _inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form)
@ -289,6 +289,7 @@ mod tests {
password_encrypted: inserted_sara_local_user.password_encrypted, password_encrypted: inserted_sara_local_user.password_encrypted,
open_links_in_new_tab: inserted_sara_local_user.open_links_in_new_tab, open_links_in_new_tab: inserted_sara_local_user.open_links_in_new_tab,
infinite_scroll_enabled: inserted_sara_local_user.infinite_scroll_enabled, infinite_scroll_enabled: inserted_sara_local_user.infinite_scroll_enabled,
admin: false,
}, },
creator: Person { creator: Person {
id: inserted_sara_person.id, id: inserted_sara_person.id,
@ -301,7 +302,6 @@ mod tests {
banned: false, banned: false,
ban_expires: None, ban_expires: None,
deleted: false, deleted: false,
admin: false,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,
@ -380,7 +380,6 @@ mod tests {
banned: false, banned: false,
ban_expires: None, ban_expires: None,
deleted: false, deleted: false,
admin: true,
bot_account: false, bot_account: false,
bio: None, bio: None,
banner: None, banner: None,

View File

@ -1,10 +1,10 @@
use crate::structs::PersonView; use crate::structs::PersonView;
use diesel::{ use diesel::{
dsl::now,
pg::Pg, pg::Pg,
result::Error, result::Error,
BoolExpressionMethods, BoolExpressionMethods,
ExpressionMethods, ExpressionMethods,
NullableExpressionMethods,
PgTextExpressionMethods, PgTextExpressionMethods,
QueryDsl, QueryDsl,
}; };
@ -13,10 +13,10 @@ use lemmy_db_schema::{
aggregates::structs::PersonAggregates, aggregates::structs::PersonAggregates,
newtypes::PersonId, newtypes::PersonId,
schema, schema,
schema::{person, person_aggregates}, schema::{local_user, person, person_aggregates},
source::person::Person, source::person::Person,
traits::JoinView, traits::JoinView,
utils::{fuzzy_search, get_conn, limit_and_offset, DbConn, DbPool, ListFn, Queries, ReadFn}, utils::{fuzzy_search, get_conn, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn},
PersonSortType, PersonSortType,
}; };
@ -33,6 +33,7 @@ fn queries<'a>(
let all_joins = |query: person::BoxedQuery<'a, Pg>| { let all_joins = |query: person::BoxedQuery<'a, Pg>| {
query query
.inner_join(person_aggregates::table) .inner_join(person_aggregates::table)
.left_join(local_user::table)
.select((person::all_columns, person_aggregates::all_columns)) .select((person::all_columns, person_aggregates::all_columns))
}; };
@ -47,7 +48,7 @@ fn queries<'a>(
match mode { match mode {
ListMode::Admins => { ListMode::Admins => {
query = query query = query
.filter(person::admin.eq(true)) .filter(local_user::admin.eq(true))
.filter(person::deleted.eq(false)) .filter(person::deleted.eq(false))
.order_by(person::published); .order_by(person::published);
} }
@ -57,7 +58,7 @@ fn queries<'a>(
person::banned.eq(true).and( person::banned.eq(true).and(
person::ban_expires person::ban_expires
.is_null() .is_null()
.or(person::ban_expires.gt(now)), .or(person::ban_expires.gt(now().nullable())),
), ),
) )
.filter(person::deleted.eq(false)); .filter(person::deleted.eq(false));
@ -95,9 +96,13 @@ impl PersonView {
} }
pub async fn is_admin(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<bool, Error> { pub async fn is_admin(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<bool, Error> {
use schema::person::dsl::{admin, id, person}; use schema::{
local_user::dsl::admin,
person::dsl::{id, person},
};
let conn = &mut get_conn(pool).await?; let conn = &mut get_conn(pool).await?;
let is_admin = person let is_admin = person
.inner_join(local_user::table)
.filter(id.eq(person_id)) .filter(id.eq(person_id))
.select(admin) .select(admin)
.first::<bool>(conn) .first::<bool>(conn)

View File

@ -1,6 +1,6 @@
use actix_web::{error::ErrorBadRequest, web, Error, HttpRequest, HttpResponse, Result}; use actix_web::{error::ErrorBadRequest, web, Error, HttpRequest, HttpResponse, Result};
use anyhow::anyhow; use anyhow::anyhow;
use chrono::{DateTime, NaiveDateTime, Utc}; use chrono::{DateTime, Utc};
use lemmy_api_common::context::LemmyContext; use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::{ use lemmy_db_schema::{
newtypes::LocalUserId, newtypes::LocalUserId,
@ -449,7 +449,7 @@ fn create_reply_and_mention_items(
#[tracing::instrument(skip_all)] #[tracing::instrument(skip_all)]
fn build_item( fn build_item(
creator_name: &str, creator_name: &str,
published: &NaiveDateTime, published: &DateTime<Utc>,
url: &str, url: &str,
content: &str, content: &str,
protocol_and_hostname: &str, protocol_and_hostname: &str,
@ -460,7 +460,7 @@ fn build_item(
i.author(format!( i.author(format!(
"/u/{creator_name} <a href=\"{author_url}\">(link)</a>" "/u/{creator_name} <a href=\"{author_url}\">(link)</a>"
)); ));
let dt = DateTime::<Utc>::from_utc(*published, Utc); let dt = published;
i.pub_date(dt.to_rfc2822()); i.pub_date(dt.to_rfc2822());
i.comments(url.to_owned()); i.comments(url.to_owned());
let guid = GuidBuilder::default().permalink(true).value(url).build(); let guid = GuidBuilder::default().permalink(true).value(url).build();
@ -487,7 +487,7 @@ fn create_post_items(
dc_extension.creators(vec![p.creator.actor_id.to_string()]); dc_extension.creators(vec![p.creator.actor_id.to_string()]);
let dt = DateTime::<Utc>::from_utc(p.post.published, Utc); let dt = p.post.published;
i.pub_date(dt.to_rfc2822()); i.pub_date(dt.to_rfc2822());
let post_url = format!("{}/post/{}", protocol_and_hostname, p.post.id); let post_url = format!("{}/post/{}", protocol_and_hostname, p.post.id);

View File

@ -2,7 +2,6 @@ use crate::error::LemmyError;
use chrono::Utc; use chrono::Utc;
use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
type Jwt = String; type Jwt = String;
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View File

@ -1,12 +1,12 @@
use chrono::{DateTime, FixedOffset, NaiveDateTime}; use chrono::{DateTime, TimeZone, Utc};
pub fn naive_from_unix(time: i64) -> NaiveDateTime { pub fn naive_from_unix(time: i64) -> DateTime<Utc> {
NaiveDateTime::from_timestamp_opt(time, 0).expect("convert datetime") Utc
.timestamp_opt(time, 0)
.single()
.expect("convert datetime")
} }
pub fn convert_datetime(datetime: NaiveDateTime) -> DateTime<FixedOffset> { pub fn convert_datetime(datetime: DateTime<Utc>) -> DateTime<Utc> {
DateTime::<FixedOffset>::from_utc( datetime
datetime,
FixedOffset::east_opt(0).expect("create fixed offset"),
)
} }

View File

@ -0,0 +1,16 @@
ALTER TABLE person
ADD COLUMN admin boolean DEFAULT FALSE NOT NULL;
UPDATE
person
SET
admin = TRUE
FROM
local_user
WHERE
local_user.person_id = person.id
AND local_user.admin;
ALTER TABLE local_user
DROP COLUMN admin;

View File

@ -0,0 +1,16 @@
ALTER TABLE local_user
ADD COLUMN admin boolean DEFAULT FALSE NOT NULL;
UPDATE
local_user
SET
admin = TRUE
FROM
person
WHERE
local_user.person_id = person.id
AND person.admin;
ALTER TABLE person
DROP COLUMN admin;

View File

@ -0,0 +1,346 @@
SET timezone TO utc;
ALTER TABLE community_moderator
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community_follower
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE person_ban
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community_person_ban
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community_person_ban
ALTER COLUMN expires TYPE timestamp
USING expires;
ALTER TABLE person
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE person
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE person
ALTER COLUMN last_refreshed_at TYPE timestamp
USING last_refreshed_at;
ALTER TABLE person
ALTER COLUMN ban_expires TYPE timestamp
USING ban_expires;
ALTER TABLE post_like
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE post_saved
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE post_read
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE comment_like
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE comment_saved
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE comment
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE comment
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE mod_remove_post
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_lock_post
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_remove_comment
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_remove_community
ALTER COLUMN expires TYPE timestamp
USING expires;
ALTER TABLE mod_remove_community
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_ban_from_community
ALTER COLUMN expires TYPE timestamp
USING expires;
ALTER TABLE mod_ban_from_community
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_ban
ALTER COLUMN expires TYPE timestamp
USING expires;
ALTER TABLE mod_ban
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_add_community
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE mod_add
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE person_mention
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE mod_feature_post
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE password_reset_request
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE private_message
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE private_message
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE sent_activity
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE received_activity
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE community
ALTER COLUMN last_refreshed_at TYPE timestamp
USING last_refreshed_at;
ALTER TABLE post
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE post
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE comment_report
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE comment_report
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE post_report
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE post_report
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE post_aggregates
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE post_aggregates
ALTER COLUMN newest_comment_time_necro TYPE timestamp
USING newest_comment_time_necro;
ALTER TABLE post_aggregates
ALTER COLUMN newest_comment_time TYPE timestamp
USING newest_comment_time;
ALTER TABLE comment_aggregates
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community_block
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE community_aggregates
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE mod_transfer_community
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE person_block
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE local_user
ALTER COLUMN validator_time TYPE timestamp
USING validator_time;
ALTER TABLE admin_purge_person
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE email_verification
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE admin_purge_community
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE admin_purge_post
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE admin_purge_comment
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE registration_application
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE mod_hide_community
ALTER COLUMN when_ TYPE timestamp
USING when_;
ALTER TABLE site
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE site
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE site
ALTER COLUMN last_refreshed_at TYPE timestamp
USING last_refreshed_at;
ALTER TABLE comment_reply
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE person_post_aggregates
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE private_message_report
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE private_message_report
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE local_site
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE local_site
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE federation_allowlist
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE federation_allowlist
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE federation_blocklist
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE federation_blocklist
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE local_site_rate_limit
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE local_site_rate_limit
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE person_follower
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE tagline
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE tagline
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE custom_emoji
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE custom_emoji
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE instance
ALTER COLUMN published TYPE timestamp
USING published;
ALTER TABLE instance
ALTER COLUMN updated TYPE timestamp
USING updated;
ALTER TABLE captcha_answer
ALTER COLUMN published TYPE timestamp
USING published;
CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp without time zone)
RETURNS integer
AS $$
DECLARE
hours_diff numeric := EXTRACT(EPOCH FROM (timezone('utc', now()) - published)) / 3600;
BEGIN
IF (hours_diff > 0) THEN
RETURN floor(10000 * log(greatest (1, score + 3)) / power((hours_diff + 2), 1.8))::integer;
ELSE
RETURN 0;
END IF;
END;
$$
LANGUAGE plpgsql
IMMUTABLE PARALLEL SAFE;

View File

@ -0,0 +1,351 @@
SET timezone = 'UTC';
-- Allow ALTER TABLE ... SET DATA TYPE changing between timestamp and timestamptz to avoid a table rewrite when the session time zone is UTC (Noah Misch)
-- In the UTC time zone, these two data types are binary compatible.
ALTER TABLE community_moderator
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community_follower
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE person_ban
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community_person_ban
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community_person_ban
ALTER COLUMN expires TYPE timestamptz
USING expires;
ALTER TABLE person
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE person
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE person
ALTER COLUMN last_refreshed_at TYPE timestamptz
USING last_refreshed_at;
ALTER TABLE person
ALTER COLUMN ban_expires TYPE timestamptz
USING ban_expires;
ALTER TABLE post_like
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE post_saved
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE post_read
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE comment_like
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE comment_saved
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE comment
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE comment
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE mod_remove_post
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_lock_post
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_remove_comment
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_remove_community
ALTER COLUMN expires TYPE timestamptz
USING expires;
ALTER TABLE mod_remove_community
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_ban_from_community
ALTER COLUMN expires TYPE timestamptz
USING expires;
ALTER TABLE mod_ban_from_community
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_ban
ALTER COLUMN expires TYPE timestamptz
USING expires;
ALTER TABLE mod_ban
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_add_community
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE mod_add
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE person_mention
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE mod_feature_post
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE password_reset_request
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE private_message
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE private_message
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE sent_activity
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE received_activity
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE community
ALTER COLUMN last_refreshed_at TYPE timestamptz
USING last_refreshed_at;
ALTER TABLE post
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE post
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE comment_report
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE comment_report
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE post_report
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE post_report
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE post_aggregates
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE post_aggregates
ALTER COLUMN newest_comment_time_necro TYPE timestamptz
USING newest_comment_time_necro;
ALTER TABLE post_aggregates
ALTER COLUMN newest_comment_time TYPE timestamptz
USING newest_comment_time;
ALTER TABLE comment_aggregates
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community_block
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE community_aggregates
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE mod_transfer_community
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE person_block
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE local_user
ALTER COLUMN validator_time TYPE timestamptz
USING validator_time;
ALTER TABLE admin_purge_person
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE email_verification
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE admin_purge_community
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE admin_purge_post
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE admin_purge_comment
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE registration_application
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE mod_hide_community
ALTER COLUMN when_ TYPE timestamptz
USING when_;
ALTER TABLE site
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE site
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE site
ALTER COLUMN last_refreshed_at TYPE timestamptz
USING last_refreshed_at;
ALTER TABLE comment_reply
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE person_post_aggregates
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE private_message_report
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE private_message_report
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE local_site
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE local_site
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE federation_allowlist
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE federation_allowlist
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE federation_blocklist
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE federation_blocklist
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE local_site_rate_limit
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE local_site_rate_limit
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE person_follower
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE tagline
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE tagline
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE custom_emoji
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE custom_emoji
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE instance
ALTER COLUMN published TYPE timestamptz
USING published;
ALTER TABLE instance
ALTER COLUMN updated TYPE timestamptz
USING updated;
ALTER TABLE captcha_answer
ALTER COLUMN published TYPE timestamptz
USING published;
-- same as before just with time zone argument
CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp with time zone)
RETURNS integer
AS $$
DECLARE
hours_diff numeric := EXTRACT(EPOCH FROM (now() - published)) / 3600;
BEGIN
IF (hours_diff > 0) THEN
RETURN floor(10000 * log(greatest (1, score + 3)) / power((hours_diff + 2), 1.8))::integer;
ELSE
-- if the post is from the future, set hot score to 0. otherwise you can game the post to
-- always be on top even with only 1 vote by setting it to the future
RETURN 0;
END IF;
END;
$$
LANGUAGE plpgsql
IMMUTABLE PARALLEL SAFE;

View File

@ -457,7 +457,6 @@ async fn initialize_local_site_2022_10_10(
// Register the user if there's a site setup // Register the user if there's a site setup
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm::builder()
.name(setup.admin_username.clone()) .name(setup.admin_username.clone())
.admin(Some(true))
.instance_id(instance.id) .instance_id(instance.id)
.actor_id(Some(person_actor_id.clone())) .actor_id(Some(person_actor_id.clone()))
.private_key(Some(person_keypair.private_key)) .private_key(Some(person_keypair.private_key))
@ -471,6 +470,7 @@ async fn initialize_local_site_2022_10_10(
.person_id(person_inserted.id) .person_id(person_inserted.id)
.password_encrypted(setup.admin_password.clone()) .password_encrypted(setup.admin_password.clone())
.email(setup.admin_email.clone()) .email(setup.admin_email.clone())
.admin(Some(true))
.build(); .build();
LocalUser::create(pool, &local_user_form).await?; LocalUser::create(pool, &local_user_form).await?;
}; };

Some files were not shown because too many files have changed in this diff Show More