diff --git a/src/activitypub/actors/attachments.rs b/src/activitypub/actors/attachments.rs index 3f98d12..30987fe 100644 --- a/src/activitypub/actors/attachments.rs +++ b/src/activitypub/actors/attachments.rs @@ -158,8 +158,10 @@ pub fn parse_extra_field( #[cfg(test)] mod tests { - use crate::utils::caip2::ChainId; - use crate::utils::id::new_uuid; + use crate::utils::{ + caip2::ChainId, + id::generate_ulid, + }; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -181,7 +183,7 @@ mod tests { #[test] fn test_payment_option() { - let user_id = new_uuid(); + let user_id = generate_ulid(); let payment_option = PaymentOption::ethereum_subscription(ChainId::ethereum_mainnet()); let subscription_page_url = diff --git a/src/activitypub/builders/accept_follow.rs b/src/activitypub/builders/accept_follow.rs index fff87f0..8651709 100644 --- a/src/activitypub/builders/accept_follow.rs +++ b/src/activitypub/builders/accept_follow.rs @@ -10,7 +10,7 @@ use crate::activitypub::{ use crate::config::Instance; use crate::models::profiles::types::DbActorProfile; use crate::models::users::types::User; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; #[derive(Serialize)] struct AcceptFollow { @@ -34,7 +34,7 @@ fn build_accept_follow( follow_activity_id: &str, ) -> AcceptFollow { // Accept(Follow) is idempotent so its ID can be random - let activity_id = local_object_id(instance_url, &new_uuid()); + let activity_id = local_object_id(instance_url, &generate_ulid()); let actor_id = local_actor_id(instance_url, &actor_profile.username); AcceptFollow { context: build_default_context(), diff --git a/src/activitypub/builders/add_person.rs b/src/activitypub/builders/add_person.rs index b58e355..1a8a308 100644 --- a/src/activitypub/builders/add_person.rs +++ b/src/activitypub/builders/add_person.rs @@ -9,7 +9,7 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::models::users::types::User; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; #[derive(Serialize)] struct AddOrRemovePerson { @@ -35,7 +35,7 @@ fn build_update_collection( remove: bool, ) -> AddOrRemovePerson { let actor_id = local_actor_id(instance_url, sender_username); - let activity_id = local_object_id(instance_url, &new_uuid()); + let activity_id = local_object_id(instance_url, &generate_ulid()); let activity_type = if remove { REMOVE } else { ADD }; let collection_id = collection.of(&actor_id); AddOrRemovePerson { diff --git a/src/activitypub/builders/follow.rs b/src/activitypub/builders/follow.rs index d7d7a62..b8b123f 100644 --- a/src/activitypub/builders/follow.rs +++ b/src/activitypub/builders/follow.rs @@ -68,7 +68,7 @@ pub fn prepare_follow( #[cfg(test)] mod tests { - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -79,7 +79,7 @@ mod tests { username: "follower".to_string(), ..Default::default() }; - let follow_request_id = new_uuid(); + let follow_request_id = generate_ulid(); let target_actor_id = "https://test.remote/actor/test"; let activity = build_follow( INSTANCE_URL, diff --git a/src/activitypub/builders/like.rs b/src/activitypub/builders/like.rs index 32bac4a..361dd7c 100644 --- a/src/activitypub/builders/like.rs +++ b/src/activitypub/builders/like.rs @@ -110,7 +110,7 @@ pub async fn prepare_like( #[cfg(test)] mod tests { - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -120,7 +120,7 @@ mod tests { let author = DbActorProfile::default(); let post_id = "https://example.com/objects/123"; let post_author_id = "https://example.com/users/test"; - let reaction_id = new_uuid(); + let reaction_id = generate_ulid(); let activity = build_like( INSTANCE_URL, &author, diff --git a/src/activitypub/builders/move_person.rs b/src/activitypub/builders/move_person.rs index da1589f..62f7f0d 100644 --- a/src/activitypub/builders/move_person.rs +++ b/src/activitypub/builders/move_person.rs @@ -10,7 +10,7 @@ use crate::activitypub::{ }; use crate::config::Instance; use crate::models::users::types::User; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; #[derive(Serialize)] pub struct MovePerson { @@ -36,7 +36,7 @@ pub fn build_move_person( maybe_internal_activity_id: Option<&Uuid>, ) -> MovePerson { let internal_activity_id = maybe_internal_activity_id.copied() - .unwrap_or(new_uuid()); + .unwrap_or(generate_ulid()); let activity_id = local_object_id(instance_url, &internal_activity_id); let actor_id = local_actor_id(instance_url, &sender.profile.username); MovePerson { @@ -78,7 +78,7 @@ pub fn prepare_move_person( #[cfg(test)] mod tests { use crate::models::profiles::types::DbActorProfile; - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -97,7 +97,7 @@ mod tests { "https://server1.org/users/1".to_string(), "https://server2.org/users/2".to_string(), ]; - let internal_activity_id = new_uuid(); + let internal_activity_id = generate_ulid(); let activity = build_move_person( INSTANCE_URL, &sender, diff --git a/src/activitypub/builders/undo_announce.rs b/src/activitypub/builders/undo_announce.rs index be60b40..1ed678d 100644 --- a/src/activitypub/builders/undo_announce.rs +++ b/src/activitypub/builders/undo_announce.rs @@ -88,7 +88,7 @@ pub async fn prepare_undo_announce( #[cfg(test)] mod tests { - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -97,7 +97,7 @@ mod tests { fn test_build_undo_announce() { let announcer = DbActorProfile::default(); let post_author_id = "https://example.com/users/test"; - let repost_id = new_uuid(); + let repost_id = generate_ulid(); let activity = build_undo_announce( INSTANCE_URL, &announcer, diff --git a/src/activitypub/builders/undo_follow.rs b/src/activitypub/builders/undo_follow.rs index d29946a..0706ae7 100644 --- a/src/activitypub/builders/undo_follow.rs +++ b/src/activitypub/builders/undo_follow.rs @@ -85,7 +85,7 @@ pub fn prepare_undo_follow( #[cfg(test)] mod tests { - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -97,7 +97,7 @@ mod tests { ..Default::default() }; let target_actor_id = "https://test.remote/users/123"; - let follow_request_id = new_uuid(); + let follow_request_id = generate_ulid(); let activity = build_undo_follow( INSTANCE_URL, &actor_profile, diff --git a/src/activitypub/builders/undo_like.rs b/src/activitypub/builders/undo_like.rs index 1898ad0..1181cb8 100644 --- a/src/activitypub/builders/undo_like.rs +++ b/src/activitypub/builders/undo_like.rs @@ -87,7 +87,7 @@ pub async fn prepare_undo_like( #[cfg(test)] mod tests { use crate::activitypub::constants::AP_PUBLIC; - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.com"; @@ -96,7 +96,7 @@ mod tests { fn test_build_undo_like() { let author = DbActorProfile::default(); let post_author_id = "https://example.com/users/test"; - let reaction_id = new_uuid(); + let reaction_id = generate_ulid(); let activity = build_undo_like( INSTANCE_URL, &author, diff --git a/src/activitypub/builders/update_person.rs b/src/activitypub/builders/update_person.rs index 0658514..88d2657 100644 --- a/src/activitypub/builders/update_person.rs +++ b/src/activitypub/builders/update_person.rs @@ -13,7 +13,7 @@ use crate::config::Instance; use crate::database::{DatabaseClient, DatabaseError, DatabaseTypeError}; use crate::models::relationships::queries::get_followers; use crate::models::users::types::User; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; #[derive(Serialize)] pub struct UpdatePerson { @@ -38,7 +38,7 @@ pub fn build_update_person( let actor = get_local_actor(user, instance_url)?; // Update(Person) is idempotent so its ID can be random let internal_activity_id = - maybe_internal_activity_id.unwrap_or(new_uuid()); + maybe_internal_activity_id.unwrap_or(generate_ulid()); let activity_id = local_object_id(instance_url, &internal_activity_id); let activity = UpdatePerson { context: build_default_context(), @@ -111,7 +111,7 @@ mod tests { }, ..Default::default() }; - let internal_id = new_uuid(); + let internal_id = generate_ulid(); let activity = build_update_person( INSTANCE_URL, &user, diff --git a/src/activitypub/identifiers.rs b/src/activitypub/identifiers.rs index ec23667..705dde9 100644 --- a/src/activitypub/identifiers.rs +++ b/src/activitypub/identifiers.rs @@ -116,7 +116,7 @@ pub fn parse_local_object_id( #[cfg(test)] mod tests { - use crate::utils::id::new_uuid; + use crate::utils::id::generate_ulid; use super::*; const INSTANCE_URL: &str = "https://example.org"; @@ -159,7 +159,7 @@ mod tests { #[test] fn test_parse_local_object_id() { - let expected_uuid = new_uuid(); + let expected_uuid = generate_ulid(); let object_id = format!( "https://example.org/objects/{}", expected_uuid, diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index 6495e6f..fe52e56 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -77,7 +77,7 @@ use crate::utils::{ serialize_private_key, }, currencies::Currency, - id::new_uuid, + id::generate_ulid, passwords::hash_password, }; use super::helpers::{follow_or_create_request, get_relationship}; @@ -244,7 +244,7 @@ async fn get_unsigned_update( ) -> Result { let db_client = &**get_database_client(&db_pool).await?; let current_user = get_current_user(db_client, auth.token()).await?; - let internal_activity_id = new_uuid(); + let internal_activity_id = generate_ulid(); let activity = build_update_person( &config.instance_url(), ¤t_user, diff --git a/src/models/attachments/queries.rs b/src/models/attachments/queries.rs index 08f7c74..f7e61ce 100644 --- a/src/models/attachments/queries.rs +++ b/src/models/attachments/queries.rs @@ -7,7 +7,7 @@ use crate::models::cleanup::{ find_orphaned_ipfs_objects, DeletionQueue, }; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; use super::types::DbMediaAttachment; pub async fn create_attachment( @@ -17,7 +17,7 @@ pub async fn create_attachment( file_size: usize, media_type: Option, ) -> Result { - let attachment_id = new_uuid(); + let attachment_id = generate_ulid(); let file_size: i32 = file_size.try_into() .expect("value should be within bounds"); let inserted_row = db_client.query_one( diff --git a/src/models/emojis/queries.rs b/src/models/emojis/queries.rs index 4fa89ec..ea32313 100644 --- a/src/models/emojis/queries.rs +++ b/src/models/emojis/queries.rs @@ -10,7 +10,7 @@ use crate::models::{ cleanup::{find_orphaned_files, DeletionQueue}, instances::queries::create_instance, }; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; use super::types::{DbEmoji, EmojiImage}; pub async fn create_emoji( @@ -21,7 +21,7 @@ pub async fn create_emoji( object_id: Option<&str>, updated_at: &DateTime, ) -> Result { - let emoji_id = new_uuid(); + let emoji_id = generate_ulid(); if let Some(hostname) = hostname { create_instance(db_client, hostname).await?; }; diff --git a/src/models/invoices/queries.rs b/src/models/invoices/queries.rs index d0a74c2..2faed27 100644 --- a/src/models/invoices/queries.rs +++ b/src/models/invoices/queries.rs @@ -5,8 +5,10 @@ use crate::database::{ DatabaseClient, DatabaseError, }; -use crate::utils::caip2::ChainId; -use crate::utils::id::new_uuid; +use crate::utils::{ + caip2::ChainId, + id::generate_ulid, +}; use super::types::{DbInvoice, InvoiceStatus}; pub async fn create_invoice( @@ -17,7 +19,7 @@ pub async fn create_invoice( payment_address: &str, amount: i64, ) -> Result { - let invoice_id = new_uuid(); + let invoice_id = generate_ulid(); let row = db_client.query_one( " INSERT INTO invoice ( diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index 6109519..68aa572 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -23,7 +23,7 @@ use crate::models::notifications::queries::{ use crate::models::profiles::queries::update_post_count; use crate::models::profiles::types::DbActorProfile; use crate::models::relationships::types::RelationshipType; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; use super::types::{ DbPost, Post, @@ -166,7 +166,7 @@ pub async fn create_post( post_data: PostCreateData, ) -> Result { let transaction = db_client.transaction().await?; - let post_id = new_uuid(); + let post_id = generate_ulid(); // Replying to reposts is not allowed // Reposting of other reposts or non-public posts is not allowed let insert_statement = format!( diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index 4f5be8c..71835be 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -15,8 +15,10 @@ use crate::models::cleanup::{ }; use crate::models::instances::queries::create_instance; use crate::models::relationships::types::RelationshipType; -use crate::utils::currencies::Currency; -use crate::utils::id::new_uuid; +use crate::utils::{ + currencies::Currency, + id::generate_ulid, +}; use super::types::{ DbActorProfile, ExtraFields, @@ -31,7 +33,7 @@ pub async fn create_profile( db_client: &impl DatabaseClient, profile_data: ProfileCreateData, ) -> Result { - let profile_id = new_uuid(); + let profile_id = generate_ulid(); if let Some(ref hostname) = profile_data.hostname { create_instance(db_client, hostname).await?; }; diff --git a/src/models/reactions/queries.rs b/src/models/reactions/queries.rs index 4bac9d9..2c062d7 100644 --- a/src/models/reactions/queries.rs +++ b/src/models/reactions/queries.rs @@ -10,7 +10,7 @@ use crate::models::posts::queries::{ update_reaction_count, get_post_author, }; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; use super::types::DbReaction; pub async fn create_reaction( @@ -20,7 +20,7 @@ pub async fn create_reaction( activity_id: Option<&String>, ) -> Result { let transaction = db_client.transaction().await?; - let reaction_id = new_uuid(); + let reaction_id = generate_ulid(); // Reactions to reposts are not allowed let maybe_row = transaction.query_opt( " diff --git a/src/models/relationships/queries.rs b/src/models/relationships/queries.rs index 70a114b..61fd716 100644 --- a/src/models/relationships/queries.rs +++ b/src/models/relationships/queries.rs @@ -12,7 +12,7 @@ use crate::models::profiles::queries::{ update_subscriber_count, }; use crate::models::profiles::types::DbActorProfile; -use crate::utils::id::new_uuid; +use crate::utils::id::generate_ulid; use super::types::{ DbFollowRequest, DbRelationship, @@ -142,7 +142,7 @@ pub async fn create_follow_request( source_id: &Uuid, target_id: &Uuid, ) -> Result { - let request_id = new_uuid(); + let request_id = generate_ulid(); let row = db_client.query_one( " INSERT INTO follow_request ( @@ -169,7 +169,7 @@ pub async fn create_remote_follow_request_opt( target_id: &Uuid, activity_id: &str, ) -> Result { - let request_id = new_uuid(); + let request_id = generate_ulid(); let row = db_client.query_one( " INSERT INTO follow_request ( diff --git a/src/utils/id.rs b/src/utils/id.rs index 1b1fd90..5090c47 100644 --- a/src/utils/id.rs +++ b/src/utils/id.rs @@ -2,7 +2,7 @@ use ulid::Ulid; use uuid::Uuid; /// Produces new lexicographically sortable ID -pub fn new_uuid() -> Uuid { +pub fn generate_ulid() -> Uuid { let ulid = Ulid::new(); Uuid::from(ulid) }