From 5949bb9bf3545d5a157f0129f11d99a7723f51d5 Mon Sep 17 00:00:00 2001 From: April John Date: Sat, 27 Jul 2024 16:24:04 +0200 Subject: [PATCH] fix: formatting & DB --- ...0725_120932_follow_table_two_point_zero.rs | 6 +- src/lysand/conversion.rs | 4 +- src/lysand/objects.rs | 62 +++++++++++++++++++ src/main.rs | 2 +- src/objects/person.rs | 6 +- 5 files changed, 69 insertions(+), 11 deletions(-) diff --git a/migration/src/m20240725_120932_follow_table_two_point_zero.rs b/migration/src/m20240725_120932_follow_table_two_point_zero.rs index 8c9f25f..b91c10e 100644 --- a/migration/src/m20240725_120932_follow_table_two_point_zero.rs +++ b/migration/src/m20240725_120932_follow_table_two_point_zero.rs @@ -41,11 +41,7 @@ impl MigrationTrait for Migration { .col(ColumnDef::new(FollowRelation::ApAcceptId).string()) .col(ColumnDef::new(FollowRelation::Remote).boolean().not_null()) .col(ColumnDef::new(FollowRelation::ApJson).string().not_null()) - .col( - ColumnDef::new(FollowRelation::ApAcceptJson) - .string() - .not_null(), - ) + .col(ColumnDef::new(FollowRelation::ApAcceptJson).string()) .foreign_key( ForeignKey::create() .name("fk_follow_relation_followee_id") diff --git a/src/lysand/conversion.rs b/src/lysand/conversion.rs index 09f9240..0401be4 100644 --- a/src/lysand/conversion.rs +++ b/src/lysand/conversion.rs @@ -189,9 +189,7 @@ pub async fn lysand_user_from_db( } content_type_header.unwrap().to_str().unwrap().to_string() }); - content_format - .x - .insert(media_type, content_entry); + content_format.x.insert(media_type, content_entry); let mut name = tag.name.chars(); name.next(); name.next_back(); diff --git a/src/lysand/objects.rs b/src/lysand/objects.rs index 5344577..7b1b7a6 100644 --- a/src/lysand/objects.rs +++ b/src/lysand/objects.rs @@ -354,6 +354,44 @@ pub struct Note { //TODO extensions } +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct Patch { + #[serde(rename = "type")] + pub rtype: LysandType, + pub id: Uuid, + pub uri: Url, + pub author: Url, + #[serde(with = "iso_lysand")] + pub created_at: OffsetDateTime, + #[serde(with = "iso_lysand")] + pub patched_at: OffsetDateTime, + #[serde(skip_serializing_if = "Option::is_none")] + pub category: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub content: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub device: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub previews: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub group: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub attachments: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub replies_to: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub quotes: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub mentions: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub subject: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub is_sensitive: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub visibility: Option, + //TODO extensions +} + #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Outbox { pub first: Url, @@ -364,3 +402,27 @@ pub struct Outbox { pub prev: Option, pub items: Vec, } + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct Follow { + #[serde(rename = "type")] + pub rtype: LysandType, + pub id: Uuid, + pub uri: Url, + pub author: Url, + #[serde(with = "iso_lysand")] + pub created_at: OffsetDateTime, + pub followee: Url, +} + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct FollowResult { + #[serde(rename = "type")] + pub rtype: LysandType, + pub id: Uuid, + pub uri: Url, + pub author: Url, + #[serde(with = "iso_lysand")] + pub created_at: OffsetDateTime, + pub follower: Url, +} diff --git a/src/main.rs b/src/main.rs index 9ae9593..61dc1b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,7 +19,6 @@ use lysand::http::{create_activity, fetch_lysand_post, fetch_post, fetch_user, q use objects::person::{DbUser, Person}; use sea_orm::{ActiveModelTrait, DatabaseConnection, Set}; use serde::{Deserialize, Serialize}; -use uuid::Uuid; use std::{ collections::HashMap, env, @@ -30,6 +29,7 @@ use tokio::signal; use tracing::{info, instrument::WithSubscriber}; use url::Url; use utils::generate_object_id; +use uuid::Uuid; use crate::{ activities::create_post::CreatePost, diff --git a/src/objects/person.rs b/src/objects/person.rs index a5a0a8d..88c9c77 100644 --- a/src/objects/person.rs +++ b/src/objects/person.rs @@ -5,7 +5,8 @@ use crate::{ }, database::{State, StateHandle}, entities::{self, user}, - error::Error, API_DOMAIN, + error::Error, + API_DOMAIN, }; use activitypub_federation::{ config::Data, @@ -227,7 +228,8 @@ impl Actor for user::Model { "https://{}/apbridge/user/{}", API_DOMAIN.to_string(), &self.id - )).unwrap() + )) + .unwrap() } fn public_key_pem(&self) -> &str {