diff --git a/src/migrations/m20240316_000001_create_table.rs b/src/migrations/m20240316_000001_create_table.rs index 62c6895..9007f65 100644 --- a/src/migrations/m20240316_000001_create_table.rs +++ b/src/migrations/m20240316_000001_create_table.rs @@ -28,6 +28,8 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(Users::Outbox).string().null()) .col(ColumnDef::new(Users::Following).string().null()) .col(ColumnDef::new(Users::Followers).string().null()) + .col(ColumnDef::new(Users::FollowingCount).integer().not_null().default(0)) + .col(ColumnDef::new(Users::FollowersCount).integer().not_null().default(0)) .col(ColumnDef::new(Users::PublicKey).string().not_null()) .col(ColumnDef::new(Users::PrivateKey).string().null()) .col(ColumnDef::new(Users::Created).date_time().not_null()) @@ -120,7 +122,9 @@ enum Users { SharedInbox, Outbox, Following, + FollowingCount, Followers, + FollowersCount, PublicKey, PrivateKey, Created, diff --git a/src/model/user.rs b/src/model/user.rs index 2495ce4..2d89902 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -1,7 +1,7 @@ use sea_orm::entity::prelude::*; use crate::activitystream::key::PublicKey as _; -use crate::{activitypub, activitystream::object::actor::{Actor, ActorType}}; +use crate::{activitypub, activitystream::object::{collection::Collection, actor::{Actor, ActorType}}}; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "users")] @@ -24,6 +24,9 @@ pub struct Model { pub following: Option, pub followers: Option, + pub following_count: i64, + pub followers_count: i64, + pub public_key: String, pub private_key: Option, @@ -53,6 +56,8 @@ impl Model { following: object.following().id().map(|x| x.to_string()), created: object.published().unwrap_or(chrono::Utc::now()), 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, 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 })