Compare commits
2 commits
ffa92b4f61
...
15e9118ed2
Author | SHA1 | Date | |
---|---|---|---|
15e9118ed2 | |||
5cfd16ea35 |
8 changed files with 46 additions and 104 deletions
|
@ -83,6 +83,7 @@ pub async fn faker(ctx: upub::Context, count: i64) -> Result<(), sea_orm::DbErr>
|
||||||
replies: Set(0),
|
replies: Set(0),
|
||||||
likes: Set(0),
|
likes: Set(0),
|
||||||
announces: Set(0),
|
announces: Set(0),
|
||||||
|
audience: Set(None),
|
||||||
to: Set(Audience(vec![apb::target::PUBLIC.to_string()])),
|
to: Set(Audience(vec![apb::target::PUBLIC.to_string()])),
|
||||||
bto: Set(Audience::default()),
|
bto: Set(Audience::default()),
|
||||||
cc: Set(Audience(vec![])),
|
cc: Set(Audience(vec![])),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use apb::{field::OptionalString, ActivityMut, ActivityType, BaseMut, ObjectMut};
|
use apb::{ActivityMut, ActivityType, BaseMut, ObjectMut};
|
||||||
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
||||||
|
|
||||||
use crate::model::Audience;
|
use crate::model::Audience;
|
||||||
|
@ -79,25 +79,6 @@ impl Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveModel {
|
|
||||||
#[deprecated = "use AP::activity() from processor::normalize"]
|
|
||||||
pub fn new(activity: &impl apb::Activity) -> Result<Self, apb::FieldErr> {
|
|
||||||
Ok(ActiveModel {
|
|
||||||
internal: sea_orm::ActiveValue::NotSet,
|
|
||||||
id: sea_orm::ActiveValue::Set(activity.id()?.to_string()),
|
|
||||||
activity_type: sea_orm::ActiveValue::Set(activity.activity_type()?),
|
|
||||||
actor: sea_orm::ActiveValue::Set(activity.actor().id()?.to_string()),
|
|
||||||
object: sea_orm::ActiveValue::Set(activity.object().id().str()),
|
|
||||||
target: sea_orm::ActiveValue::Set(activity.target().id().str()),
|
|
||||||
published: sea_orm::ActiveValue::Set(activity.published().unwrap_or(chrono::Utc::now())),
|
|
||||||
to: sea_orm::ActiveValue::Set(activity.to().into()),
|
|
||||||
bto: sea_orm::ActiveValue::Set(activity.bto().into()),
|
|
||||||
cc: sea_orm::ActiveValue::Set(activity.cc().into()),
|
|
||||||
bcc: sea_orm::ActiveValue::Set(activity.bcc().into()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
pub fn ap(self) -> serde_json::Value {
|
pub fn ap(self) -> serde_json::Value {
|
||||||
apb::new()
|
apb::new()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
||||||
|
|
||||||
use apb::{field::OptionalString, Actor, ActorMut, ActorType, BaseMut, DocumentMut, Endpoints, EndpointsMut, Object, ObjectMut, PublicKey, PublicKeyMut};
|
use apb::{ActorMut, ActorType, BaseMut, DocumentMut, EndpointsMut, ObjectMut, PublicKeyMut};
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||||
#[sea_orm(table_name = "actors")]
|
#[sea_orm(table_name = "actors")]
|
||||||
|
@ -150,37 +150,6 @@ impl Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveModel {
|
|
||||||
#[deprecated = "use AP::actor() from processor::normalize"]
|
|
||||||
pub fn new(object: &impl Actor) -> Result<Self, apb::FieldErr> {
|
|
||||||
let ap_id = object.id()?.to_string();
|
|
||||||
let (domain, fallback_preferred_username) = split_user_id(&ap_id);
|
|
||||||
Ok(ActiveModel {
|
|
||||||
internal: sea_orm::ActiveValue::NotSet,
|
|
||||||
domain: sea_orm::ActiveValue::Set(domain),
|
|
||||||
id: sea_orm::ActiveValue::Set(ap_id),
|
|
||||||
preferred_username: sea_orm::ActiveValue::Set(object.preferred_username().unwrap_or(&fallback_preferred_username).to_string()),
|
|
||||||
actor_type: sea_orm::ActiveValue::Set(object.actor_type()?),
|
|
||||||
name: sea_orm::ActiveValue::Set(object.name().str()),
|
|
||||||
summary: sea_orm::ActiveValue::Set(object.summary().str()),
|
|
||||||
icon: sea_orm::ActiveValue::Set(object.icon().get().and_then(|x| x.url().id().str())),
|
|
||||||
image: sea_orm::ActiveValue::Set(object.image().get().and_then(|x| x.url().id().str())),
|
|
||||||
inbox: sea_orm::ActiveValue::Set(object.inbox().id().str()),
|
|
||||||
outbox: sea_orm::ActiveValue::Set(object.outbox().id().str()),
|
|
||||||
shared_inbox: sea_orm::ActiveValue::Set(object.endpoints().get().and_then(|x| x.shared_inbox().str())),
|
|
||||||
followers: sea_orm::ActiveValue::Set(object.followers().id().str()),
|
|
||||||
following: sea_orm::ActiveValue::Set(object.following().id().str()),
|
|
||||||
published: sea_orm::ActiveValue::Set(object.published().unwrap_or(chrono::Utc::now())),
|
|
||||||
updated: sea_orm::ActiveValue::Set(chrono::Utc::now()),
|
|
||||||
following_count: sea_orm::ActiveValue::Set(object.following_count().unwrap_or(0) as i32),
|
|
||||||
followers_count: sea_orm::ActiveValue::Set(object.followers_count().unwrap_or(0) as i32),
|
|
||||||
statuses_count: sea_orm::ActiveValue::Set(object.statuses_count().unwrap_or(0) as i32),
|
|
||||||
public_key: sea_orm::ActiveValue::Set(object.public_key().get().ok_or(apb::FieldErr("publicKey"))?.public_key_pem().to_string()),
|
|
||||||
private_key: sea_orm::ActiveValue::Set(None), // there's no way to transport privkey over AP json, must come from DB
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
pub fn ap(self) -> serde_json::Value {
|
pub fn ap(self) -> serde_json::Value {
|
||||||
apb::new()
|
apb::new()
|
||||||
|
@ -220,13 +189,3 @@ impl Model {
|
||||||
.set_discoverable(Some(true))
|
.set_discoverable(Some(true))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn split_user_id(id: &str) -> (String, String) {
|
|
||||||
let clean = id
|
|
||||||
.replace("http://", "")
|
|
||||||
.replace("https://", "");
|
|
||||||
let mut splits = clean.split('/');
|
|
||||||
let first = splits.next().unwrap_or("");
|
|
||||||
let last = splits.last().unwrap_or(first);
|
|
||||||
(first.to_string(), last.to_string())
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use apb::{field::OptionalString, BaseMut, Collection, CollectionMut, ObjectMut, ObjectType};
|
use apb::{BaseMut, CollectionMut, ObjectMut, ObjectType};
|
||||||
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns};
|
||||||
|
|
||||||
use super::Audience;
|
use super::Audience;
|
||||||
|
@ -28,6 +28,8 @@ pub struct Model {
|
||||||
pub bcc: Audience,
|
pub bcc: Audience,
|
||||||
pub published: ChronoDateTimeUtc,
|
pub published: ChronoDateTimeUtc,
|
||||||
pub updated: ChronoDateTimeUtc,
|
pub updated: ChronoDateTimeUtc,
|
||||||
|
|
||||||
|
pub audience: Option<String>, // added with migration m20240606_000001
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
@ -140,47 +142,6 @@ impl Entity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActiveModel {
|
|
||||||
#[deprecated = "use AP::object() from processor::normalize"]
|
|
||||||
pub fn new(object: &impl apb::Object) -> Result<Self, apb::FieldErr> {
|
|
||||||
let t = object.object_type()?;
|
|
||||||
if matches!(t,
|
|
||||||
apb::ObjectType::Activity(_)
|
|
||||||
| apb::ObjectType::Actor(_)
|
|
||||||
| apb::ObjectType::Collection(_)
|
|
||||||
| apb::ObjectType::Document(_)
|
|
||||||
) {
|
|
||||||
return Err(apb::FieldErr("type"));
|
|
||||||
}
|
|
||||||
Ok(ActiveModel {
|
|
||||||
internal: sea_orm::ActiveValue::NotSet,
|
|
||||||
id: sea_orm::ActiveValue::Set(object.id()?.to_string()),
|
|
||||||
object_type: sea_orm::ActiveValue::Set(t),
|
|
||||||
attributed_to: sea_orm::ActiveValue::Set(object.attributed_to().id().str()),
|
|
||||||
name: sea_orm::ActiveValue::Set(object.name().str()),
|
|
||||||
summary: sea_orm::ActiveValue::Set(object.summary().str()),
|
|
||||||
content: sea_orm::ActiveValue::Set(object.content().str()),
|
|
||||||
context: sea_orm::ActiveValue::Set(object.context().id().str()),
|
|
||||||
in_reply_to: sea_orm::ActiveValue::Set(object.in_reply_to().id().str()),
|
|
||||||
published: sea_orm::ActiveValue::Set(object.published().unwrap_or_else(|_| chrono::Utc::now())),
|
|
||||||
updated: sea_orm::ActiveValue::Set(object.updated().unwrap_or_else(|_| chrono::Utc::now())),
|
|
||||||
url: sea_orm::ActiveValue::Set(object.url().id().str()),
|
|
||||||
replies: sea_orm::ActiveValue::Set(object.replies().get()
|
|
||||||
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32),
|
|
||||||
likes: sea_orm::ActiveValue::Set(object.likes().get()
|
|
||||||
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32),
|
|
||||||
announces: sea_orm::ActiveValue::Set(object.shares().get()
|
|
||||||
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32),
|
|
||||||
to: sea_orm::ActiveValue::Set(object.to().into()),
|
|
||||||
bto: sea_orm::ActiveValue::Set(object.bto().into()),
|
|
||||||
cc: sea_orm::ActiveValue::Set(object.cc().into()),
|
|
||||||
bcc: sea_orm::ActiveValue::Set(object.bcc().into()),
|
|
||||||
|
|
||||||
sensitive: sea_orm::ActiveValue::Set(object.sensitive().unwrap_or(false)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Model {
|
impl Model {
|
||||||
pub fn ap(self) -> serde_json::Value {
|
pub fn ap(self) -> serde_json::Value {
|
||||||
apb::new()
|
apb::new()
|
||||||
|
@ -195,6 +156,7 @@ impl Model {
|
||||||
.set_in_reply_to(apb::Node::maybe_link(self.in_reply_to.clone()))
|
.set_in_reply_to(apb::Node::maybe_link(self.in_reply_to.clone()))
|
||||||
.set_published(Some(self.published))
|
.set_published(Some(self.published))
|
||||||
.set_updated(Some(self.updated))
|
.set_updated(Some(self.updated))
|
||||||
|
.set_audience(apb::Node::maybe_link(self.audience))
|
||||||
.set_to(apb::Node::links(self.to.0.clone()))
|
.set_to(apb::Node::links(self.to.0.clone()))
|
||||||
.set_bto(apb::Node::Empty)
|
.set_bto(apb::Node::Empty)
|
||||||
.set_cc(apb::Node::links(self.cc.0.clone()))
|
.set_cc(apb::Node::links(self.cc.0.clone()))
|
||||||
|
|
|
@ -231,6 +231,7 @@ impl AP {
|
||||||
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32,
|
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32,
|
||||||
announces: object.shares().get()
|
announces: object.shares().get()
|
||||||
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32,
|
.map_or(0, |x| x.total_items().unwrap_or(0)) as i32,
|
||||||
|
audience: object.audience().id().str(),
|
||||||
to: object.to().into(),
|
to: object.to().into(),
|
||||||
bto: object.bto().into(),
|
bto: object.bto().into(),
|
||||||
cc: object.cc().into(),
|
cc: object.cc().into(),
|
||||||
|
|
|
@ -7,6 +7,7 @@ mod m20240524_000004_create_addressing_deliveries;
|
||||||
mod m20240524_000005_create_attachments_tags_mentions;
|
mod m20240524_000005_create_attachments_tags_mentions;
|
||||||
mod m20240529_000001_add_relation_unique_index;
|
mod m20240529_000001_add_relation_unique_index;
|
||||||
mod m20240605_000001_add_jobs_table;
|
mod m20240605_000001_add_jobs_table;
|
||||||
|
mod m20240606_000001_add_audience_to_objects;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ impl MigratorTrait for Migrator {
|
||||||
Box::new(m20240524_000005_create_attachments_tags_mentions::Migration),
|
Box::new(m20240524_000005_create_attachments_tags_mentions::Migration),
|
||||||
Box::new(m20240529_000001_add_relation_unique_index::Migration),
|
Box::new(m20240529_000001_add_relation_unique_index::Migration),
|
||||||
Box::new(m20240605_000001_add_jobs_table::Migration),
|
Box::new(m20240605_000001_add_jobs_table::Migration),
|
||||||
|
Box::new(m20240606_000001_add_audience_to_objects::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ pub enum Objects {
|
||||||
Bto,
|
Bto,
|
||||||
Published,
|
Published,
|
||||||
Updated,
|
Updated,
|
||||||
|
Audience, // added with migration m20240606_000001
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(DeriveIden)]
|
#[derive(DeriveIden)]
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue