feat: naive attempt to resolve followers/following
This commit is contained in:
parent
bcfd71eb06
commit
c94bfdcbe8
2 changed files with 63 additions and 1 deletions
|
@ -61,6 +61,8 @@ pub enum Relation {
|
|||
Mentions,
|
||||
#[sea_orm(has_many = "super::object::Entity")]
|
||||
Objects,
|
||||
#[sea_orm(has_many = "super::relation::Entity")]
|
||||
Relations,
|
||||
#[sea_orm(has_many = "super::session::Entity")]
|
||||
Sessions,
|
||||
}
|
||||
|
@ -125,6 +127,12 @@ impl Related<super::object::Entity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<super::relation::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Relations.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::session::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Sessions.def()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "relations")]
|
||||
|
@ -47,4 +47,58 @@ pub enum Relation {
|
|||
ActorsFollowing,
|
||||
}
|
||||
|
||||
impl Related<super::actor::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::ActorsFollowing.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::activity::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::ActivitiesFollow.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl Entity {
|
||||
pub async fn followers(uid: &str, db: &DatabaseConnection) -> crate::Result<Vec<String>> {
|
||||
let internal_id = super::actor::Entity::ap_to_internal(uid, db).await?;
|
||||
let out = Entity::find()
|
||||
.join(
|
||||
sea_orm::JoinType::InnerJoin,
|
||||
Entity::belongs_to(super::actor::Entity)
|
||||
.from(Column::Follower)
|
||||
.to(super::actor::Column::Internal)
|
||||
.into()
|
||||
)
|
||||
.filter(Column::Following.eq(internal_id))
|
||||
.select_only()
|
||||
.select_column(super::actor::Column::Id)
|
||||
.into_tuple::<String>()
|
||||
.all(db)
|
||||
.await?;
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
pub async fn following(uid: &str, db: &DatabaseConnection) -> crate::Result<Vec<String>> {
|
||||
let internal_id = super::actor::Entity::ap_to_internal(uid, db).await?;
|
||||
let out = Entity::find()
|
||||
.join(
|
||||
sea_orm::JoinType::InnerJoin,
|
||||
Entity::belongs_to(super::actor::Entity)
|
||||
.from(Column::Following)
|
||||
.to(super::actor::Column::Internal)
|
||||
.into()
|
||||
)
|
||||
.filter(Column::Follower.eq(internal_id))
|
||||
.select_only()
|
||||
.select_column(super::actor::Column::Id)
|
||||
.into_tuple::<String>()
|
||||
.all(db)
|
||||
.await?;
|
||||
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue