mirror of
https://github.com/versia-pub/activitypub.git
synced 2026-03-13 10:59:17 +01:00
save changes, fake commit
This commit is contained in:
parent
b65a51a1ef
commit
e42baf51e4
8 changed files with 88 additions and 45 deletions
46
src/lysand/conversion.rs
Normal file
46
src/lysand/conversion.rs
Normal 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(), ¬e.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,
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
pub mod objects;
|
||||
pub mod superx;
|
||||
pub mod test;
|
||||
pub mod conversion;
|
||||
|
|
@ -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>,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue