save changes, fake commit

This commit is contained in:
April John 2024-05-19 07:17:13 +02:00
parent b65a51a1ef
commit e42baf51e4
Signed by: aprl
GPG key ID: BCB934A2909C5460
8 changed files with 88 additions and 45 deletions

46
src/lysand/conversion.rs Normal file
View file

@ -0,0 +1,46 @@
use activitypub_federation::fetch::object_id::ObjectId;
use activitystreams_kinds::public;
use sea_orm::{EntityTrait, QueryFilter};
use url::Url;
use crate::{database::State, entities::{self, post, prelude}, objects::post::Mention, utils::{generate_object_id, generate_user_id}, FEDERATION_CONFIG};
use super::objects::Note;
pub async fn receive_lysand_note(note: Note, db_id: String, db: State) {
let author: entities::user::Model = todo!();
let user_res = prelude::User::find_by_id(db_id).one(db.database_connection.as_ref()).await;
if user_res.is_err() {
println!("{}", user_res.unwrap_err());
return;
}
if let Some(target) = user_res.ok().unwrap() {
let data = FEDERATION_CONFIG.get().unwrap();
let id: ObjectId<post::Model> = generate_object_id(data.domain(), &note.id.to_string()).unwrap().into();
let user_id = generate_user_id(data.domain(), &target.id.to_string()).unwrap();
let to = match note.visibility.unwrap_or(super::objects::VisibilityType::Public) {
super::objects::VisibilityType::Public => vec![public(), Url::parse(&author.inbox).unwrap()],
super::objects::VisibilityType::Followers => vec![Url::parse(&author.inbox).unwrap()],
super::objects::VisibilityType::Direct => vec![user_id],
super::objects::VisibilityType::Unlisted => vec![Url::parse(&author.inbox).unwrap()],
};
let cc = match note.visibility.unwrap_or(super::objects::VisibilityType::Public) {
super::objects::VisibilityType::Unlisted => Some(vec![public()]),
_ => None
};
let mut tag: Vec<Mention> = Vec::new();
for l_tag in note.mentions.unwrap_or_default() {
tag.push(Mention { href: l_tag, //todo convert to ap url
kind: Default::default(), })
}
let ap_note = crate::objects::post::Note {
kind: Default::default(),
id,
sensitive: note.is_sensitive.unwrap_or(false),
cc,
to,
tag,
}
}
}

View file

@ -1,3 +1,4 @@
pub mod objects;
pub mod superx;
pub mod test;
pub mod conversion;

View file

@ -58,7 +58,7 @@ pub enum CategoryType {
Image,
Video,
Audio,
Messaging
Messaging,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -66,7 +66,7 @@ pub enum VisibilityType {
Public,
Unlisted,
Followers,
Direct
Direct,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -191,7 +191,7 @@ pub struct LinkPreview {
title: String,
link: Url,
image: Option<Url>,
icon: Option<Url>
icon: Option<Url>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
@ -225,4 +225,4 @@ pub struct Outbox {
pub next: Option<Url>,
pub prev: Option<Url>,
pub items: Vec<Note>,
}
}

View file

@ -22,10 +22,7 @@ pub async fn main() -> anyhow::Result<()> {
let user_json = serde_json::to_string_pretty(&SortAlphabetically(&user))?;
println!("{}", user_json);
let response_outbox = client
.get(user.outbox.as_str())
.send()
.await?;
let response_outbox = client.get(user.outbox.as_str()).send().await?;
let outbox_json = response_outbox.text().await?;
let outbox = super::superx::deserialize_outbox(outbox_json).await?;