forked from alemi/upub
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:
parent
72c2cd5f81
commit
d36ac82dd9
2 changed files with 10 additions and 1 deletions
|
@ -28,6 +28,8 @@ impl MigrationTrait for Migration {
|
||||||
.col(ColumnDef::new(Users::Outbox).string().null())
|
.col(ColumnDef::new(Users::Outbox).string().null())
|
||||||
.col(ColumnDef::new(Users::Following).string().null())
|
.col(ColumnDef::new(Users::Following).string().null())
|
||||||
.col(ColumnDef::new(Users::Followers).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::PublicKey).string().not_null())
|
||||||
.col(ColumnDef::new(Users::PrivateKey).string().null())
|
.col(ColumnDef::new(Users::PrivateKey).string().null())
|
||||||
.col(ColumnDef::new(Users::Created).date_time().not_null())
|
.col(ColumnDef::new(Users::Created).date_time().not_null())
|
||||||
|
@ -120,7 +122,9 @@ enum Users {
|
||||||
SharedInbox,
|
SharedInbox,
|
||||||
Outbox,
|
Outbox,
|
||||||
Following,
|
Following,
|
||||||
|
FollowingCount,
|
||||||
Followers,
|
Followers,
|
||||||
|
FollowersCount,
|
||||||
PublicKey,
|
PublicKey,
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
Created,
|
Created,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
use crate::activitystream::key::PublicKey as _;
|
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)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||||
#[sea_orm(table_name = "users")]
|
#[sea_orm(table_name = "users")]
|
||||||
|
@ -24,6 +24,9 @@ pub struct Model {
|
||||||
pub following: Option<String>,
|
pub following: Option<String>,
|
||||||
pub followers: Option<String>,
|
pub followers: Option<String>,
|
||||||
|
|
||||||
|
pub following_count: i64,
|
||||||
|
pub followers_count: i64,
|
||||||
|
|
||||||
pub public_key: String,
|
pub public_key: String,
|
||||||
pub private_key: Option<String>,
|
pub private_key: Option<String>,
|
||||||
|
|
||||||
|
@ -53,6 +56,8 @@ impl Model {
|
||||||
following: object.following().id().map(|x| x.to_string()),
|
following: object.following().id().map(|x| x.to_string()),
|
||||||
created: object.published().unwrap_or(chrono::Utc::now()),
|
created: object.published().unwrap_or(chrono::Utc::now()),
|
||||||
updated: 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(),
|
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
|
private_key: None, // there's no way to transport privkey over AP json, must come from DB
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue