1
0
Fork 0
forked from alemi/upub

feat: add statuses count and in_reply_to fields

migration + models update
This commit is contained in:
əlemi 2024-04-18 04:09:13 +02:00
parent 179fd0807b
commit a897edd310
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 80 additions and 1 deletions

View file

@ -0,0 +1,72 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Users::Table)
.add_column(
ColumnDef::new(Users::StatusesCount)
.integer()
.not_null()
.default(0)
)
.to_owned()
)
.await?;
manager
.alter_table(
Table::alter()
.table(Objects::Table)
.add_column(
ColumnDef::new(Objects::InReplyTo)
.string()
.null()
)
.to_owned()
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Users::Table)
.drop_column(Users::StatusesCount)
.to_owned()
)
.await?;
manager
.alter_table(
Table::alter()
.table(Objects::Table)
.drop_column(Objects::InReplyTo)
.to_owned()
)
.await?;
Ok(())
}
}
#[derive(DeriveIden)]
enum Users {
Table,
StatusesCount,
}
#[derive(DeriveIden)]
enum Objects {
Table,
InReplyTo,
}

View file

@ -9,6 +9,7 @@ mod m20240323_000002_add_simple_credentials;
mod m20240324_000001_add_addressing;
mod m20240325_000001_add_deliveries;
mod m20240325_000002_add_system_key;
mod m20240418_000001_add_statuses_and_reply_to;
pub struct Migrator;
@ -25,6 +26,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240324_000001_add_addressing::Migration),
Box::new(m20240325_000001_add_deliveries::Migration),
Box::new(m20240325_000002_add_system_key::Migration),
Box::new(m20240418_000001_add_statuses_and_reply_to::Migration),
]
}
}

View file

@ -17,6 +17,7 @@ pub async fn faker(db: &sea_orm::DatabaseConnection, domain: String, count: u64)
following_count: 0,
followers: None,
followers_count: 0,
statuses_count: count as i64,
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,
@ -69,6 +70,7 @@ pub async fn faker(db: &sea_orm::DatabaseConnection, domain: String, count: u64)
attributed_to: Set(Some(format!("{domain}/users/test"))),
summary: Set(None),
context: Set(Some(context.clone())),
in_reply_to: 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)),
comments: Set(0),

View file

@ -16,6 +16,7 @@ pub struct Model {
pub shares: i64,
pub comments: i64,
pub context: Option<String>,
pub in_reply_to: Option<String>,
pub cc: Audience,
pub bcc: Audience,
pub to: Audience,
@ -33,6 +34,7 @@ impl Model {
summary: object.summary().map(|x| x.to_string()),
content: object.content().map(|x| x.to_string()),
context: object.context().id(),
in_reply_to: object.in_reply_to().id(),
published: object.published().ok_or(super::FieldError("published"))?,
comments: 0,
likes: 0,

View file

@ -24,7 +24,7 @@ pub struct Model {
pub following_count: i64,
pub followers_count: i64,
// pub statuses_count: i64,
pub statuses_count: i64,
pub public_key: String,
pub private_key: Option<String>,
@ -57,6 +57,7 @@ impl Model {
updated: chrono::Utc::now(),
following_count: object.following().get().map(|f| f.total_items().unwrap_or(0)).unwrap_or(0) as i64,
followers_count: object.followers().get().map(|f| f.total_items().unwrap_or(0)).unwrap_or(0) as i64,
statuses_count: object.outbox().get().map(|o| o.total_items().unwrap_or(0)).unwrap_or(0) as i64,
public_key: object.public_key().get().ok_or(super::FieldError("publicKey"))?.public_key_pem().to_string(),
private_key: None, // there's no way to transport privkey over AP json, must come from DB
})