From 514f2222e05a64a35f73436aef4c6e83dbf4b7f1 Mon Sep 17 00:00:00 2001 From: phiresky Date: Thu, 24 Aug 2023 17:27:00 +0200 Subject: [PATCH] Fix time zone handling (#3496) * convert naive time to utc time * compounding fixes * cargo fmt * fix the rest * fix down migration * fix migrations * fix after merge * clippy fix * ap-fed 0.5.0 --------- Co-authored-by: Nutomic --- Cargo.lock | 4 +- Cargo.toml | 2 +- crates/api_common/src/utils.rs | 6 +- .../lemmy/activities/block/block_user.json | 2 +- .../activities/block/undo_block_user.json | 2 +- .../community/announce_create_page.json | 2 +- .../community/update_community.json | 4 +- .../create_or_update/create_note.json | 2 +- .../create_or_update/create_page.json | 2 +- .../create_private_message.json | 2 +- .../create_or_update/update_page.json | 4 +- .../collections/group_featured_posts.json | 4 +- .../lemmy/collections/group_outbox.json | 4 +- .../assets/lemmy/objects/chat_message.json | 2 +- crates/apub/assets/lemmy/objects/group.json | 4 +- .../apub/assets/lemmy/objects/instance.json | 2 +- crates/apub/assets/lemmy/objects/note.json | 4 +- crates/apub/assets/lemmy/objects/page.json | 2 +- crates/apub/assets/lemmy/objects/person.json | 4 +- .../apub/src/activities/block/block_user.rs | 12 +- crates/apub/src/activities/block/mod.rs | 4 +- .../src/activities/block/undo_block_user.rs | 2 +- crates/apub/src/fetcher/post_or_comment.rs | 4 +- crates/apub/src/fetcher/search.rs | 4 +- crates/apub/src/fetcher/user_or_community.rs | 4 +- crates/apub/src/lib.rs | 11 +- crates/apub/src/objects/comment.rs | 8 +- crates/apub/src/objects/community.rs | 4 +- crates/apub/src/objects/instance.rs | 6 +- crates/apub/src/objects/person.rs | 8 +- crates/apub/src/objects/post.rs | 10 +- crates/apub/src/objects/private_message.rs | 8 +- .../protocol/activities/block/block_user.rs | 4 +- .../apub/src/protocol/objects/chat_message.rs | 6 +- crates/apub/src/protocol/objects/group.rs | 14 +- crates/apub/src/protocol/objects/instance.rs | 6 +- crates/apub/src/protocol/objects/note.rs | 6 +- crates/apub/src/protocol/objects/page.rs | 6 +- crates/apub/src/protocol/objects/person.rs | 6 +- crates/db_schema/src/aggregates/structs.rs | 16 +- crates/db_schema/src/diesel_ltree.patch | 2 +- .../db_schema/src/impls/email_verification.rs | 4 +- crates/db_schema/src/impls/instance.rs | 10 +- .../src/impls/password_reset_request.rs | 6 +- crates/db_schema/src/impls/person.rs | 3 +- crates/db_schema/src/schema.rs | 166 ++++----- crates/db_schema/src/source/activity.rs | 5 +- crates/db_schema/src/source/captcha_answer.rs | 3 +- crates/db_schema/src/source/comment.rs | 15 +- crates/db_schema/src/source/comment_reply.rs | 3 +- crates/db_schema/src/source/comment_report.rs | 5 +- crates/db_schema/src/source/community.rs | 29 +- .../db_schema/src/source/community_block.rs | 3 +- crates/db_schema/src/source/custom_emoji.rs | 5 +- .../src/source/email_verification.rs | 3 +- .../src/source/federation_allowlist.rs | 7 +- .../src/source/federation_blocklist.rs | 7 +- crates/db_schema/src/source/instance.rs | 7 +- crates/db_schema/src/source/local_site.rs | 7 +- .../src/source/local_site_rate_limit.rs | 7 +- crates/db_schema/src/source/local_user.rs | 3 +- crates/db_schema/src/source/moderator.rs | 43 +-- .../src/source/password_reset_request.rs | 3 +- crates/db_schema/src/source/person.rs | 25 +- crates/db_schema/src/source/person_block.rs | 3 +- crates/db_schema/src/source/person_mention.rs | 3 +- crates/db_schema/src/source/post.rs | 19 +- crates/db_schema/src/source/post_report.rs | 5 +- .../db_schema/src/source/private_message.rs | 13 +- .../src/source/private_message_report.rs | 5 +- .../src/source/registration_application.rs | 3 +- crates/db_schema/src/source/site.rs | 16 +- crates/db_schema/src/source/tagline.rs | 7 +- crates/db_schema/src/utils.rs | 19 +- crates/db_views/src/post_view.rs | 6 +- crates/db_views_actor/src/person_view.rs | 6 +- crates/routes/src/feeds.rs | 8 +- crates/utils/src/claims.rs | 1 - crates/utils/src/utils/time.rs | 16 +- .../2023-08-02-174444_fix-timezones/down.sql | 346 +++++++++++++++++ .../2023-08-02-174444_fix-timezones/up.sql | 351 ++++++++++++++++++ src/scheduled_tasks.rs | 41 +- 82 files changed, 1094 insertions(+), 352 deletions(-) create mode 100644 migrations/2023-08-02-174444_fix-timezones/down.sql create mode 100644 migrations/2023-08-02-174444_fix-timezones/up.sql diff --git a/Cargo.lock b/Cargo.lock index ba37fcc14..a44dfb916 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" [[package]] name = "activitypub_federation" -version = "0.4.6" +version = "0.5.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e6e7fefba6602240fcf612931b70640ad1e249dff833551ebc218f1c96a4193" +checksum = "fb4c5f0e97215be7fb8bdd632283f66d78168f388029d678ab4854ff599f0238" dependencies = [ "activitystreams-kinds", "actix-web", diff --git a/Cargo.toml b/Cargo.toml index 424c10e73..c2adfd0cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ lemmy_routes = { version = "=0.18.1", path = "./crates/routes" } 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_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", ] } diesel = "2.1.0" diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index fa84962d8..a79e3bd52 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -5,7 +5,7 @@ use crate::{ site::FederatedInstances, }; use anyhow::Context; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_db_schema::{ impls::person::is_banned, newtypes::{CommunityId, DbUrl, LocalUserId, PersonId, PostId}, @@ -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. pub fn check_validator_time( - validator_time: &NaiveDateTime, + validator_time: &DateTime, claims: &Claims, ) -> Result<(), LemmyError> { let user_validation_time = validator_time.timestamp(); @@ -176,7 +176,7 @@ pub fn check_validator_time( pub fn check_user_valid( banned: bool, - ban_expires: Option, + ban_expires: Option>, deleted: bool, ) -> Result<(), LemmyError> { // Check for a site ban diff --git a/crates/apub/assets/lemmy/activities/block/block_user.json b/crates/apub/assets/lemmy/activities/block/block_user.json index a94471830..a07d3786c 100644 --- a/crates/apub/assets/lemmy/activities/block/block_user.json +++ b/crates/apub/assets/lemmy/activities/block/block_user.json @@ -8,6 +8,6 @@ "type": "Block", "removeData": true, "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" } diff --git a/crates/apub/assets/lemmy/activities/block/undo_block_user.json b/crates/apub/assets/lemmy/activities/block/undo_block_user.json index 49083448a..5dadc0781 100644 --- a/crates/apub/assets/lemmy/activities/block/undo_block_user.json +++ b/crates/apub/assets/lemmy/activities/block/undo_block_user.json @@ -11,7 +11,7 @@ "type": "Block", "removeData": true, "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" }, "cc": ["http://enterprise.lemmy.ml/c/main"], diff --git a/crates/apub/assets/lemmy/activities/community/announce_create_page.json b/crates/apub/assets/lemmy/activities/community/announce_create_page.json index cb4db8289..71b4a7e54 100644 --- a/crates/apub/assets/lemmy/activities/community/announce_create_page.json +++ b/crates/apub/assets/lemmy/activities/community/announce_create_page.json @@ -17,7 +17,7 @@ "commentsEnabled": true, "sensitive": 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"], "type": "Create", diff --git a/crates/apub/assets/lemmy/activities/community/update_community.json b/crates/apub/assets/lemmy/activities/community/update_community.json index 873b03b76..604e04d45 100644 --- a/crates/apub/assets/lemmy/activities/community/update_community.json +++ b/crates/apub/assets/lemmy/activities/community/update_community.json @@ -35,8 +35,8 @@ "name": "Deutsch" } ], - "published": "2021-10-29T15:05:51.476984+00:00", - "updated": "2021-11-01T12:23:50.151874+00:00" + "published": "2021-10-29T15:05:51.476984Z", + "updated": "2021-11-01T12:23:50.151874Z" }, "cc": ["http://enterprise.lemmy.ml/c/main"], "audience": "http://enterprise.lemmy.ml/u/main", diff --git a/crates/apub/assets/lemmy/activities/create_or_update/create_note.json b/crates/apub/assets/lemmy/activities/create_or_update/create_note.json index eed673fc9..a12eeb51c 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/create_note.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/create_note.json @@ -18,7 +18,7 @@ "mediaType": "text/markdown" }, "inReplyTo": "http://ds9.lemmy.ml/post/1", - "published": "2021-11-01T11:45:49.794920+00:00" + "published": "2021-11-01T11:45:49.794920Z" }, "cc": [ "http://enterprise.lemmy.ml/c/main", diff --git a/crates/apub/assets/lemmy/activities/create_or_update/create_page.json b/crates/apub/assets/lemmy/activities/create_or_update/create_page.json index 1729a8bdd..50d2536fe 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/create_page.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/create_page.json @@ -29,7 +29,7 @@ "identifier": "ko", "name": "한국어" }, - "published": "2021-10-29T15:10:51.557399+00:00" + "published": "2021-10-29T15:10:51.557399Z" }, "cc": ["http://enterprise.lemmy.ml/c/main"], "audience": "https://enterprise.lemmy.ml/c/main", diff --git a/crates/apub/assets/lemmy/activities/create_or_update/create_private_message.json b/crates/apub/assets/lemmy/activities/create_or_update/create_private_message.json index 738515400..54ee39350 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/create_private_message.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/create_private_message.json @@ -13,7 +13,7 @@ "content": "hello", "mediaType": "text/markdown" }, - "published": "2021-10-29T15:31:56.058289+00:00" + "published": "2021-10-29T15:31:56.058289Z" }, "type": "Create" } diff --git a/crates/apub/assets/lemmy/activities/create_or_update/update_page.json b/crates/apub/assets/lemmy/activities/create_or_update/update_page.json index 2e1007638..888b866b8 100644 --- a/crates/apub/assets/lemmy/activities/create_or_update/update_page.json +++ b/crates/apub/assets/lemmy/activities/create_or_update/update_page.json @@ -25,8 +25,8 @@ ], "commentsEnabled": true, "sensitive": false, - "published": "2021-10-29T15:10:51.557399+00:00", - "updated": "2021-10-29T15:11:35.976374+00:00" + "published": "2021-10-29T15:10:51.557399Z", + "updated": "2021-10-29T15:11:35.976374Z" }, "cc": ["http://enterprise.lemmy.ml/c/main"], "audience": "https://enterprise.lemmy.ml/c/main", diff --git a/crates/apub/assets/lemmy/collections/group_featured_posts.json b/crates/apub/assets/lemmy/collections/group_featured_posts.json index 227c6f877..59f1afb9c 100644 --- a/crates/apub/assets/lemmy/collections/group_featured_posts.json +++ b/crates/apub/assets/lemmy/collections/group_featured_posts.json @@ -17,7 +17,7 @@ "attachment": [], "commentsEnabled": true, "sensitive": false, - "published": "2023-02-06T06:42:41.939437+00:00", + "published": "2023-02-06T06:42:41.939437Z", "language": { "identifier": "de", "name": "Deutsch" @@ -38,7 +38,7 @@ "attachment": [], "commentsEnabled": true, "sensitive": false, - "published": "2023-02-06T06:42:37.119567+00:00", + "published": "2023-02-06T06:42:37.119567Z", "language": { "identifier": "de", "name": "Deutsch" diff --git a/crates/apub/assets/lemmy/collections/group_outbox.json b/crates/apub/assets/lemmy/collections/group_outbox.json index 1bdb816b0..c7279a799 100644 --- a/crates/apub/assets/lemmy/collections/group_outbox.json +++ b/crates/apub/assets/lemmy/collections/group_outbox.json @@ -25,7 +25,7 @@ "commentsEnabled": true, "sensitive": 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"], @@ -54,7 +54,7 @@ "commentsEnabled": true, "sensitive": 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"], diff --git a/crates/apub/assets/lemmy/objects/chat_message.json b/crates/apub/assets/lemmy/objects/chat_message.json index c39db8dea..95b37322e 100644 --- a/crates/apub/assets/lemmy/objects/chat_message.json +++ b/crates/apub/assets/lemmy/objects/chat_message.json @@ -9,5 +9,5 @@ "content": "Hello hello, testing", "mediaType": "text/markdown" }, - "published": "2021-10-21T10:13:14.597721+00:00" + "published": "2021-10-21T10:13:14.597721Z" } diff --git a/crates/apub/assets/lemmy/objects/group.json b/crates/apub/assets/lemmy/objects/group.json index 66dfe144b..3870daf75 100644 --- a/crates/apub/assets/lemmy/objects/group.json +++ b/crates/apub/assets/lemmy/objects/group.json @@ -41,6 +41,6 @@ "name": "Deutsch" } ], - "published": "2019-06-02T16:43:50.799554+00:00", - "updated": "2021-03-10T17:18:10.498868+00:00" + "published": "2019-06-02T16:43:50.799554Z", + "updated": "2021-03-10T17:18:10.498868Z" } diff --git a/crates/apub/assets/lemmy/objects/instance.json b/crates/apub/assets/lemmy/objects/instance.json index a7c3ca5db..1e07043d9 100644 --- a/crates/apub/assets/lemmy/objects/instance.json +++ b/crates/apub/assets/lemmy/objects/instance.json @@ -26,5 +26,5 @@ "name": "Español" } ], - "published": "2022-01-19T21:52:11.110741+00:00" + "published": "2022-01-19T21:52:11.110741Z" } diff --git a/crates/apub/assets/lemmy/objects/note.json b/crates/apub/assets/lemmy/objects/note.json index 2e50abcdb..8366ebd6d 100644 --- a/crates/apub/assets/lemmy/objects/note.json +++ b/crates/apub/assets/lemmy/objects/note.json @@ -27,6 +27,6 @@ "identifier": "fr", "name": "Français" }, - "published": "2021-03-01T13:42:43.966208+00:00", - "updated": "2021-03-01T13:43:03.955787+00:00" + "published": "2021-03-01T13:42:43.966208Z", + "updated": "2021-03-01T13:43:03.955787Z" } diff --git a/crates/apub/assets/lemmy/objects/page.json b/crates/apub/assets/lemmy/objects/page.json index b3e9b480b..6b536dd90 100644 --- a/crates/apub/assets/lemmy/objects/page.json +++ b/crates/apub/assets/lemmy/objects/page.json @@ -30,5 +30,5 @@ "identifier": "fr", "name": "Français" }, - "published": "2021-02-26T12:35:34.292626+00:00" + "published": "2021-02-26T12:35:34.292626Z" } diff --git a/crates/apub/assets/lemmy/objects/person.json b/crates/apub/assets/lemmy/objects/person.json index 4f708656c..5be860c6c 100644 --- a/crates/apub/assets/lemmy/objects/person.json +++ b/crates/apub/assets/lemmy/objects/person.json @@ -22,8 +22,8 @@ "endpoints": { "sharedInbox": "https://enterprise.lemmy.ml/inbox" }, - "published": "2020-01-17T01:38:22.348392+00:00", - "updated": "2021-08-13T00:11:15.941990+00:00", + "published": "2020-01-17T01:38:22.348392Z", + "updated": "2021-08-13T00:11:15.941990Z", "publicKey": { "id": "https://enterprise.lemmy.ml/u/picard#main-key", "owner": "https://enterprise.lemmy.ml/u/picard", diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index b4fb53c7d..163aca038 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -20,7 +20,7 @@ use activitypub_federation::{ traits::{ActivityHandler, Actor}, }; use anyhow::anyhow; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{remove_user_data, remove_user_data_in_community, sanitize_html_opt}, @@ -38,7 +38,7 @@ use lemmy_db_schema::{ }, traits::{Bannable, Crud, Followable}, }; -use lemmy_utils::{error::LemmyError, utils::time::convert_datetime}; +use lemmy_utils::error::LemmyError; use url::Url; impl BlockUser { @@ -48,7 +48,7 @@ impl BlockUser { mod_: &ApubPerson, remove_data: Option, reason: Option, - expires: Option, + expires: Option>, context: &Data, ) -> Result { let audience = if let SiteOrCommunity::Community(c) = target { @@ -70,7 +70,7 @@ impl BlockUser { &context.settings().get_protocol_and_hostname(), )?, audience, - expires: expires.map(convert_datetime), + expires, }) } @@ -81,7 +81,7 @@ impl BlockUser { mod_: &ApubPerson, remove_data: bool, reason: Option, - expires: Option, + expires: Option>, context: &Data, ) -> Result<(), LemmyError> { let block = BlockUser::new( @@ -148,7 +148,7 @@ impl ActivityHandler for BlockUser { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> 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 blocked_person = self.object.dereference(context).await?; let target = self.target.dereference(context).await?; diff --git a/crates/apub/src/activities/block/mod.rs b/crates/apub/src/activities/block/mod.rs index e9986afc8..0d64aacd4 100644 --- a/crates/apub/src/activities/block/mod.rs +++ b/crates/apub/src/activities/block/mod.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ fetch::object_id::ObjectId, traits::{Actor, Object}, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{community::BanFromCommunity, context::LemmyContext, person::BanPerson}; use lemmy_db_schema::{ newtypes::CommunityId, @@ -49,7 +49,7 @@ impl Object for SiteOrCommunity { type Error = LemmyError; #[tracing::instrument(skip_all)] - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { Some(match self { SiteOrCommunity::Site(i) => i.last_refreshed_at, SiteOrCommunity::Community(c) => c.last_refreshed_at, diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index 91cafa0a5..5f6bf84cb 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -97,7 +97,7 @@ impl ActivityHandler for UndoBlockUser { #[tracing::instrument(skip_all)] async fn receive(self, context: &Data) -> 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 blocked_person = self.object.object.dereference(context).await?; match self.object.target.dereference(context).await? { diff --git a/crates/apub/src/fetcher/post_or_comment.rs b/crates/apub/src/fetcher/post_or_comment.rs index 929149669..31c53864a 100644 --- a/crates/apub/src/fetcher/post_or_comment.rs +++ b/crates/apub/src/fetcher/post_or_comment.rs @@ -6,7 +6,7 @@ use crate::{ }, }; use activitypub_federation::{config::Data, traits::Object}; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ source::{community::Community, post::Post}, @@ -35,7 +35,7 @@ impl Object for PostOrComment { type Kind = PageOrNote; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { None } diff --git a/crates/apub/src/fetcher/search.rs b/crates/apub/src/fetcher/search.rs index dd8ef2ca2..54951edd9 100644 --- a/crates/apub/src/fetcher/search.rs +++ b/crates/apub/src/fetcher/search.rs @@ -7,7 +7,7 @@ use activitypub_federation::{ fetch::{object_id::ObjectId, webfinger::webfinger_resolve_actor}, traits::Object, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_utils::error::{LemmyError, LemmyErrorType}; use serde::Deserialize; @@ -80,7 +80,7 @@ impl Object for SearchableObjects { type Kind = SearchableKinds; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { match self { SearchableObjects::Person(p) => p.last_refreshed_at(), SearchableObjects::Community(c) => c.last_refreshed_at(), diff --git a/crates/apub/src/fetcher/user_or_community.rs b/crates/apub/src/fetcher/user_or_community.rs index d872c4e24..8ce188ca6 100644 --- a/crates/apub/src/fetcher/user_or_community.rs +++ b/crates/apub/src/fetcher/user_or_community.rs @@ -6,7 +6,7 @@ use activitypub_federation::{ config::Data, traits::{Actor, Object}, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_utils::error::LemmyError; use serde::{Deserialize, Serialize}; @@ -37,7 +37,7 @@ impl Object for UserOrCommunity { type Kind = PersonOrGroup; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { Some(match self { UserOrCommunity::User(p) => p.last_refreshed_at, UserOrCommunity::Community(p) => p.last_refreshed_at, diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 31febd7ff..6b9bb1ff6 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -1,5 +1,6 @@ use crate::fetcher::post_or_comment::PostOrComment; use activitypub_federation::config::{Data, UrlVerifier}; +use anyhow::anyhow; use async_trait::async_trait; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ @@ -38,7 +39,7 @@ pub struct VerifyUrlData(pub ActualDbPool); #[async_trait] 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()) .await .expect("read local site data"); @@ -46,16 +47,16 @@ impl UrlVerifier for VerifyUrlData { LemmyError { error_type: LemmyErrorType::FederationDisabled, .. - } => "Federation disabled", + } => anyhow!("Federation disabled"), LemmyError { error_type: LemmyErrorType::DomainBlocked(_), .. - } => "Domain is blocked", + } => anyhow!("Domain is blocked"), LemmyError { error_type: LemmyErrorType::DomainNotInAllowList(_), .. - } => "Domain is not in allowlist", - _ => "Failed validating apub id", + } => anyhow!("Domain is not in allowlist"), + _ => anyhow!("Failed validating apub id"), })?; Ok(()) } diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index 1b7724431..9be6639c0 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -15,7 +15,7 @@ use activitypub_federation::{ protocol::{values::MediaTypeMarkdownOrHtml, verification::verify_domains_match}, traits::Object, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{local_site_opt_to_slur_regex, sanitize_html}, @@ -59,7 +59,7 @@ impl Object for ApubComment { type Kind = Note; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { None } @@ -170,8 +170,8 @@ impl Object for ApubComment { post_id: post.id, content, removed: None, - published: note.published.map(|u| u.naive_local()), - updated: note.updated.map(|u| u.naive_local()), + published: note.published.map(Into::into), + updated: note.updated.map(Into::into), deleted: Some(false), ap_id: Some(note.id.into()), distinguished: note.distinguished, diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 10d5ddd4f..31055efd8 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -13,7 +13,7 @@ use activitypub_federation::{ kinds::actor::GroupType, traits::{Actor, Object}, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{generate_featured_url, generate_moderators_url, generate_outbox_url}, @@ -56,7 +56,7 @@ impl Object for ApubCommunity { type Kind = Group; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { Some(self.last_refreshed_at) } diff --git a/crates/apub/src/objects/instance.rs b/crates/apub/src/objects/instance.rs index 52fc210b0..5cbe75eda 100644 --- a/crates/apub/src/objects/instance.rs +++ b/crates/apub/src/objects/instance.rs @@ -15,7 +15,7 @@ use activitypub_federation::{ protocol::{values::MediaTypeHtml, verification::verify_domains_match}, traits::{Actor, Object}, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{local_site_opt_to_slur_regex, sanitize_html_opt}, @@ -64,7 +64,7 @@ impl Object for ApubSite { type Kind = Instance; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { Some(self.last_refreshed_at) } @@ -139,7 +139,7 @@ impl Object for ApubSite { let site_form = SiteInsertForm { name: apub.name.clone(), sidebar, - updated: apub.updated.map(|u| u.clone().naive_local()), + updated: apub.updated, icon: apub.icon.clone().map(|i| i.url.into()), banner: apub.image.clone().map(|i| i.url.into()), description, diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 3c98ce735..a0e7f590a 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -16,7 +16,7 @@ use activitypub_federation::{ protocol::verification::verify_domains_match, traits::{Actor, Object}, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{generate_outbox_url, local_site_opt_to_slur_regex, sanitize_html, sanitize_html_opt}, @@ -59,7 +59,7 @@ impl Object for ApubPerson { type Kind = Person; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { Some(self.last_refreshed_at) } @@ -158,8 +158,8 @@ impl Object for ApubPerson { deleted: Some(false), avatar: person.icon.map(|i| i.url.into()), banner: person.image.map(|i| i.url.into()), - published: person.published.map(|u| u.naive_local()), - updated: person.updated.map(|u| u.naive_local()), + published: person.published.map(Into::into), + updated: person.updated.map(Into::into), actor_id: Some(person.id.into()), bio, local: Some(false), diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index df3aefed2..aee2eaf90 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -20,7 +20,7 @@ use activitypub_federation::{ traits::Object, }; use anyhow::anyhow; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use html2md::parse_html; use lemmy_api_common::{ context::LemmyContext, @@ -80,7 +80,7 @@ impl Object for ApubPost { type Kind = Page; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { None } @@ -249,8 +249,8 @@ impl Object for ApubPost { community_id: community.id, removed: None, locked: page.comments_enabled.map(|e| !e), - published: page.published.map(|u| u.naive_local()), - updated: page.updated.map(|u| u.naive_local()), + published: page.published.map(Into::into), + updated: page.updated.map(Into::into), deleted: Some(false), nsfw: page.sensitive, embed_title, @@ -271,7 +271,7 @@ impl Object for ApubPost { .community_id(community.id) .ap_id(Some(page.id.clone().into())) .locked(page.comments_enabled.map(|e| !e)) - .updated(page.updated.map(|u| u.naive_local())) + .updated(page.updated.map(Into::into)) .build() }; diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index 9a92b0b51..2210e0b0e 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -11,7 +11,7 @@ use activitypub_federation::{ protocol::{values::MediaTypeHtml, verification::verify_domains_match}, traits::Object, }; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{check_person_block, sanitize_html}, @@ -52,7 +52,7 @@ impl Object for ApubPrivateMessage { type Kind = ChatMessage; type Error = LemmyError; - fn last_refreshed_at(&self) -> Option { + fn last_refreshed_at(&self) -> Option> { None } @@ -130,8 +130,8 @@ impl Object for ApubPrivateMessage { creator_id: creator.id, recipient_id: recipient.id, content, - published: note.published.map(|u| u.naive_local()), - updated: note.updated.map(|u| u.naive_local()), + published: note.published.map(Into::into), + updated: note.updated.map(Into::into), deleted: Some(false), read: None, ap_id: Some(note.id.into()), diff --git a/crates/apub/src/protocol/activities/block/block_user.rs b/crates/apub/src/protocol/activities/block/block_user.rs index 2cad2adcd..b958b58e1 100644 --- a/crates/apub/src/protocol/activities/block/block_user.rs +++ b/crates/apub/src/protocol/activities/block/block_user.rs @@ -10,7 +10,7 @@ use activitypub_federation::{ protocol::helpers::deserialize_one_or_many, }; use anyhow::anyhow; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_utils::error::LemmyError; use serde::{Deserialize, Serialize}; @@ -38,7 +38,7 @@ pub struct BlockUser { pub(crate) remove_data: Option, /// block reason, written to mod log pub(crate) summary: Option, - pub(crate) expires: Option>, + pub(crate) expires: Option>, } #[async_trait::async_trait] diff --git a/crates/apub/src/protocol/objects/chat_message.rs b/crates/apub/src/protocol/objects/chat_message.rs index 22bdd916a..8cb83e664 100644 --- a/crates/apub/src/protocol/objects/chat_message.rs +++ b/crates/apub/src/protocol/objects/chat_message.rs @@ -9,7 +9,7 @@ use activitypub_federation::{ values::MediaTypeHtml, }, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; @@ -27,8 +27,8 @@ pub struct ChatMessage { pub(crate) media_type: Option, #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) source: Option, - pub(crate) published: Option>, - pub(crate) updated: Option>, + pub(crate) published: Option>, + pub(crate) updated: Option>, } /// https://docs.pleroma.social/backend/development/ap_extensions/#chatmessages diff --git a/crates/apub/src/protocol/objects/group.rs b/crates/apub/src/protocol/objects/group.rs index 9c679fdf1..3ee788f94 100644 --- a/crates/apub/src/protocol/objects/group.rs +++ b/crates/apub/src/protocol/objects/group.rs @@ -22,7 +22,7 @@ use activitypub_federation::{ verification::verify_domains_match, }, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use lemmy_api_common::{ context::LemmyContext, utils::{local_site_opt_to_slur_regex, sanitize_html, sanitize_html_opt}, @@ -73,8 +73,8 @@ pub struct Group { pub(crate) featured: Option>, #[serde(default)] pub(crate) language: Vec, - pub(crate) published: Option>, - pub(crate) updated: Option>, + pub(crate) published: Option>, + pub(crate) updated: Option>, } impl Group { @@ -107,8 +107,8 @@ impl Group { title, description, removed: None, - published: self.published.map(|u| u.naive_local()), - updated: self.updated.map(|u| u.naive_local()), + published: self.published, + updated: self.updated, deleted: Some(false), nsfw: Some(self.sensitive.unwrap_or(false)), actor_id: Some(self.id.into()), @@ -138,8 +138,8 @@ impl Group { &self.source, )), removed: None, - published: self.published.map(|u| u.naive_local()), - updated: Some(self.updated.map(|u| u.naive_local())), + published: self.published.map(Into::into), + updated: Some(self.updated.map(Into::into)), deleted: None, nsfw: Some(self.sensitive.unwrap_or(false)), actor_id: Some(self.id.into()), diff --git a/crates/apub/src/protocol/objects/instance.rs b/crates/apub/src/protocol/objects/instance.rs index 4a3d6ea2e..8c9944306 100644 --- a/crates/apub/src/protocol/objects/instance.rs +++ b/crates/apub/src/protocol/objects/instance.rs @@ -7,7 +7,7 @@ use activitypub_federation::{ kinds::actor::ApplicationType, protocol::{helpers::deserialize_skip_error, public_key::PublicKey, values::MediaTypeHtml}, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -39,6 +39,6 @@ pub struct Instance { pub(crate) image: Option, #[serde(default)] pub(crate) language: Vec, - pub(crate) published: DateTime, - pub(crate) updated: Option>, + pub(crate) published: DateTime, + pub(crate) updated: Option>, } diff --git a/crates/apub/src/protocol/objects/note.rs b/crates/apub/src/protocol/objects/note.rs index f594c14e4..259a8fcfa 100644 --- a/crates/apub/src/protocol/objects/note.rs +++ b/crates/apub/src/protocol/objects/note.rs @@ -14,7 +14,7 @@ use activitypub_federation::{ values::MediaTypeMarkdownOrHtml, }, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ source::{community::Community, post::Post}, @@ -43,8 +43,8 @@ pub struct Note { pub(crate) media_type: Option, #[serde(deserialize_with = "deserialize_skip_error", default)] pub(crate) source: Option, - pub(crate) published: Option>, - pub(crate) updated: Option>, + pub(crate) published: Option>, + pub(crate) updated: Option>, #[serde(default)] pub(crate) tag: Vec, // lemmy extension diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index f3308b075..f7952885e 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -17,7 +17,7 @@ use activitypub_federation::{ }, traits::{ActivityHandler, Object}, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use itertools::Itertools; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::newtypes::DbUrl; @@ -63,8 +63,8 @@ pub struct Page { pub(crate) image: Option, pub(crate) comments_enabled: Option, pub(crate) sensitive: Option, - pub(crate) published: Option>, - pub(crate) updated: Option>, + pub(crate) published: Option>, + pub(crate) updated: Option>, pub(crate) language: Option, pub(crate) audience: Option>, } diff --git a/crates/apub/src/protocol/objects/person.rs b/crates/apub/src/protocol/objects/person.rs index ecedbcd71..cc9607c7f 100644 --- a/crates/apub/src/protocol/objects/person.rs +++ b/crates/apub/src/protocol/objects/person.rs @@ -6,7 +6,7 @@ use activitypub_federation::{ fetch::object_id::ObjectId, protocol::{helpers::deserialize_skip_error, public_key::PublicKey}, }; -use chrono::{DateTime, FixedOffset}; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use url::Url; @@ -43,6 +43,6 @@ pub struct Person { pub(crate) image: Option, pub(crate) matrix_user_id: Option, pub(crate) endpoints: Option, - pub(crate) published: Option>, - pub(crate) updated: Option>, + pub(crate) published: Option>, + pub(crate) updated: Option>, } diff --git a/crates/db_schema/src/aggregates/structs.rs b/crates/db_schema/src/aggregates/structs.rs index 3b3612bb7..f34ff9c89 100644 --- a/crates/db_schema/src/aggregates/structs.rs +++ b/crates/db_schema/src/aggregates/structs.rs @@ -8,10 +8,10 @@ use crate::schema::{ post_aggregates, site_aggregates, }; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] use ts_rs::TS; - #[derive(PartialEq, Debug, Serialize, Deserialize, Clone)] #[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))] #[cfg_attr(feature = "full", diesel(table_name = comment_aggregates))] @@ -24,7 +24,7 @@ pub struct CommentAggregates { pub score: i64, pub upvotes: i64, pub downvotes: i64, - pub published: chrono::NaiveDateTime, + pub published: DateTime, /// The total number of children in this comment branch. pub child_count: i32, pub hot_rank: i32, @@ -46,7 +46,7 @@ pub struct CommunityAggregates { pub subscribers: i64, pub posts: i64, pub comments: i64, - pub published: chrono::NaiveDateTime, + pub published: DateTime, /// The number of users with any activity in the last day. pub users_active_day: i64, /// The number of users with any activity in the last week. @@ -86,11 +86,11 @@ pub struct PostAggregates { pub score: i64, pub upvotes: i64, pub downvotes: i64, - pub published: chrono::NaiveDateTime, + pub published: DateTime, /// A newest comment time, limited to 2 days, to prevent necrobumping - pub newest_comment_time_necro: chrono::NaiveDateTime, + pub newest_comment_time_necro: DateTime, /// The time of the newest comment in the post. - pub newest_comment_time: chrono::NaiveDateTime, + pub newest_comment_time: DateTime, /// If the post is featured on the community. pub featured_community: bool, /// 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. pub read_comments: i64, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[derive(Clone, Default)] @@ -125,7 +125,7 @@ pub struct PersonPostAggregatesForm { pub person_id: PersonId, pub post_id: PostId, pub read_comments: i64, - pub published: Option, + pub published: Option>, } #[derive(PartialEq, Eq, Debug, Serialize, Deserialize, Clone)] diff --git a/crates/db_schema/src/diesel_ltree.patch b/crates/db_schema/src/diesel_ltree.patch index ecbeb2193..0e84eeceb 100644 --- a/crates/db_schema/src/diesel_ltree.patch +++ b/crates/db_schema/src/diesel_ltree.patch @@ -20,7 +20,7 @@ index 255c6422..f2ccf5e2 100644 #[derive(diesel::sql_types::SqlType)] #[diesel(postgres_type(name = "sort_type_enum"))] @@ -76,13 +76,13 @@ diesel::table! { - published -> Timestamp, + published -> Timestamptz, } } diff --git a/crates/db_schema/src/impls/email_verification.rs b/crates/db_schema/src/impls/email_verification.rs index 59c5b9536..c5a8792fb 100644 --- a/crates/db_schema/src/impls/email_verification.rs +++ b/crates/db_schema/src/impls/email_verification.rs @@ -13,7 +13,9 @@ use diesel::{ dsl::{now, IntervalDsl}, insert_into, result::Error, + sql_types::Timestamptz, ExpressionMethods, + IntoSql, QueryDsl, }; use diesel_async::RunQueryDsl; @@ -31,7 +33,7 @@ impl EmailVerification { let conn = &mut get_conn(pool).await?; email_verification .filter(verification_token.eq(token)) - .filter(published.gt(now - 7.days())) + .filter(published.gt(now.into_sql::() - 7.days())) .first::(conn) .await } diff --git a/crates/db_schema/src/impls/instance.rs b/crates/db_schema/src/impls/instance.rs index 9bf3c28f5..acd4c1431 100644 --- a/crates/db_schema/src/impls/instance.rs +++ b/crates/db_schema/src/impls/instance.rs @@ -3,12 +3,12 @@ use crate::{ newtypes::InstanceId, schema::{federation_allowlist, federation_blocklist, instance, local_site, site}, source::instance::{Instance, InstanceForm}, - utils::{functions::lower, get_conn, naive_now, DbPool}, + utils::{functions::lower, get_conn, naive_now, now, DbPool}, }; use diesel::{ - dsl::{insert_into, now}, + dsl::insert_into, result::Error, - sql_types::{Nullable, Timestamp}, + sql_types::{Nullable, Timestamptz}, ExpressionMethods, QueryDsl, }; @@ -66,7 +66,7 @@ impl Instance { let conn = &mut get_conn(pool).await?; instance::table .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) .await } @@ -109,4 +109,4 @@ impl Instance { } } -sql_function! { fn coalesce(x: Nullable, y: Timestamp) -> Timestamp; } +sql_function! { fn coalesce(x: Nullable, y: Timestamptz) -> Timestamptz; } diff --git a/crates/db_schema/src/impls/password_reset_request.rs b/crates/db_schema/src/impls/password_reset_request.rs index a5a8fc494..5600ffc66 100644 --- a/crates/db_schema/src/impls/password_reset_request.rs +++ b/crates/db_schema/src/impls/password_reset_request.rs @@ -8,7 +8,9 @@ use crate::{ use diesel::{ dsl::{insert_into, now, IntervalDsl}, result::Error, + sql_types::Timestamptz, ExpressionMethods, + IntoSql, QueryDsl, }; use diesel_async::RunQueryDsl; @@ -59,7 +61,7 @@ impl PasswordResetRequest { let conn = &mut get_conn(pool).await?; password_reset_request .filter(token.eq(token_)) - .filter(published.gt(now - 1.days())) + .filter(published.gt(now.into_sql::() - 1.days())) .first::(conn) .await } @@ -71,7 +73,7 @@ impl PasswordResetRequest { let conn = &mut get_conn(pool).await?; password_reset_request .filter(local_user_id.eq(user_id)) - .filter(published.gt(now - 1.days())) + .filter(published.gt(now.into_sql::() - 1.days())) .count() .get_result(conn) .await diff --git a/crates/db_schema/src/impls/person.rs b/crates/db_schema/src/impls/person.rs index 6616970d8..723062aeb 100644 --- a/crates/db_schema/src/impls/person.rs +++ b/crates/db_schema/src/impls/person.rs @@ -11,6 +11,7 @@ use crate::{ traits::{ApubActor, Crud, Followable}, utils::{functions::lower, get_conn, naive_now, DbPool}, }; +use chrono::{DateTime, Utc}; use diesel::{dsl::insert_into, result::Error, ExpressionMethods, JoinOnDsl, QueryDsl}; use diesel_async::RunQueryDsl; @@ -89,7 +90,7 @@ impl Person { } } -pub fn is_banned(banned_: bool, expires: Option) -> bool { +pub fn is_banned(banned_: bool, expires: Option>) -> bool { if let Some(expires) = expires { banned_ && expires.gt(&naive_now()) } else { diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 77224f9fe..317a06250 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -20,7 +20,7 @@ diesel::table! { admin_person_id -> Int4, post_id -> Int4, reason -> Nullable, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -29,7 +29,7 @@ diesel::table! { id -> Int4, admin_person_id -> Int4, reason -> Nullable, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -38,7 +38,7 @@ diesel::table! { id -> Int4, admin_person_id -> Int4, reason -> Nullable, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -48,7 +48,7 @@ diesel::table! { admin_person_id -> Int4, community_id -> Int4, reason -> Nullable, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -57,7 +57,7 @@ diesel::table! { id -> Int4, uuid -> Uuid, answer -> Text, - published -> Timestamp, + published -> Timestamptz, } } @@ -71,8 +71,8 @@ diesel::table! { post_id -> Int4, content -> Text, removed -> Bool, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, deleted -> Bool, #[max_length = 255] ap_id -> Varchar, @@ -90,7 +90,7 @@ diesel::table! { score -> Int8, upvotes -> Int8, downvotes -> Int8, - published -> Timestamp, + published -> Timestamptz, child_count -> Int4, hot_rank -> Int4, controversy_rank -> Float8, @@ -104,7 +104,7 @@ diesel::table! { comment_id -> Int4, post_id -> Int4, score -> Int2, - published -> Timestamp, + published -> Timestamptz, } } @@ -114,7 +114,7 @@ diesel::table! { recipient_id -> Int4, comment_id -> Int4, read -> Bool, - published -> Timestamp, + published -> Timestamptz, } } @@ -127,8 +127,8 @@ diesel::table! { reason -> Text, resolved -> Bool, resolver_id -> Nullable, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -137,7 +137,7 @@ diesel::table! { id -> Int4, comment_id -> Int4, person_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -150,8 +150,8 @@ diesel::table! { title -> Varchar, description -> Nullable, removed -> Bool, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, deleted -> Bool, nsfw -> Bool, #[max_length = 255] @@ -159,7 +159,7 @@ diesel::table! { local -> Bool, private_key -> Nullable, public_key -> Text, - last_refreshed_at -> Timestamp, + last_refreshed_at -> Timestamptz, icon -> Nullable, banner -> Nullable, #[max_length = 255] @@ -185,7 +185,7 @@ diesel::table! { subscribers -> Int8, posts -> Int8, comments -> Int8, - published -> Timestamp, + published -> Timestamptz, users_active_day -> Int8, users_active_week -> Int8, users_active_month -> Int8, @@ -199,7 +199,7 @@ diesel::table! { id -> Int4, person_id -> Int4, community_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -208,7 +208,7 @@ diesel::table! { id -> Int4, community_id -> Int4, person_id -> Int4, - published -> Timestamp, + published -> Timestamptz, pending -> Bool, } } @@ -226,7 +226,7 @@ diesel::table! { id -> Int4, community_id -> Int4, person_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -235,8 +235,8 @@ diesel::table! { id -> Int4, community_id -> Int4, person_id -> Int4, - published -> Timestamp, - expires -> Nullable, + published -> Timestamptz, + expires -> Nullable, } } @@ -249,8 +249,8 @@ diesel::table! { image_url -> Text, alt_text -> Text, category -> Text, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -269,7 +269,7 @@ diesel::table! { local_user_id -> Int4, email -> Text, verification_token -> Text, - published -> Timestamp, + published -> Timestamptz, } } @@ -277,8 +277,8 @@ diesel::table! { federation_allowlist (id) { id -> Int4, instance_id -> Int4, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -286,8 +286,8 @@ diesel::table! { federation_blocklist (id) { id -> Int4, instance_id -> Int4, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -296,8 +296,8 @@ diesel::table! { id -> Int4, #[max_length = 255] domain -> Varchar, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, #[max_length = 255] software -> Nullable, #[max_length = 255] @@ -340,8 +340,8 @@ diesel::table! { captcha_enabled -> Bool, #[max_length = 255] captcha_difficulty -> Varchar, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, registration_mode -> RegistrationModeEnum, reports_email_admins -> Bool, } @@ -363,8 +363,8 @@ diesel::table! { comment_per_second -> Int4, search -> Int4, search_per_second -> Int4, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -386,7 +386,7 @@ diesel::table! { interface_language -> Varchar, show_avatars -> Bool, send_notifications_to_email -> Bool, - validator_time -> Timestamp, + validator_time -> Timestamptz, show_scores -> Bool, show_bot_accounts -> Bool, show_read_posts -> Bool, @@ -396,9 +396,9 @@ diesel::table! { totp_2fa_secret -> Nullable, totp_2fa_url -> Nullable, open_links_in_new_tab -> Bool, - infinite_scroll_enabled -> Bool, blur_nsfw -> Bool, auto_expand -> Bool, + infinite_scroll_enabled -> Bool, admin -> Bool, } } @@ -417,7 +417,7 @@ diesel::table! { mod_person_id -> Int4, other_person_id -> Int4, removed -> Bool, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -428,7 +428,7 @@ diesel::table! { other_person_id -> Int4, community_id -> Int4, removed -> Bool, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -439,8 +439,8 @@ diesel::table! { other_person_id -> Int4, reason -> Nullable, banned -> Bool, - expires -> Nullable, - when_ -> Timestamp, + expires -> Nullable, + when_ -> Timestamptz, } } @@ -452,8 +452,8 @@ diesel::table! { community_id -> Int4, reason -> Nullable, banned -> Bool, - expires -> Nullable, - when_ -> Timestamp, + expires -> Nullable, + when_ -> Timestamptz, } } @@ -463,7 +463,7 @@ diesel::table! { mod_person_id -> Int4, post_id -> Int4, featured -> Bool, - when_ -> Timestamp, + when_ -> Timestamptz, is_featured_community -> Bool, } } @@ -473,7 +473,7 @@ diesel::table! { id -> Int4, community_id -> Int4, mod_person_id -> Int4, - when_ -> Timestamp, + when_ -> Timestamptz, reason -> Nullable, hidden -> Bool, } @@ -485,7 +485,7 @@ diesel::table! { mod_person_id -> Int4, post_id -> Int4, locked -> Bool, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -496,7 +496,7 @@ diesel::table! { comment_id -> Int4, reason -> Nullable, removed -> Bool, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -507,8 +507,8 @@ diesel::table! { community_id -> Int4, reason -> Nullable, removed -> Bool, - expires -> Nullable, - when_ -> Timestamp, + expires -> Nullable, + when_ -> Timestamptz, } } @@ -519,7 +519,7 @@ diesel::table! { post_id -> Int4, reason -> Nullable, removed -> Bool, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -529,7 +529,7 @@ diesel::table! { mod_person_id -> Int4, other_person_id -> Int4, community_id -> Int4, - when_ -> Timestamp, + when_ -> Timestamptz, } } @@ -537,7 +537,7 @@ diesel::table! { password_reset_request (id) { id -> Int4, token -> Text, - published -> Timestamp, + published -> Timestamptz, local_user_id -> Int4, } } @@ -551,15 +551,15 @@ diesel::table! { display_name -> Nullable, avatar -> Nullable, banned -> Bool, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, #[max_length = 255] actor_id -> Varchar, bio -> Nullable, local -> Bool, private_key -> Nullable, public_key -> Text, - last_refreshed_at -> Timestamp, + last_refreshed_at -> Timestamptz, banner -> Nullable, deleted -> Bool, #[max_length = 255] @@ -568,7 +568,7 @@ diesel::table! { shared_inbox_url -> Nullable, matrix_user_id -> Nullable, bot_account -> Bool, - ban_expires -> Nullable, + ban_expires -> Nullable, instance_id -> Int4, } } @@ -588,7 +588,7 @@ diesel::table! { person_ban (id) { id -> Int4, person_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -597,7 +597,7 @@ diesel::table! { id -> Int4, person_id -> Int4, target_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -606,7 +606,7 @@ diesel::table! { id -> Int4, person_id -> Int4, follower_id -> Int4, - published -> Timestamp, + published -> Timestamptz, pending -> Bool, } } @@ -617,7 +617,7 @@ diesel::table! { recipient_id -> Int4, comment_id -> Int4, read -> Bool, - published -> Timestamp, + published -> Timestamptz, } } @@ -627,7 +627,7 @@ diesel::table! { person_id -> Int4, post_id -> Int4, read_comments -> Int8, - published -> Timestamp, + published -> Timestamptz, } } @@ -643,8 +643,8 @@ diesel::table! { community_id -> Int4, removed -> Bool, locked -> Bool, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, deleted -> Bool, nsfw -> Bool, embed_title -> Nullable, @@ -668,9 +668,9 @@ diesel::table! { score -> Int8, upvotes -> Int8, downvotes -> Int8, - published -> Timestamp, - newest_comment_time_necro -> Timestamp, - newest_comment_time -> Timestamp, + published -> Timestamptz, + newest_comment_time_necro -> Timestamptz, + newest_comment_time -> Timestamptz, featured_community -> Bool, featured_local -> Bool, hot_rank -> Int4, @@ -687,7 +687,7 @@ diesel::table! { post_id -> Int4, person_id -> Int4, score -> Int2, - published -> Timestamp, + published -> Timestamptz, } } @@ -696,7 +696,7 @@ diesel::table! { id -> Int4, post_id -> Int4, person_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -712,8 +712,8 @@ diesel::table! { reason -> Text, resolved -> Bool, resolver_id -> Nullable, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -722,7 +722,7 @@ diesel::table! { id -> Int4, post_id -> Int4, person_id -> Int4, - published -> Timestamp, + published -> Timestamptz, } } @@ -734,8 +734,8 @@ diesel::table! { content -> Text, deleted -> Bool, read -> Bool, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, #[max_length = 255] ap_id -> Varchar, local -> Bool, @@ -751,8 +751,8 @@ diesel::table! { reason -> Text, resolved -> Bool, resolver_id -> Nullable, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } @@ -760,7 +760,7 @@ diesel::table! { received_activity (id) { id -> Int8, ap_id -> Text, - published -> Timestamp, + published -> Timestamptz, } } @@ -771,7 +771,7 @@ diesel::table! { answer -> Text, admin_id -> Nullable, deny_reason -> Nullable, - published -> Timestamp, + published -> Timestamptz, } } @@ -788,7 +788,7 @@ diesel::table! { ap_id -> Text, data -> Json, sensitive -> Bool, - published -> Timestamp, + published -> Timestamptz, } } @@ -798,15 +798,15 @@ diesel::table! { #[max_length = 20] name -> Varchar, sidebar -> Nullable, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, icon -> Nullable, banner -> Nullable, #[max_length = 150] description -> Nullable, #[max_length = 255] actor_id -> Varchar, - last_refreshed_at -> Timestamp, + last_refreshed_at -> Timestamptz, #[max_length = 255] inbox_url -> Varchar, private_key -> Nullable, @@ -843,8 +843,8 @@ diesel::table! { id -> Int4, local_site_id -> Int4, content -> Text, - published -> Timestamp, - updated -> Nullable, + published -> Timestamptz, + updated -> Nullable, } } diff --git a/crates/db_schema/src/source/activity.rs b/crates/db_schema/src/source/activity.rs index 85b193f51..eafb75ad2 100644 --- a/crates/db_schema/src/source/activity.rs +++ b/crates/db_schema/src/source/activity.rs @@ -1,4 +1,5 @@ use crate::{newtypes::DbUrl, schema::sent_activity}; +use chrono::{DateTime, Utc}; use serde_json::Value; use std::fmt::Debug; @@ -9,7 +10,7 @@ pub struct SentActivity { pub ap_id: DbUrl, pub data: Value, pub sensitive: bool, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[derive(Insertable)] #[diesel(table_name = sent_activity)] @@ -24,5 +25,5 @@ pub struct SentActivityForm { pub struct ReceivedActivity { pub id: i64, pub ap_id: DbUrl, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } diff --git a/crates/db_schema/src/source/captcha_answer.rs b/crates/db_schema/src/source/captcha_answer.rs index e3e64c4eb..b7e9636c4 100644 --- a/crates/db_schema/src/source/captcha_answer.rs +++ b/crates/db_schema/src/source/captcha_answer.rs @@ -1,5 +1,6 @@ #[cfg(feature = "full")] use crate::schema::captcha_answer; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use uuid::Uuid; @@ -12,7 +13,7 @@ pub struct CaptchaAnswer { pub id: i32, pub uuid: Uuid, pub answer: String, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[skip_serializing_none] diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index f76e2fba7..efe3b7cdf 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -3,6 +3,7 @@ use crate::newtypes::LtreeDef; use crate::newtypes::{CommentId, DbUrl, LanguageId, PersonId, PostId}; #[cfg(feature = "full")] use crate::schema::{comment, comment_like, comment_saved}; +use chrono::{DateTime, Utc}; #[cfg(feature = "full")] use diesel_ltree::Ltree; use serde::{Deserialize, Serialize}; @@ -25,8 +26,8 @@ pub struct Comment { pub content: String, /// Whether the comment has been removed. pub removed: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, /// Whether the comment has been deleted by its creator. pub deleted: bool, /// The federated activity id / ap_id. @@ -57,8 +58,8 @@ pub struct CommentInsertForm { #[builder(!default)] pub content: String, pub removed: Option, - pub published: Option, - pub updated: Option, + pub published: Option>, + pub updated: Option>, pub deleted: Option, pub ap_id: Option, pub local: Option, @@ -73,7 +74,7 @@ pub struct CommentUpdateForm { pub content: Option, pub removed: Option, // Don't use a default naive_now here, because the create function does a lot of comment updates - pub updated: Option>, + pub updated: Option>>, pub deleted: Option, pub ap_id: Option, pub local: Option, @@ -91,7 +92,7 @@ pub struct CommentLike { pub comment_id: CommentId, pub post_id: PostId, // TODO this is redundant pub score: i16, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[derive(Clone)] @@ -112,7 +113,7 @@ pub struct CommentSaved { pub id: i32, pub comment_id: CommentId, pub person_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/comment_reply.rs b/crates/db_schema/src/source/comment_reply.rs index 63c79ae27..30d4ae919 100644 --- a/crates/db_schema/src/source/comment_reply.rs +++ b/crates/db_schema/src/source/comment_reply.rs @@ -1,6 +1,7 @@ use crate::newtypes::{CommentId, CommentReplyId, PersonId}; #[cfg(feature = "full")] use crate::schema::comment_reply; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] use ts_rs::TS; @@ -16,7 +17,7 @@ pub struct CommentReply { pub recipient_id: PersonId, pub comment_id: CommentId, pub read: bool, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/comment_report.rs b/crates/db_schema/src/source/comment_report.rs index 1483cd812..23697adce 100644 --- a/crates/db_schema/src/source/comment_report.rs +++ b/crates/db_schema/src/source/comment_report.rs @@ -1,6 +1,7 @@ use crate::newtypes::{CommentId, CommentReportId, PersonId}; #[cfg(feature = "full")] use crate::schema::comment_report; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -21,8 +22,8 @@ pub struct CommentReport { pub reason: String, pub resolved: bool, pub resolver_id: Option, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone)] diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index 5d56c36a5..c00a065a6 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -4,6 +4,7 @@ use crate::{ newtypes::{CommunityId, DbUrl, InstanceId, PersonId}, source::placeholder_apub_url, }; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -25,8 +26,8 @@ pub struct Community { pub description: Option, /// Whether the community is removed by a mod. pub removed: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, /// Whether the community has been deleted by its creator. pub deleted: bool, /// Whether its an NSFW community. @@ -40,7 +41,7 @@ pub struct Community { #[serde(skip)] pub public_key: String, #[serde(skip)] - pub last_refreshed_at: chrono::NaiveDateTime, + pub last_refreshed_at: DateTime, /// A URL for an icon. pub icon: Option, /// A URL for a banner. @@ -75,15 +76,15 @@ pub struct CommunityInsertForm { pub title: String, pub description: Option, pub removed: Option, - pub published: Option, - pub updated: Option, + pub published: Option>, + pub updated: Option>, pub deleted: Option, pub nsfw: Option, pub actor_id: Option, pub local: Option, pub private_key: Option, pub public_key: String, - pub last_refreshed_at: Option, + pub last_refreshed_at: Option>, pub icon: Option, pub banner: Option, pub followers_url: Option, @@ -104,15 +105,15 @@ pub struct CommunityUpdateForm { pub title: Option, pub description: Option>, pub removed: Option, - pub published: Option, - pub updated: Option>, + pub published: Option>, + pub updated: Option>>, pub deleted: Option, pub nsfw: Option, pub actor_id: Option, pub local: Option, pub public_key: Option, pub private_key: Option>, - pub last_refreshed_at: Option, + pub last_refreshed_at: Option>, pub icon: Option>, pub banner: Option>, pub followers_url: Option, @@ -135,7 +136,7 @@ pub struct CommunityModerator { pub id: i32, pub community_id: CommunityId, pub person_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[derive(Clone)] @@ -157,8 +158,8 @@ pub struct CommunityPersonBan { pub id: i32, pub community_id: CommunityId, pub person_id: PersonId, - pub published: chrono::NaiveDateTime, - pub expires: Option, + pub published: DateTime, + pub expires: Option>, } #[derive(Clone)] @@ -167,7 +168,7 @@ pub struct CommunityPersonBan { pub struct CommunityPersonBanForm { pub community_id: CommunityId, pub person_id: PersonId, - pub expires: Option>, + pub expires: Option>>, } #[derive(PartialEq, Eq, Debug)] @@ -181,7 +182,7 @@ pub struct CommunityFollower { pub id: i32, pub community_id: CommunityId, pub person_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, pub pending: bool, } diff --git a/crates/db_schema/src/source/community_block.rs b/crates/db_schema/src/source/community_block.rs index 3efdce4f2..628e77ade 100644 --- a/crates/db_schema/src/source/community_block.rs +++ b/crates/db_schema/src/source/community_block.rs @@ -1,6 +1,7 @@ use crate::newtypes::{CommunityBlockId, CommunityId, PersonId}; #[cfg(feature = "full")] use crate::schema::community_block; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -14,7 +15,7 @@ pub struct CommunityBlock { pub id: CommunityBlockId, pub person_id: PersonId, pub community_id: CommunityId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/custom_emoji.rs b/crates/db_schema/src/source/custom_emoji.rs index 5f8060e71..015004cae 100644 --- a/crates/db_schema/src/source/custom_emoji.rs +++ b/crates/db_schema/src/source/custom_emoji.rs @@ -1,6 +1,7 @@ use crate::newtypes::{CustomEmojiId, DbUrl, LocalSiteId}; #[cfg(feature = "full")] use crate::schema::custom_emoji; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -24,8 +25,8 @@ pub struct CustomEmoji { pub image_url: DbUrl, pub alt_text: String, pub category: String, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Debug, Clone, TypedBuilder)] diff --git a/crates/db_schema/src/source/email_verification.rs b/crates/db_schema/src/source/email_verification.rs index 0ee5b47d0..af117e0bd 100644 --- a/crates/db_schema/src/source/email_verification.rs +++ b/crates/db_schema/src/source/email_verification.rs @@ -1,6 +1,7 @@ use crate::newtypes::LocalUserId; #[cfg(feature = "full")] use crate::schema::email_verification; +use chrono::{DateTime, Utc}; #[derive(Clone)] #[cfg_attr(feature = "full", derive(Queryable, Identifiable))] @@ -10,7 +11,7 @@ pub struct EmailVerification { pub local_user_id: LocalUserId, pub email: String, pub verification_code: String, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/federation_allowlist.rs b/crates/db_schema/src/source/federation_allowlist.rs index 309e24e36..534e1b02e 100644 --- a/crates/db_schema/src/source/federation_allowlist.rs +++ b/crates/db_schema/src/source/federation_allowlist.rs @@ -1,6 +1,7 @@ use crate::newtypes::InstanceId; #[cfg(feature = "full")] use crate::schema::federation_allowlist; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; @@ -14,8 +15,8 @@ use std::fmt::Debug; pub struct FederationAllowList { pub id: i32, pub instance_id: InstanceId, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone, Default)] @@ -23,5 +24,5 @@ pub struct FederationAllowList { #[cfg_attr(feature = "full", diesel(table_name = federation_allowlist))] pub struct FederationAllowListForm { pub instance_id: InstanceId, - pub updated: Option, + pub updated: Option>, } diff --git a/crates/db_schema/src/source/federation_blocklist.rs b/crates/db_schema/src/source/federation_blocklist.rs index 2ee5ec0f0..0cf615d7b 100644 --- a/crates/db_schema/src/source/federation_blocklist.rs +++ b/crates/db_schema/src/source/federation_blocklist.rs @@ -1,6 +1,7 @@ use crate::newtypes::InstanceId; #[cfg(feature = "full")] use crate::schema::federation_blocklist; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; @@ -14,8 +15,8 @@ use std::fmt::Debug; pub struct FederationBlockList { pub id: i32, pub instance_id: InstanceId, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone, Default)] @@ -23,5 +24,5 @@ pub struct FederationBlockList { #[cfg_attr(feature = "full", diesel(table_name = federation_blocklist))] pub struct FederationBlockListForm { pub instance_id: InstanceId, - pub updated: Option, + pub updated: Option>, } diff --git a/crates/db_schema/src/source/instance.rs b/crates/db_schema/src/source/instance.rs index a75259c15..a887ae32f 100644 --- a/crates/db_schema/src/source/instance.rs +++ b/crates/db_schema/src/source/instance.rs @@ -1,6 +1,7 @@ use crate::newtypes::InstanceId; #[cfg(feature = "full")] use crate::schema::instance; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; use std::fmt::Debug; @@ -17,8 +18,8 @@ use typed_builder::TypedBuilder; pub struct Instance { pub id: InstanceId, pub domain: String, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, pub software: Option, pub version: Option, } @@ -32,5 +33,5 @@ pub struct InstanceForm { pub domain: String, pub software: Option, pub version: Option, - pub updated: Option, + pub updated: Option>, } diff --git a/crates/db_schema/src/source/local_site.rs b/crates/db_schema/src/source/local_site.rs index a57bf503c..e5945e86f 100644 --- a/crates/db_schema/src/source/local_site.rs +++ b/crates/db_schema/src/source/local_site.rs @@ -5,6 +5,7 @@ use crate::{ ListingType, RegistrationMode, }; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -54,8 +55,8 @@ pub struct LocalSite { pub captcha_enabled: bool, /// The captcha difficulty. pub captcha_difficulty: String, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, pub registration_mode: RegistrationMode, /// Whether to email admins on new reports. pub reports_email_admins: bool, @@ -112,5 +113,5 @@ pub struct LocalSiteUpdateForm { pub captcha_difficulty: Option, pub registration_mode: Option, pub reports_email_admins: Option, - pub updated: Option>, + pub updated: Option>>, } diff --git a/crates/db_schema/src/source/local_site_rate_limit.rs b/crates/db_schema/src/source/local_site_rate_limit.rs index ab14bfd83..b16d4e134 100644 --- a/crates/db_schema/src/source/local_site_rate_limit.rs +++ b/crates/db_schema/src/source/local_site_rate_limit.rs @@ -1,6 +1,7 @@ use crate::newtypes::LocalSiteId; #[cfg(feature = "full")] use crate::schema::local_site_rate_limit; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -32,8 +33,8 @@ pub struct LocalSiteRateLimit { pub comment_per_second: i32, pub search: i32, pub search_per_second: i32, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone, TypedBuilder)] @@ -73,5 +74,5 @@ pub struct LocalSiteRateLimitUpdateForm { pub comment_per_second: Option, pub search: Option, pub search_per_second: Option, - pub updated: Option>, + pub updated: Option>>, } diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index d9e03c35f..8440531c6 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -5,6 +5,7 @@ use crate::{ ListingType, SortType, }; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -34,7 +35,7 @@ pub struct LocalUser { pub show_avatars: bool, pub send_notifications_to_email: bool, /// A validation ID used in logging out sessions. - pub validator_time: chrono::NaiveDateTime, + pub validator_time: DateTime, /// Whether to show comment / post scores. pub show_scores: bool, /// Whether to show bot accounts. diff --git a/crates/db_schema/src/source/moderator.rs b/crates/db_schema/src/source/moderator.rs index 63049de2b..7e2ff2867 100644 --- a/crates/db_schema/src/source/moderator.rs +++ b/crates/db_schema/src/source/moderator.rs @@ -17,6 +17,7 @@ use crate::schema::{ mod_remove_post, mod_transfer_community, }; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -34,7 +35,7 @@ pub struct ModRemovePost { pub post_id: PostId, pub reason: Option, pub removed: bool, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -56,7 +57,7 @@ pub struct ModLockPost { pub mod_person_id: PersonId, pub post_id: PostId, pub locked: bool, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -77,7 +78,7 @@ pub struct ModFeaturePost { pub mod_person_id: PersonId, pub post_id: PostId, pub featured: bool, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, pub is_featured_community: bool, } @@ -102,7 +103,7 @@ pub struct ModRemoveComment { pub comment_id: CommentId, pub reason: Option, pub removed: bool, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -126,8 +127,8 @@ pub struct ModRemoveCommunity { pub community_id: CommunityId, pub reason: Option, pub removed: bool, - pub expires: Option, - pub when_: chrono::NaiveDateTime, + pub expires: Option>, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -137,7 +138,7 @@ pub struct ModRemoveCommunityForm { pub community_id: CommunityId, pub reason: Option, pub removed: Option, - pub expires: Option, + pub expires: Option>, } #[skip_serializing_none] @@ -153,8 +154,8 @@ pub struct ModBanFromCommunity { pub community_id: CommunityId, pub reason: Option, pub banned: bool, - pub expires: Option, - pub when_: chrono::NaiveDateTime, + pub expires: Option>, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -165,7 +166,7 @@ pub struct ModBanFromCommunityForm { pub community_id: CommunityId, pub reason: Option, pub banned: Option, - pub expires: Option, + pub expires: Option>, } #[skip_serializing_none] @@ -180,8 +181,8 @@ pub struct ModBan { pub other_person_id: PersonId, pub reason: Option, pub banned: bool, - pub expires: Option, - pub when_: chrono::NaiveDateTime, + pub expires: Option>, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -203,7 +204,7 @@ pub struct ModHideCommunity { pub id: i32, pub community_id: CommunityId, pub mod_person_id: PersonId, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, pub reason: Option, pub hidden: bool, } @@ -215,7 +216,7 @@ pub struct ModBanForm { pub other_person_id: PersonId, pub reason: Option, pub banned: Option, - pub expires: Option, + pub expires: Option>, } #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -229,7 +230,7 @@ pub struct ModAddCommunity { pub other_person_id: PersonId, pub community_id: CommunityId, pub removed: bool, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -251,7 +252,7 @@ pub struct ModTransferCommunity { pub mod_person_id: PersonId, pub other_person_id: PersonId, pub community_id: CommunityId, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -272,7 +273,7 @@ pub struct ModAdd { pub mod_person_id: PersonId, pub other_person_id: PersonId, pub removed: bool, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -293,7 +294,7 @@ pub struct AdminPurgePerson { pub id: i32, pub admin_person_id: PersonId, pub reason: Option, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -313,7 +314,7 @@ pub struct AdminPurgeCommunity { pub id: i32, pub admin_person_id: PersonId, pub reason: Option, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -334,7 +335,7 @@ pub struct AdminPurgePost { pub admin_person_id: PersonId, pub community_id: CommunityId, pub reason: Option, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -356,7 +357,7 @@ pub struct AdminPurgeComment { pub admin_person_id: PersonId, pub post_id: PostId, pub reason: Option, - pub when_: chrono::NaiveDateTime, + pub when_: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/password_reset_request.rs b/crates/db_schema/src/source/password_reset_request.rs index 6e1b572d3..648c7164c 100644 --- a/crates/db_schema/src/source/password_reset_request.rs +++ b/crates/db_schema/src/source/password_reset_request.rs @@ -1,6 +1,7 @@ use crate::newtypes::LocalUserId; #[cfg(feature = "full")] use crate::schema::password_reset_request; +use chrono::{DateTime, Utc}; #[derive(PartialEq, Eq, Debug)] #[cfg_attr(feature = "full", derive(Queryable, Identifiable))] @@ -8,7 +9,7 @@ use crate::schema::password_reset_request; pub struct PasswordResetRequest { pub id: i32, pub token: String, - pub published: chrono::NaiveDateTime, + pub published: DateTime, pub local_user_id: LocalUserId, } diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index 9ff3972d4..339ce5adf 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -4,6 +4,7 @@ use crate::{ newtypes::{DbUrl, InstanceId, PersonId}, source::placeholder_apub_url, }; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -25,8 +26,8 @@ pub struct Person { pub avatar: Option, /// Whether the person is banned. pub banned: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, /// The federated actor_id. pub actor_id: DbUrl, /// An optional bio, in markdown. @@ -38,7 +39,7 @@ pub struct Person { #[serde(skip)] pub public_key: String, #[serde(skip)] - pub last_refreshed_at: chrono::NaiveDateTime, + pub last_refreshed_at: DateTime, /// A URL for a banner. pub banner: Option, /// Whether the person is deleted. @@ -52,7 +53,7 @@ pub struct Person { /// Whether the person is a bot account. pub bot_account: bool, /// When their ban, if it exists, expires, if at all. - pub ban_expires: Option, + pub ban_expires: Option>, pub instance_id: InstanceId, } @@ -70,20 +71,20 @@ pub struct PersonInsertForm { pub display_name: Option, pub avatar: Option, pub banned: Option, - pub published: Option, - pub updated: Option, + pub published: Option>, + pub updated: Option>, pub actor_id: Option, pub bio: Option, pub local: Option, pub private_key: Option, - pub last_refreshed_at: Option, + pub last_refreshed_at: Option>, pub banner: Option, pub deleted: Option, pub inbox_url: Option, pub shared_inbox_url: Option, pub matrix_user_id: Option, pub bot_account: Option, - pub ban_expires: Option, + pub ban_expires: Option>, } #[derive(Clone, Default)] @@ -93,20 +94,20 @@ pub struct PersonUpdateForm { pub display_name: Option>, pub avatar: Option>, pub banned: Option, - pub updated: Option>, + pub updated: Option>>, pub actor_id: Option, pub bio: Option>, pub local: Option, pub public_key: Option, pub private_key: Option>, - pub last_refreshed_at: Option, + pub last_refreshed_at: Option>, pub banner: Option>, pub deleted: Option, pub inbox_url: Option, pub shared_inbox_url: Option>, pub matrix_user_id: Option>, pub bot_account: Option, - pub ban_expires: Option>, + pub ban_expires: Option>>, } #[derive(PartialEq, Eq, Debug)] @@ -117,7 +118,7 @@ pub struct PersonFollower { pub id: i32, pub person_id: PersonId, pub follower_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, pub pending: bool, } diff --git a/crates/db_schema/src/source/person_block.rs b/crates/db_schema/src/source/person_block.rs index f9bd6e565..3380fbfc3 100644 --- a/crates/db_schema/src/source/person_block.rs +++ b/crates/db_schema/src/source/person_block.rs @@ -1,6 +1,7 @@ use crate::newtypes::{PersonBlockId, PersonId}; #[cfg(feature = "full")] use crate::schema::person_block; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] @@ -11,7 +12,7 @@ pub struct PersonBlock { pub id: PersonBlockId, pub person_id: PersonId, pub target_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/person_mention.rs b/crates/db_schema/src/source/person_mention.rs index 5b7732c6d..b9d7ccf8e 100644 --- a/crates/db_schema/src/source/person_mention.rs +++ b/crates/db_schema/src/source/person_mention.rs @@ -1,6 +1,7 @@ use crate::newtypes::{CommentId, PersonId, PersonMentionId}; #[cfg(feature = "full")] use crate::schema::person_mention; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] use ts_rs::TS; @@ -16,7 +17,7 @@ pub struct PersonMention { pub recipient_id: PersonId, pub comment_id: CommentId, pub read: bool, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index de56f1187..4fe8e34c6 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -1,6 +1,7 @@ use crate::newtypes::{CommunityId, DbUrl, LanguageId, PersonId, PostId}; #[cfg(feature = "full")] use crate::schema::{post, post_like, post_read, post_saved}; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -27,8 +28,8 @@ pub struct Post { pub removed: bool, /// Whether the post is locked. pub locked: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, /// Whether the post is deleted. pub deleted: bool, /// Whether the post is NSFW. @@ -71,8 +72,8 @@ pub struct PostInsertForm { pub body: Option, pub removed: Option, pub locked: Option, - pub updated: Option, - pub published: Option, + pub updated: Option>, + pub published: Option>, pub deleted: Option, pub embed_title: Option, pub embed_description: Option, @@ -95,8 +96,8 @@ pub struct PostUpdateForm { pub body: Option>, pub removed: Option, pub locked: Option, - pub published: Option, - pub updated: Option>, + pub published: Option>, + pub updated: Option>>, pub deleted: Option, pub embed_title: Option>, pub embed_description: Option>, @@ -118,7 +119,7 @@ pub struct PostLike { pub post_id: PostId, pub person_id: PersonId, pub score: i16, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[derive(Clone)] @@ -138,7 +139,7 @@ pub struct PostSaved { pub id: i32, pub post_id: PostId, pub person_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] @@ -156,7 +157,7 @@ pub struct PostRead { pub id: i32, pub post_id: PostId, pub person_id: PersonId, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] diff --git a/crates/db_schema/src/source/post_report.rs b/crates/db_schema/src/source/post_report.rs index 74e418670..9f5f53d95 100644 --- a/crates/db_schema/src/source/post_report.rs +++ b/crates/db_schema/src/source/post_report.rs @@ -1,6 +1,7 @@ use crate::newtypes::{DbUrl, PersonId, PostId, PostReportId}; #[cfg(feature = "full")] use crate::schema::post_report; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -26,8 +27,8 @@ pub struct PostReport { pub reason: String, pub resolved: bool, pub resolver_id: Option, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone, Default)] diff --git a/crates/db_schema/src/source/private_message.rs b/crates/db_schema/src/source/private_message.rs index bd8c73e30..033bfbe20 100644 --- a/crates/db_schema/src/source/private_message.rs +++ b/crates/db_schema/src/source/private_message.rs @@ -1,6 +1,7 @@ use crate::newtypes::{DbUrl, PersonId, PrivateMessageId}; #[cfg(feature = "full")] use crate::schema::private_message; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -24,8 +25,8 @@ pub struct PrivateMessage { pub content: String, pub deleted: bool, pub read: bool, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, pub ap_id: DbUrl, pub local: bool, } @@ -43,8 +44,8 @@ pub struct PrivateMessageInsertForm { pub content: String, pub deleted: Option, pub read: Option, - pub published: Option, - pub updated: Option, + pub published: Option>, + pub updated: Option>, pub ap_id: Option, pub local: Option, } @@ -56,8 +57,8 @@ pub struct PrivateMessageUpdateForm { pub content: Option, pub deleted: Option, pub read: Option, - pub published: Option, - pub updated: Option>, + pub published: Option>, + pub updated: Option>>, pub ap_id: Option, pub local: Option, } diff --git a/crates/db_schema/src/source/private_message_report.rs b/crates/db_schema/src/source/private_message_report.rs index a9ee8998b..0afc5b039 100644 --- a/crates/db_schema/src/source/private_message_report.rs +++ b/crates/db_schema/src/source/private_message_report.rs @@ -1,6 +1,7 @@ use crate::newtypes::{PersonId, PrivateMessageId, PrivateMessageReportId}; #[cfg(feature = "full")] use crate::schema::private_message_report; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -25,8 +26,8 @@ pub struct PrivateMessageReport { pub reason: String, pub resolved: bool, pub resolver_id: Option, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone)] diff --git a/crates/db_schema/src/source/registration_application.rs b/crates/db_schema/src/source/registration_application.rs index f57e6883d..1ed78703b 100644 --- a/crates/db_schema/src/source/registration_application.rs +++ b/crates/db_schema/src/source/registration_application.rs @@ -1,6 +1,7 @@ use crate::newtypes::{LocalUserId, PersonId}; #[cfg(feature = "full")] use crate::schema::registration_application; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -18,7 +19,7 @@ pub struct RegistrationApplication { pub answer: String, pub admin_id: Option, pub deny_reason: Option, - pub published: chrono::NaiveDateTime, + pub published: DateTime, } #[cfg_attr(feature = "full", derive(Insertable))] diff --git a/crates/db_schema/src/source/site.rs b/crates/db_schema/src/source/site.rs index e45ece706..0e175dc71 100644 --- a/crates/db_schema/src/source/site.rs +++ b/crates/db_schema/src/source/site.rs @@ -1,7 +1,7 @@ use crate::newtypes::{DbUrl, InstanceId, SiteId}; #[cfg(feature = "full")] use crate::schema::site; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -19,8 +19,8 @@ pub struct Site { pub name: String, /// A sidebar for the site in markdown. pub sidebar: Option, - pub published: NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, /// An icon URL. pub icon: Option, /// A banner url. @@ -30,7 +30,7 @@ pub struct Site { /// The federated actor_id. pub actor_id: DbUrl, /// The time the site was last refreshed. - pub last_refreshed_at: NaiveDateTime, + pub last_refreshed_at: DateTime, /// The site inbox pub inbox_url: DbUrl, pub private_key: Option, @@ -46,12 +46,12 @@ pub struct SiteInsertForm { #[builder(!default)] pub name: String, pub sidebar: Option, - pub updated: Option, + pub updated: Option>, pub icon: Option, pub banner: Option, pub description: Option, pub actor_id: Option, - pub last_refreshed_at: Option, + pub last_refreshed_at: Option>, pub inbox_url: Option, pub private_key: Option, pub public_key: Option, @@ -65,13 +65,13 @@ pub struct SiteInsertForm { pub struct SiteUpdateForm { pub name: Option, pub sidebar: Option>, - pub updated: Option>, + pub updated: Option>>, // 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>, pub banner: Option>, pub description: Option>, pub actor_id: Option, - pub last_refreshed_at: Option, + pub last_refreshed_at: Option>, pub inbox_url: Option, pub private_key: Option>, pub public_key: Option, diff --git a/crates/db_schema/src/source/tagline.rs b/crates/db_schema/src/source/tagline.rs index 114e7f5bd..564c6dc80 100644 --- a/crates/db_schema/src/source/tagline.rs +++ b/crates/db_schema/src/source/tagline.rs @@ -1,6 +1,7 @@ use crate::newtypes::LocalSiteId; #[cfg(feature = "full")] use crate::schema::tagline; +use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] @@ -20,8 +21,8 @@ pub struct Tagline { pub id: i32, pub local_site_id: LocalSiteId, pub content: String, - pub published: chrono::NaiveDateTime, - pub updated: Option, + pub published: DateTime, + pub updated: Option>, } #[derive(Clone, Default)] @@ -30,5 +31,5 @@ pub struct Tagline { pub struct TaglineForm { pub local_site_id: LocalSiteId, pub content: String, - pub updated: Option, + pub updated: Option>, } diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index dc26bedfc..2fbfec6c6 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -8,15 +8,17 @@ use crate::{ SortType, }; use activitypub_federation::{fetch::object_id::ObjectId, traits::Object}; -use chrono::NaiveDateTime; +use chrono::{DateTime, Utc}; use deadpool::Runtime; use diesel::{ backend::Backend, deserialize::FromSql, + helper_types::AsExprOf, pg::Pg, result::{ConnectionError, ConnectionResult, Error as DieselError, Error::QueryBuilderError}, serialize::{Output, ToSql}, - sql_types::Text, + sql_types::{Text, Timestamptz}, + IntoSql, PgConnection, }; use diesel_async::{ @@ -340,8 +342,8 @@ pub fn get_database_url(settings: Option<&Settings>) -> String { } } -pub fn naive_now() -> NaiveDateTime { - chrono::prelude::Utc::now().naive_utc() +pub fn naive_now() -> DateTime { + chrono::prelude::Utc::now() } pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType { @@ -380,10 +382,10 @@ static EMAIL_REGEX: Lazy = Lazy::new(|| { }); pub mod functions { - use diesel::sql_types::{BigInt, Text, Timestamp}; + use diesel::sql_types::{BigInt, Text, Timestamptz}; sql_function! { - fn hot_rank(score: BigInt, time: Timestamp) -> Integer; + fn hot_rank(score: BigInt, time: Timestamptz) -> Integer; } sql_function! { @@ -421,6 +423,11 @@ where } } +pub fn now() -> AsExprOf { + // https://github.com/diesel-rs/diesel/issues/1514 + diesel::dsl::now.into_sql::() +} + pub type ResultFuture<'a, T> = BoxFuture<'a, Result>; pub trait ReadFn<'a, T: JoinView, Args>: diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index f859a6ad9..e2a0672c6 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -1,13 +1,14 @@ use crate::structs::{LocalUserView, PostView}; use diesel::{ debug_query, - dsl::{now, IntervalDsl}, + dsl::IntervalDsl, pg::Pg, result::Error, sql_function, - sql_types, + sql_types::{self, Timestamptz}, BoolExpressionMethods, ExpressionMethods, + IntoSql, JoinOnDsl, NullableExpressionMethods, PgTextExpressionMethods, @@ -327,6 +328,7 @@ fn queries<'a>() -> Queries< query = query.filter(person_block::person_id.is_null()); } } + let now = diesel::dsl::now.into_sql::(); query = match options.sort.unwrap_or(SortType::Hot) { SortType::Active => query diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index b9fbf9a01..493aab27a 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -1,10 +1,10 @@ use crate::structs::PersonView; use diesel::{ - dsl::now, pg::Pg, result::Error, BoolExpressionMethods, ExpressionMethods, + NullableExpressionMethods, PgTextExpressionMethods, QueryDsl, }; @@ -16,7 +16,7 @@ use lemmy_db_schema::{ schema::{local_user, person, person_aggregates}, source::person::Person, 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, }; @@ -58,7 +58,7 @@ fn queries<'a>( person::banned.eq(true).and( person::ban_expires .is_null() - .or(person::ban_expires.gt(now)), + .or(person::ban_expires.gt(now().nullable())), ), ) .filter(person::deleted.eq(false)); diff --git a/crates/routes/src/feeds.rs b/crates/routes/src/feeds.rs index 96e718631..49cef6d41 100644 --- a/crates/routes/src/feeds.rs +++ b/crates/routes/src/feeds.rs @@ -1,6 +1,6 @@ use actix_web::{error::ErrorBadRequest, web, Error, HttpRequest, HttpResponse, Result}; use anyhow::anyhow; -use chrono::{DateTime, NaiveDateTime, Utc}; +use chrono::{DateTime, Utc}; use lemmy_api_common::context::LemmyContext; use lemmy_db_schema::{ newtypes::LocalUserId, @@ -449,7 +449,7 @@ fn create_reply_and_mention_items( #[tracing::instrument(skip_all)] fn build_item( creator_name: &str, - published: &NaiveDateTime, + published: &DateTime, url: &str, content: &str, protocol_and_hostname: &str, @@ -460,7 +460,7 @@ fn build_item( i.author(format!( "/u/{creator_name} (link)" )); - let dt = DateTime::::from_utc(*published, Utc); + let dt = published; i.pub_date(dt.to_rfc2822()); i.comments(url.to_owned()); 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()]); - let dt = DateTime::::from_utc(p.post.published, Utc); + let dt = p.post.published; i.pub_date(dt.to_rfc2822()); let post_url = format!("{}/post/{}", protocol_and_hostname, p.post.id); diff --git a/crates/utils/src/claims.rs b/crates/utils/src/claims.rs index 77a720694..cebd422ac 100644 --- a/crates/utils/src/claims.rs +++ b/crates/utils/src/claims.rs @@ -2,7 +2,6 @@ use crate::error::LemmyError; use chrono::Utc; use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, Validation}; use serde::{Deserialize, Serialize}; - type Jwt = String; #[derive(Debug, Serialize, Deserialize)] diff --git a/crates/utils/src/utils/time.rs b/crates/utils/src/utils/time.rs index c1e167651..1f7ebe145 100644 --- a/crates/utils/src/utils/time.rs +++ b/crates/utils/src/utils/time.rs @@ -1,12 +1,12 @@ -use chrono::{DateTime, FixedOffset, NaiveDateTime}; +use chrono::{DateTime, TimeZone, Utc}; -pub fn naive_from_unix(time: i64) -> NaiveDateTime { - NaiveDateTime::from_timestamp_opt(time, 0).expect("convert datetime") +pub fn naive_from_unix(time: i64) -> DateTime { + Utc + .timestamp_opt(time, 0) + .single() + .expect("convert datetime") } -pub fn convert_datetime(datetime: NaiveDateTime) -> DateTime { - DateTime::::from_utc( - datetime, - FixedOffset::east_opt(0).expect("create fixed offset"), - ) +pub fn convert_datetime(datetime: DateTime) -> DateTime { + datetime } diff --git a/migrations/2023-08-02-174444_fix-timezones/down.sql b/migrations/2023-08-02-174444_fix-timezones/down.sql new file mode 100644 index 000000000..c81afa9d5 --- /dev/null +++ b/migrations/2023-08-02-174444_fix-timezones/down.sql @@ -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; + diff --git a/migrations/2023-08-02-174444_fix-timezones/up.sql b/migrations/2023-08-02-174444_fix-timezones/up.sql new file mode 100644 index 000000000..5ff41e304 --- /dev/null +++ b/migrations/2023-08-02-174444_fix-timezones/up.sql @@ -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; + diff --git a/src/scheduled_tasks.rs b/src/scheduled_tasks.rs index a93494727..3b2bfe4b5 100644 --- a/src/scheduled_tasks.rs +++ b/src/scheduled_tasks.rs @@ -1,8 +1,8 @@ -use chrono::NaiveDateTime; +use chrono::{DateTime, TimeZone, Utc}; use clokwerk::{Scheduler, TimeUnits as CTimeUnits}; use diesel::{ - dsl::{now, IntervalDsl}, - sql_types::{Integer, Timestamp}, + dsl::IntervalDsl, + sql_types::{Integer, Timestamptz}, Connection, ExpressionMethods, NullableExpressionMethods, @@ -24,7 +24,7 @@ use lemmy_db_schema::{ sent_activity, }, source::instance::{Instance, InstanceForm}, - utils::{naive_now, DELETED_REPLACEMENT_TEXT}, + utils::{naive_now, now, DELETED_REPLACEMENT_TEXT}, }; use lemmy_routes::nodeinfo::NodeInfo; use lemmy_utils::{ @@ -181,8 +181,8 @@ fn update_hot_ranks(conn: &mut PgConnection) { #[derive(QueryableByName)] struct HotRanksUpdateResult { - #[diesel(sql_type = Timestamp)] - published: NaiveDateTime, + #[diesel(sql_type = Timestamptz)] + published: DateTime, } /// Runs the hot rank update query in batches until all rows have been processed. @@ -195,7 +195,10 @@ fn process_hot_ranks_in_batches( where_clause: &str, set_clause: &str, ) { - let process_start_time = NaiveDateTime::from_timestamp_opt(0, 0).expect("0 timestamp creation"); + let process_start_time: DateTime = Utc + .timestamp_opt(0, 0) + .single() + .expect("0 timestamp creation"); let update_batch_size = 1000; // Bigger batches than this tend to cause seq scans let mut processed_rows_count = 0; @@ -217,7 +220,7 @@ fn process_hot_ranks_in_batches( set_clause = set_clause, where_clause = where_clause )) - .bind::(previous_batch_last_published) + .bind::(previous_batch_last_published) .bind::(update_batch_size) .get_results::(conn); @@ -240,7 +243,7 @@ fn process_hot_ranks_in_batches( fn delete_expired_captcha_answers(conn: &mut PgConnection) { diesel::delete( - captcha_answer::table.filter(captcha_answer::published.lt(now - IntervalDsl::minutes(10))), + captcha_answer::table.filter(captcha_answer::published.lt(now() - IntervalDsl::minutes(10))), ) .execute(conn) .map(|_| { @@ -253,13 +256,13 @@ fn delete_expired_captcha_answers(conn: &mut PgConnection) { /// Clear old activities (this table gets very large) fn clear_old_activities(conn: &mut PgConnection) { info!("Clearing old activities..."); - diesel::delete(sent_activity::table.filter(sent_activity::published.lt(now - 3.months()))) + diesel::delete(sent_activity::table.filter(sent_activity::published.lt(now() - 3.months()))) .execute(conn) .map_err(|e| error!("Failed to clear old sent activities: {e}")) .ok(); diesel::delete( - received_activity::table.filter(received_activity::published.lt(now - 3.months())), + received_activity::table.filter(received_activity::published.lt(now() - 3.months())), ) .execute(conn) .map(|_| info!("Done.")) @@ -273,7 +276,7 @@ fn overwrite_deleted_posts_and_comments(conn: &mut PgConnection) { diesel::update( post::table .filter(post::deleted.eq(true)) - .filter(post::updated.lt(now.nullable() - 1.months())) + .filter(post::updated.lt(now().nullable() - 1.months())) .filter(post::body.ne(DELETED_REPLACEMENT_TEXT)), ) .set(( @@ -291,7 +294,7 @@ fn overwrite_deleted_posts_and_comments(conn: &mut PgConnection) { diesel::update( comment::table .filter(comment::deleted.eq(true)) - .filter(comment::updated.lt(now.nullable() - 1.months())) + .filter(comment::updated.lt(now().nullable() - 1.months())) .filter(comment::content.ne(DELETED_REPLACEMENT_TEXT)), ) .set(comment::content.eq(DELETED_REPLACEMENT_TEXT)) @@ -341,17 +344,19 @@ fn update_banned_when_expired(conn: &mut PgConnection) { diesel::update( person::table .filter(person::banned.eq(true)) - .filter(person::ban_expires.lt(now)), + .filter(person::ban_expires.lt(now().nullable())), ) .set(person::banned.eq(false)) .execute(conn) .map_err(|e| error!("Failed to update person.banned when expires: {e}")) .ok(); - diesel::delete(community_person_ban::table.filter(community_person_ban::expires.lt(now))) - .execute(conn) - .map_err(|e| error!("Failed to remove community_ban expired rows: {e}")) - .ok(); + diesel::delete( + community_person_ban::table.filter(community_person_ban::expires.lt(now().nullable())), + ) + .execute(conn) + .map_err(|e| error!("Failed to remove community_ban expired rows: {e}")) + .ok(); } /// Updates the instance software and version