feat: add followers and followers count to users

redo migrations (: honestly if you're expecting to keep a long-lasting
db at this stage of development i have bad news for you
This commit is contained in:
əlemi 2024-03-23 16:44:27 +01:00
parent 72c2cd5f81
commit d36ac82dd9
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 10 additions and 1 deletions

View file

@ -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,

View file

@ -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<String>,
pub followers: Option<String>,
pub following_count: i64,
pub followers_count: i64,
pub public_key: String,
pub private_key: Option<String>,
@ -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
})