2024-03-21 01:09:33 +01:00
use sea_orm ::IntoActiveModel ;
use crate ::{ activitypub ::PUBLIC_TARGET , activitystream ::object ::actor ::Actor , model ::activity ::Audience } ;
2024-03-16 03:27:36 +01:00
pub mod user ;
2024-03-16 05:45:58 +01:00
pub mod object ;
2023-12-30 05:08:05 +01:00
pub mod activity ;
2024-03-16 05:45:58 +01:00
2024-03-16 20:09:06 +01:00
#[ derive(Debug, Clone, thiserror::Error) ]
#[ error( " missing required field: '{0}' " ) ]
2024-03-19 01:00:44 +01:00
pub struct FieldError ( pub & 'static str ) ;
2024-03-16 20:09:06 +01:00
2024-03-20 08:56:35 +01:00
pub async fn faker ( db : & sea_orm ::DatabaseConnection , domain : String ) -> Result < ( ) , sea_orm ::DbErr > {
2024-03-21 01:09:33 +01:00
use sea_orm ::{ EntityTrait , Set } ;
let root = user ::Model {
id : format ! ( " {domain}/users/root " ) ,
name : " root " . into ( ) ,
domain : crate ::activitypub ::domain ( & domain ) ,
preferred_username : Some ( " Administrator " . to_string ( ) ) ,
summary : Some ( " hello world! i'm manually generated but served dynamically from db! " . to_string ( ) ) ,
following : None ,
followers : None ,
icon : Some ( " https://cdn.alemi.dev/social/circle-square.png " . to_string ( ) ) ,
image : Some ( " https://cdn.alemi.dev/social/someriver-xs.jpg " . to_string ( ) ) ,
inbox : None ,
shared_inbox : None ,
outbox : None ,
actor_type : super ::activitystream ::object ::actor ::ActorType ::Person ,
created : chrono ::Utc ::now ( ) ,
updated : chrono ::Utc ::now ( ) ,
} ;
2024-03-16 05:45:58 +01:00
2024-03-21 01:09:33 +01:00
user ::Entity ::insert ( root . clone ( ) . into_active_model ( ) ) . exec ( db ) . await ? ;
2024-03-16 05:45:58 +01:00
2024-03-20 07:53:45 +01:00
for i in ( 0 .. 100 ) . rev ( ) {
let oid = uuid ::Uuid ::new_v4 ( ) ;
let aid = uuid ::Uuid ::new_v4 ( ) ;
object ::Entity ::insert ( object ::ActiveModel {
2024-03-21 01:09:33 +01:00
id : Set ( format! ( " {domain} /objects/ {oid} " ) ) ,
name : Set ( None ) ,
object_type : Set ( crate ::activitystream ::object ::ObjectType ::Note ) ,
attributed_to : Set ( Some ( format! ( " {domain} /users/root " ) ) ) ,
summary : Set ( None ) ,
content : Set ( Some ( format! ( " [ {i} ] Tic(k). Quasiparticle of intensive multiplicity. Tics (or ticks) are intrinsically several components of autonomously numbering anorganic populations, propagating by contagion between segmentary divisions in the order of nature. Ticks - as nonqualitative differentially-decomposable counting marks - each designate a multitude comprehended as a singular variation in tic(k)-density. " ) ) ) ,
published : Set ( chrono ::Utc ::now ( ) - std ::time ::Duration ::from_secs ( 60 * i ) ) ,
2024-03-20 07:53:45 +01:00
} ) . exec ( db ) . await ? ;
2024-03-16 05:45:58 +01:00
2024-03-20 07:53:45 +01:00
activity ::Entity ::insert ( activity ::ActiveModel {
2024-03-21 01:09:33 +01:00
id : Set ( format! ( " {domain} /activities/ {aid} " ) ) ,
activity_type : Set ( crate ::activitystream ::object ::activity ::ActivityType ::Create ) ,
actor : Set ( format! ( " {domain} /users/root " ) ) ,
object : Set ( Some ( format! ( " {domain} /objects/ {oid} " ) ) ) ,
target : Set ( None ) ,
published : Set ( chrono ::Utc ::now ( ) - std ::time ::Duration ::from_secs ( 60 * i ) ) ,
to : Set ( Audience ( vec! [ PUBLIC_TARGET . to_string ( ) ] ) ) ,
bto : Set ( Audience ::default ( ) ) ,
cc : Set ( Audience ( vec! [ root . followers ( ) . id ( ) . unwrap_or ( " " ) . to_string ( ) ] ) ) ,
bcc : Set ( Audience ::default ( ) ) ,
2024-03-20 07:53:45 +01:00
} ) . exec ( db ) . await ? ;
}
2024-03-16 05:45:58 +01:00
Ok ( ( ) )
}