mirror of
https://github.com/versia-pub/activitypub.git
synced 2025-12-06 06:38:20 +01:00
fix: format files
This commit is contained in:
parent
489a216aca
commit
cd6ff024e4
|
|
@ -1,5 +1,5 @@
|
||||||
use sea_orm_migration::prelude::*;
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
#[async_std::main]
|
#[async_std::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
|
|
||||||
12
src/http.rs
12
src/http.rs
|
|
@ -1,5 +1,9 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
database::StateHandle, entities::user, error::Error, lysand::{self, conversion::receive_lysand_note}, objects::person::{DbUser, PersonAcceptedActivities}
|
database::StateHandle,
|
||||||
|
entities::user,
|
||||||
|
error::Error,
|
||||||
|
lysand::{self, conversion::receive_lysand_note},
|
||||||
|
objects::person::{DbUser, PersonAcceptedActivities},
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
actix_web::{inbox::receive_activity, signing_actor},
|
actix_web::{inbox::receive_activity, signing_actor},
|
||||||
|
|
@ -33,7 +37,11 @@ pub fn listen(config: &FederationConfig<StateHandle>) -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lysand_inbox(note: web::Json<lysand::objects::Note>, id: web::Path<String>, data: Data<StateHandle>) -> Result<HttpResponse, Error> {
|
pub fn lysand_inbox(
|
||||||
|
note: web::Json<lysand::objects::Note>,
|
||||||
|
id: web::Path<String>,
|
||||||
|
data: Data<StateHandle>,
|
||||||
|
) -> Result<HttpResponse, Error> {
|
||||||
tokio::spawn(receive_lysand_note(note.into_inner(), id.into_inner()));
|
tokio::spawn(receive_lysand_note(note.into_inner(), id.into_inner()));
|
||||||
Ok(HttpResponse::Created().finish())
|
Ok(HttpResponse::Created().finish())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,23 @@
|
||||||
use activitypub_federation::{fetch::object_id::ObjectId, http_signatures::generate_actor_keypair};
|
use activitypub_federation::{fetch::object_id::ObjectId, http_signatures::generate_actor_keypair};
|
||||||
use activitystreams_kinds::public;
|
use activitystreams_kinds::public;
|
||||||
|
use anyhow::{anyhow, Ok};
|
||||||
|
use async_recursion::async_recursion;
|
||||||
use chrono::{DateTime, TimeZone, Utc};
|
use chrono::{DateTime, TimeZone, Utc};
|
||||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
|
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter, Set};
|
||||||
use anyhow::{anyhow, Ok};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use async_recursion::async_recursion;
|
|
||||||
|
|
||||||
use crate::{database::State, entities::{self, post, prelude, user}, objects::post::Mention, utils::{generate_object_id, generate_user_id}, API_DOMAIN, DB, FEDERATION_CONFIG, LYSAND_DOMAIN};
|
use crate::{
|
||||||
|
database::State,
|
||||||
|
entities::{self, post, prelude, user},
|
||||||
|
objects::post::Mention,
|
||||||
|
utils::{generate_object_id, generate_user_id},
|
||||||
|
API_DOMAIN, DB, FEDERATION_CONFIG, LYSAND_DOMAIN,
|
||||||
|
};
|
||||||
|
|
||||||
use super::{objects::{ContentFormat, Note}, superx::request_client};
|
use super::{
|
||||||
|
objects::{ContentFormat, Note},
|
||||||
|
superx::request_client,
|
||||||
|
};
|
||||||
|
|
||||||
pub async fn fetch_user_from_url(url: Url) -> anyhow::Result<super::objects::User> {
|
pub async fn fetch_user_from_url(url: Url) -> anyhow::Result<super::objects::User> {
|
||||||
let req_client = request_client();
|
let req_client = request_client();
|
||||||
|
|
@ -29,7 +38,10 @@ pub async fn db_post_from_url(url: Url) -> anyhow::Result<entities::post::Model>
|
||||||
return Err(anyhow!("not lysands domain"));
|
return Err(anyhow!("not lysands domain"));
|
||||||
}
|
}
|
||||||
let str_url = url.to_string();
|
let str_url = url.to_string();
|
||||||
let post_res: Option<post::Model> = prelude::Post::find().filter(entities::post::Column::Url.eq(str_url.clone())).one(DB.get().unwrap()).await?;
|
let post_res: Option<post::Model> = prelude::Post::find()
|
||||||
|
.filter(entities::post::Column::Url.eq(str_url.clone()))
|
||||||
|
.one(DB.get().unwrap())
|
||||||
|
.await?;
|
||||||
|
|
||||||
if let Some(post) = post_res {
|
if let Some(post) = post_res {
|
||||||
Ok(post)
|
Ok(post)
|
||||||
|
|
@ -44,7 +56,10 @@ pub async fn db_user_from_url(url: Url) -> anyhow::Result<entities::user::Model>
|
||||||
if !url.domain().eq(&Some(LYSAND_DOMAIN.as_str())) {
|
if !url.domain().eq(&Some(LYSAND_DOMAIN.as_str())) {
|
||||||
return Err(anyhow!("not lysands domain"));
|
return Err(anyhow!("not lysands domain"));
|
||||||
}
|
}
|
||||||
let user_res: Option<user::Model> = prelude::User::find().filter(entities::user::Column::Url.eq(url.to_string())).one(DB.get().unwrap()).await?;
|
let user_res: Option<user::Model> = prelude::User::find()
|
||||||
|
.filter(entities::user::Column::Url.eq(url.to_string()))
|
||||||
|
.one(DB.get().unwrap())
|
||||||
|
.await?;
|
||||||
|
|
||||||
if let Some(user) = user_res {
|
if let Some(user) = user_res {
|
||||||
Ok(user)
|
Ok(user)
|
||||||
|
|
@ -63,7 +78,9 @@ pub async fn db_user_from_url(url: Url) -> anyhow::Result<entities::user::Model>
|
||||||
following_count: Set(0),
|
following_count: Set(0),
|
||||||
url: Set(ls_user.uri.to_string()),
|
url: Set(ls_user.uri.to_string()),
|
||||||
local: Set(true),
|
local: Set(true),
|
||||||
created_at: Set(DateTime::from_timestamp(ls_user.created_at.unix_timestamp(), 0).unwrap()),
|
created_at: Set(
|
||||||
|
DateTime::from_timestamp(ls_user.created_at.unix_timestamp(), 0).unwrap(),
|
||||||
|
),
|
||||||
summary: Set(option_content_format_text(ls_user.bio).await),
|
summary: Set(option_content_format_text(ls_user.bio).await),
|
||||||
updated_at: Set(Some(Utc::now())),
|
updated_at: Set(Some(Utc::now())),
|
||||||
followers: Set(Some(ls_user.followers.to_string())),
|
followers: Set(Some(ls_user.followers.to_string())),
|
||||||
|
|
@ -81,35 +98,58 @@ pub async fn fetch_note_from_url(url: Url) -> anyhow::Result<super::objects::Not
|
||||||
Ok(request.json::<super::objects::Note>().await?)
|
Ok(request.json::<super::objects::Note>().await?)
|
||||||
}
|
}
|
||||||
#[async_recursion]
|
#[async_recursion]
|
||||||
pub async fn receive_lysand_note(note: Note, db_id: String) -> anyhow::Result<entities::post::Model> {
|
pub async fn receive_lysand_note(
|
||||||
|
note: Note,
|
||||||
|
db_id: String,
|
||||||
|
) -> anyhow::Result<entities::post::Model> {
|
||||||
let lysand_author: entities::user::Model = db_user_from_url(note.author.clone()).await?;
|
let lysand_author: entities::user::Model = db_user_from_url(note.author.clone()).await?;
|
||||||
let user_res = prelude::User::find_by_id(db_id).one(DB.get().unwrap()).await;
|
let user_res = prelude::User::find_by_id(db_id)
|
||||||
|
.one(DB.get().unwrap())
|
||||||
|
.await;
|
||||||
if user_res.is_err() {
|
if user_res.is_err() {
|
||||||
println!("{}", user_res.as_ref().unwrap_err());
|
println!("{}", user_res.as_ref().unwrap_err());
|
||||||
return Err(user_res.err().unwrap().into());
|
return Err(user_res.err().unwrap().into());
|
||||||
}
|
}
|
||||||
if let Some(target) = user_res? {
|
if let Some(target) = user_res? {
|
||||||
let data = FEDERATION_CONFIG.get().unwrap();
|
let data = FEDERATION_CONFIG.get().unwrap();
|
||||||
let id: ObjectId<post::Model> = generate_object_id(data.domain(), ¬e.id.to_string())?.into();
|
let id: ObjectId<post::Model> =
|
||||||
|
generate_object_id(data.domain(), ¬e.id.to_string())?.into();
|
||||||
let user_id = generate_user_id(data.domain(), &target.id.to_string())?;
|
let user_id = generate_user_id(data.domain(), &target.id.to_string())?;
|
||||||
let user = fetch_user_from_url(note.author.clone()).await?;
|
let user = fetch_user_from_url(note.author.clone()).await?;
|
||||||
let data = FEDERATION_CONFIG.get().unwrap();
|
let data = FEDERATION_CONFIG.get().unwrap();
|
||||||
let mut tag: Vec<Mention> = Vec::new();
|
let mut tag: Vec<Mention> = Vec::new();
|
||||||
for l_tag in note.mentions.clone().unwrap_or_default() {
|
for l_tag in note.mentions.clone().unwrap_or_default() {
|
||||||
tag.push(Mention { href: l_tag, //TODO convert to ap url
|
tag.push(Mention {
|
||||||
kind: Default::default(), })
|
href: l_tag, //TODO convert to ap url
|
||||||
|
kind: Default::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
let to = match note
|
||||||
|
.visibility
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(super::objects::VisibilityType::Public)
|
||||||
|
{
|
||||||
|
super::objects::VisibilityType::Public => {
|
||||||
|
vec![public(), Url::parse(&user.followers.to_string().as_str())?]
|
||||||
|
}
|
||||||
|
super::objects::VisibilityType::Followers => {
|
||||||
|
vec![Url::parse(&user.followers.to_string().as_str())?]
|
||||||
}
|
}
|
||||||
let to = match note.visibility.clone().unwrap_or(super::objects::VisibilityType::Public) {
|
|
||||||
super::objects::VisibilityType::Public => vec![public(), Url::parse(&user.followers.to_string().as_str())?],
|
|
||||||
super::objects::VisibilityType::Followers => vec![Url::parse(&user.followers.to_string().as_str())?],
|
|
||||||
super::objects::VisibilityType::Direct => note.mentions.unwrap_or_default(),
|
super::objects::VisibilityType::Direct => note.mentions.unwrap_or_default(),
|
||||||
super::objects::VisibilityType::Unlisted => vec![Url::parse(&user.followers.to_string().as_str())?],
|
super::objects::VisibilityType::Unlisted => {
|
||||||
|
vec![Url::parse(&user.followers.to_string().as_str())?]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let cc = match note.visibility.clone().unwrap_or(super::objects::VisibilityType::Public) {
|
let cc = match note
|
||||||
|
.visibility
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(super::objects::VisibilityType::Public)
|
||||||
|
{
|
||||||
super::objects::VisibilityType::Unlisted => Some(vec![public()]),
|
super::objects::VisibilityType::Unlisted => Some(vec![public()]),
|
||||||
_ => None
|
_ => None,
|
||||||
};
|
};
|
||||||
let reply: Option<ObjectId<entities::post::Model>> = if let Some(rep) = note.replies_to.clone() {
|
let reply: Option<ObjectId<entities::post::Model>> =
|
||||||
|
if let Some(rep) = note.replies_to.clone() {
|
||||||
let note = fetch_note_from_url(rep).await?;
|
let note = fetch_note_from_url(rep).await?;
|
||||||
let fake_rep_url = Url::parse(&format!(
|
let fake_rep_url = Url::parse(&format!(
|
||||||
"https://{}/apbridge/object/{}",
|
"https://{}/apbridge/object/{}",
|
||||||
|
|
@ -120,7 +160,8 @@ pub async fn receive_lysand_note(note: Note, db_id: String) -> anyhow::Result<en
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let quote: Option<ObjectId<entities::post::Model>> = if let Some(rep) = note.quotes.clone() {
|
let quote: Option<ObjectId<entities::post::Model>> = if let Some(rep) = note.quotes.clone()
|
||||||
|
{
|
||||||
let note = fetch_note_from_url(rep).await?;
|
let note = fetch_note_from_url(rep).await?;
|
||||||
let fake_rep_url = Url::parse(&format!(
|
let fake_rep_url = Url::parse(&format!(
|
||||||
"https://{}/apbridge/object/{}",
|
"https://{}/apbridge/object/{}",
|
||||||
|
|
@ -149,11 +190,17 @@ pub async fn receive_lysand_note(note: Note, db_id: String) -> anyhow::Result<en
|
||||||
to,
|
to,
|
||||||
tag,
|
tag,
|
||||||
attributed_to: Url::parse(user.uri.clone().as_str()).unwrap().into(),
|
attributed_to: Url::parse(user.uri.clone().as_str()).unwrap().into(),
|
||||||
content: option_content_format_text(note.content).await.unwrap_or_default(),
|
content: option_content_format_text(note.content)
|
||||||
in_reply_to: reply.clone()
|
.await
|
||||||
|
.unwrap_or_default(),
|
||||||
|
in_reply_to: reply.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let visibility = match note.visibility.clone().unwrap_or(super::objects::VisibilityType::Public) {
|
let visibility = match note
|
||||||
|
.visibility
|
||||||
|
.clone()
|
||||||
|
.unwrap_or(super::objects::VisibilityType::Public)
|
||||||
|
{
|
||||||
super::objects::VisibilityType::Public => "public",
|
super::objects::VisibilityType::Public => "public",
|
||||||
super::objects::VisibilityType::Followers => "followers",
|
super::objects::VisibilityType::Followers => "followers",
|
||||||
super::objects::VisibilityType::Direct => "direct",
|
super::objects::VisibilityType::Direct => "direct",
|
||||||
|
|
@ -170,7 +217,9 @@ pub async fn receive_lysand_note(note: Note, db_id: String) -> anyhow::Result<en
|
||||||
creator: Set(lysand_author.id.clone()),
|
creator: Set(lysand_author.id.clone()),
|
||||||
content: Set(ap_note.content.clone()),
|
content: Set(ap_note.content.clone()),
|
||||||
sensitive: Set(ap_note.sensitive),
|
sensitive: Set(ap_note.sensitive),
|
||||||
created_at: Set(Utc.timestamp_micros(note.created_at.unix_timestamp()).unwrap()),
|
created_at: Set(Utc
|
||||||
|
.timestamp_micros(note.created_at.unix_timestamp())
|
||||||
|
.unwrap()),
|
||||||
local: Set(true),
|
local: Set(true),
|
||||||
updated_at: Set(Some(Utc::now())),
|
updated_at: Set(Some(Utc::now())),
|
||||||
content_type: Set("Note".to_string()),
|
content_type: Set("Note".to_string()),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -2,7 +2,14 @@ use activitypub_federation::{traits::Object, FEDERATION_CONTENT_TYPE};
|
||||||
use actix_web::{get, web, HttpResponse};
|
use actix_web::{get, web, HttpResponse};
|
||||||
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
|
||||||
|
|
||||||
use crate::{database::State, entities::{post::{self, Entity}, prelude}, error, Response, DB, FEDERATION_CONFIG};
|
use crate::{
|
||||||
|
database::State,
|
||||||
|
entities::{
|
||||||
|
post::{self, Entity},
|
||||||
|
prelude,
|
||||||
|
},
|
||||||
|
error, Response, DB, FEDERATION_CONFIG,
|
||||||
|
};
|
||||||
|
|
||||||
#[get("/apbridge/object/{post}")]
|
#[get("/apbridge/object/{post}")]
|
||||||
async fn fetch_post(
|
async fn fetch_post(
|
||||||
|
|
@ -21,5 +28,10 @@ async fn fetch_post(
|
||||||
None => return Ok(HttpResponse::NotFound().finish()),
|
None => return Ok(HttpResponse::NotFound().finish()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().content_type(FEDERATION_CONTENT_TYPE).json(post.into_json(&FEDERATION_CONFIG.get().unwrap().to_request_data()).await?))
|
Ok(HttpResponse::Ok()
|
||||||
|
.content_type(FEDERATION_CONTENT_TYPE)
|
||||||
|
.json(
|
||||||
|
post.into_json(&FEDERATION_CONFIG.get().unwrap().to_request_data())
|
||||||
|
.await?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
pub mod objects;
|
|
||||||
pub mod superx;
|
|
||||||
pub mod test;
|
|
||||||
pub mod conversion;
|
pub mod conversion;
|
||||||
pub mod funcs;
|
pub mod funcs;
|
||||||
pub mod http;
|
pub mod http;
|
||||||
|
pub mod objects;
|
||||||
|
pub mod superx;
|
||||||
|
pub mod test;
|
||||||
|
|
|
||||||
|
|
@ -116,16 +116,16 @@ pub struct ContentFormat {
|
||||||
impl ContentFormat {
|
impl ContentFormat {
|
||||||
pub async fn select_rich_text(&self) -> anyhow::Result<String> {
|
pub async fn select_rich_text(&self) -> anyhow::Result<String> {
|
||||||
if let Some(entry) = self.x.get("text/x.misskeymarkdown") {
|
if let Some(entry) = self.x.get("text/x.misskeymarkdown") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("text/html") {
|
if let Some(entry) = self.x.get("text/html") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("text/markdown") {
|
if let Some(entry) = self.x.get("text/markdown") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("text/plain") {
|
if let Some(entry) = self.x.get("text/plain") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self.x.clone().values().next().unwrap().content.clone())
|
Ok(self.x.clone().values().next().unwrap().content.clone())
|
||||||
|
|
@ -133,25 +133,25 @@ impl ContentFormat {
|
||||||
|
|
||||||
pub async fn select_rich_img(&self) -> anyhow::Result<String> {
|
pub async fn select_rich_img(&self) -> anyhow::Result<String> {
|
||||||
if let Some(entry) = self.x.get("image/webp") {
|
if let Some(entry) = self.x.get("image/webp") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("image/png") {
|
if let Some(entry) = self.x.get("image/png") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("image/avif") {
|
if let Some(entry) = self.x.get("image/avif") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("image/jxl") {
|
if let Some(entry) = self.x.get("image/jxl") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("image/jpeg") {
|
if let Some(entry) = self.x.get("image/jpeg") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("image/gif") {
|
if let Some(entry) = self.x.get("image/gif") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
if let Some(entry) = self.x.get("image/bmp") {
|
if let Some(entry) = self.x.get("image/bmp") {
|
||||||
return Ok(entry.content.clone())
|
return Ok(entry.content.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(self.x.clone().values().next().unwrap().content.clone())
|
Ok(self.x.clone().values().next().unwrap().content.clone())
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,15 @@ async fn test_user_serial() {
|
||||||
let response = client
|
let response = client
|
||||||
.get("https://social.lysand.org/users/018ec082-0ae1-761c-b2c5-22275a611771")
|
.get("https://social.lysand.org/users/018ec082-0ae1-761c-b2c5-22275a611771")
|
||||||
.send()
|
.send()
|
||||||
.await.unwrap();
|
.await
|
||||||
let user = super::superx::deserialize_user(response.text().await.unwrap()).await.unwrap();
|
.unwrap();
|
||||||
|
let user = super::superx::deserialize_user(response.text().await.unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let response_outbox = client.get(user.outbox.as_str()).send().await.unwrap();
|
let response_outbox = client.get(user.outbox.as_str()).send().await.unwrap();
|
||||||
let outbox = super::superx::deserialize_outbox(response_outbox.text().await.unwrap()).await.unwrap();
|
let outbox = super::superx::deserialize_outbox(response_outbox.text().await.unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
assert!(outbox.items.len() > 0);
|
assert!(outbox.items.len() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,7 +50,11 @@ pub async fn main() -> anyhow::Result<()> {
|
||||||
|
|
||||||
println!("\n\n\nas AP:");
|
println!("\n\n\nas AP:");
|
||||||
for item in outbox.items {
|
for item in outbox.items {
|
||||||
let ap_item = super::conversion::receive_lysand_note(item, "https://ap.lysand.org/example".to_string()).await?;
|
let ap_item = super::conversion::receive_lysand_note(
|
||||||
|
item,
|
||||||
|
"https://ap.lysand.org/example".to_string(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
println!("{:#?}", ap_item);
|
println!("{:#?}", ap_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ use crate::{
|
||||||
objects::post::{Mention, Note},
|
objects::post::{Mention, Note},
|
||||||
};
|
};
|
||||||
use crate::{activities::follow::Follow, entities::user};
|
use crate::{activities::follow::Follow, entities::user};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
mod activities;
|
mod activities;
|
||||||
mod database;
|
mod database;
|
||||||
|
|
@ -96,7 +96,7 @@ async fn post_manually(
|
||||||
content: format!("{} {}", path.1, target.name),
|
content: format!("{} {}", path.1, target.name),
|
||||||
tag: vec![mention],
|
tag: vec![mention],
|
||||||
in_reply_to: None,
|
in_reply_to: None,
|
||||||
cc: vec![].into()
|
cc: vec![].into(),
|
||||||
};
|
};
|
||||||
|
|
||||||
CreatePost::send(
|
CreatePost::send(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
activities::create_post::CreatePost, database::StateHandle, entities::{post, user}, error::Error, lysand::conversion::db_user_from_url, objects::person::DbUser, utils::generate_object_id
|
activities::create_post::CreatePost,
|
||||||
|
database::StateHandle,
|
||||||
|
entities::{post, user},
|
||||||
|
error::Error,
|
||||||
|
lysand::conversion::db_user_from_url,
|
||||||
|
objects::person::DbUser,
|
||||||
|
utils::generate_object_id,
|
||||||
};
|
};
|
||||||
use activitypub_federation::{
|
use activitypub_federation::{
|
||||||
config::Data,
|
config::Data,
|
||||||
|
|
@ -57,17 +63,24 @@ impl Object for post::Model {
|
||||||
) -> Result<Option<Self>, Self::Error> {
|
) -> Result<Option<Self>, Self::Error> {
|
||||||
let post = crate::entities::prelude::Post::find()
|
let post = crate::entities::prelude::Post::find()
|
||||||
.filter(post::Column::Id.eq(object_id.to_string()))
|
.filter(post::Column::Id.eq(object_id.to_string()))
|
||||||
.one(data.app_data().database_connection.clone().as_ref()).await;
|
.one(data.app_data().database_connection.clone().as_ref())
|
||||||
|
.await;
|
||||||
Ok(post.unwrap())
|
Ok(post.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
|
async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
|
||||||
let creator = db_user_from_url(Url::parse(self.creator.as_str()).unwrap()).await?;
|
let creator = db_user_from_url(Url::parse(self.creator.as_str()).unwrap()).await?;
|
||||||
let to = match self.visibility.as_str() {
|
let to = match self.visibility.as_str() {
|
||||||
"public" => vec![public(), Url::parse(creator.followers.unwrap().as_str()).unwrap()],
|
"public" => vec![
|
||||||
|
public(),
|
||||||
|
Url::parse(creator.followers.unwrap().as_str()).unwrap(),
|
||||||
|
],
|
||||||
"followers" => vec![Url::parse(creator.followers.unwrap().as_str()).unwrap()],
|
"followers" => vec![Url::parse(creator.followers.unwrap().as_str()).unwrap()],
|
||||||
"direct" => vec![], //TODO: implement this
|
"direct" => vec![], //TODO: implement this
|
||||||
"unlisted" => vec![Url::parse(creator.followers.unwrap().as_str()).unwrap(), public()],
|
"unlisted" => vec![
|
||||||
|
Url::parse(creator.followers.unwrap().as_str()).unwrap(),
|
||||||
|
public(),
|
||||||
|
],
|
||||||
_ => vec![public()],
|
_ => vec![public()],
|
||||||
};
|
};
|
||||||
Ok(Note {
|
Ok(Note {
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,8 @@ pub fn generate_random_object_id(domain: &str) -> Result<Url, ParseError> {
|
||||||
|
|
||||||
/// Generate a follow accept id
|
/// Generate a follow accept id
|
||||||
pub fn generate_follow_accept_id(domain: &str, db_id: i32) -> Result<Url, ParseError> {
|
pub fn generate_follow_accept_id(domain: &str, db_id: i32) -> Result<Url, ParseError> {
|
||||||
Url::parse(&format!("https://{}/apbridge/activity/follow/{}", domain, db_id))
|
Url::parse(&format!(
|
||||||
|
"https://{}/apbridge/activity/follow/{}",
|
||||||
|
domain, db_id
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue