chore: removed deprecated constructors

This commit is contained in:
əlemi 2024-06-06 20:43:27 +02:00
parent 5cfd16ea35
commit 15e9118ed2
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 3 additions and 104 deletions

View file

@ -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 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 {
pub fn ap(self) -> serde_json::Value {
apb::new()

View file

@ -1,6 +1,6 @@
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)]
#[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 {
pub fn ap(self) -> serde_json::Value {
apb::new()
@ -220,13 +189,3 @@ impl Model {
.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())
}

View file

@ -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 super::Audience;
@ -142,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 {
pub fn ap(self) -> serde_json::Value {
apb::new()