feat: added audience field

so that we can see where lemmy posts are coming from
This commit is contained in:
əlemi 2024-06-06 20:43:03 +02:00
parent ffa92b4f61
commit 5cfd16ea35
Signed by: alemi
GPG key ID: A4895B84D311642C
6 changed files with 43 additions and 0 deletions

View file

@ -83,6 +83,7 @@ pub async fn faker(ctx: upub::Context, count: i64) -> Result<(), sea_orm::DbErr>
replies: Set(0),
likes: Set(0),
announces: Set(0),
audience: Set(None),
to: Set(Audience(vec![apb::target::PUBLIC.to_string()])),
bto: Set(Audience::default()),
cc: Set(Audience(vec![])),

View file

@ -28,6 +28,8 @@ pub struct Model {
pub bcc: Audience,
pub published: ChronoDateTimeUtc,
pub updated: ChronoDateTimeUtc,
pub audience: Option<String>, // added with migration m20240606_000001
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
@ -195,6 +197,7 @@ impl Model {
.set_in_reply_to(apb::Node::maybe_link(self.in_reply_to.clone()))
.set_published(Some(self.published))
.set_updated(Some(self.updated))
.set_audience(apb::Node::maybe_link(self.audience))
.set_to(apb::Node::links(self.to.0.clone()))
.set_bto(apb::Node::Empty)
.set_cc(apb::Node::links(self.cc.0.clone()))

View file

@ -231,6 +231,7 @@ impl AP {
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32,
announces: object.shares().get()
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32,
audience: object.audience().id().str(),
to: object.to().into(),
bto: object.bto().into(),
cc: object.cc().into(),

View file

@ -7,6 +7,7 @@ mod m20240524_000004_create_addressing_deliveries;
mod m20240524_000005_create_attachments_tags_mentions;
mod m20240529_000001_add_relation_unique_index;
mod m20240605_000001_add_jobs_table;
mod m20240606_000001_add_audience_to_objects;
pub struct Migrator;
@ -21,6 +22,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240524_000005_create_attachments_tags_mentions::Migration),
Box::new(m20240529_000001_add_relation_unique_index::Migration),
Box::new(m20240605_000001_add_jobs_table::Migration),
Box::new(m20240606_000001_add_audience_to_objects::Migration),
]
}
}

View file

@ -65,6 +65,7 @@ pub enum Objects {
Bto,
Published,
Updated,
Audience, // added with migration m20240606_000001
}
#[derive(DeriveIden)]

View file

@ -0,0 +1,35 @@
use sea_orm_migration::prelude::*;
use crate::m20240524_000001_create_actor_activity_object_tables::Objects;
#[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(Objects::Table)
.add_column(ColumnDef::new(Objects::Audience).string().null())
.to_owned()
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Objects::Table)
.drop_column(Objects::Audience)
.to_owned()
)
.await?;
Ok(())
}
}