mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-10 22:45:02 +00:00
Upgraded to latest activitystreams
This commit is contained in:
parent
af189c59f3
commit
5f6cf64fc7
7 changed files with 241 additions and 231 deletions
394
server/Cargo.lock
generated
vendored
394
server/Cargo.lock
generated
vendored
File diff suppressed because it is too large
Load diff
2
server/Cargo.toml
vendored
2
server/Cargo.toml
vendored
|
@ -9,7 +9,7 @@ diesel = { version = "1.4.2", features = ["postgres","chrono", "r2d2", "64-colum
|
||||||
diesel_migrations = "1.4.0"
|
diesel_migrations = "1.4.0"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
bcrypt = "0.6.1"
|
bcrypt = "0.6.1"
|
||||||
activitystreams = "0.5.0-alpha.7"
|
activitystreams = "0.5.0-alpha.10"
|
||||||
chrono = { version = "0.4.7", features = ["serde"] }
|
chrono = { version = "0.4.7", features = ["serde"] }
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
serde_json = { version = "1.0.45", features = ["preserve_order"]}
|
serde_json = { version = "1.0.45", features = ["preserve_order"]}
|
||||||
|
|
|
@ -4,9 +4,12 @@ use crate::db::community::Community;
|
||||||
use crate::db::community_view::CommunityFollowerView;
|
use crate::db::community_view::CommunityFollowerView;
|
||||||
use crate::db::establish_unpooled_connection;
|
use crate::db::establish_unpooled_connection;
|
||||||
use crate::db::post_view::{PostQueryBuilder, PostView};
|
use crate::db::post_view::{PostQueryBuilder, PostView};
|
||||||
use activitystreams::collection::apub::OrderedCollection;
|
use activitystreams::collection::OrderedCollection;
|
||||||
use activitystreams::{
|
use activitystreams::{
|
||||||
actor::apub::Group, collection::apub::UnorderedCollection, context,
|
actor::{properties::ApActorProperties, Group},
|
||||||
|
collection::UnorderedCollection,
|
||||||
|
context,
|
||||||
|
ext::Extensible,
|
||||||
object::properties::ObjectProperties,
|
object::properties::ObjectProperties,
|
||||||
};
|
};
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
|
@ -50,13 +53,14 @@ pub async fn get_apub_community(
|
||||||
oprops.set_summary_xsd_string(d)?;
|
oprops.set_summary_xsd_string(d)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
group
|
let mut actor_props = ApActorProperties::default();
|
||||||
.ap_actor_props
|
|
||||||
|
actor_props
|
||||||
.set_inbox(format!("{}/inbox", &base_url))?
|
.set_inbox(format!("{}/inbox", &base_url))?
|
||||||
.set_outbox(format!("{}/outbox", &base_url))?
|
.set_outbox(format!("{}/outbox", &base_url))?
|
||||||
.set_followers(format!("{}/followers", &base_url))?;
|
.set_followers(format!("{}/followers", &base_url))?;
|
||||||
|
|
||||||
Ok(create_apub_response(serde_json::to_string(&group)?))
|
Ok(create_apub_response(&group.extend(actor_props)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_apub_community_followers(
|
pub async fn get_apub_community_followers(
|
||||||
|
@ -79,7 +83,7 @@ pub async fn get_apub_community_followers(
|
||||||
collection
|
collection
|
||||||
.collection_props
|
.collection_props
|
||||||
.set_total_items(community_followers.len() as u64)?;
|
.set_total_items(community_followers.len() as u64)?;
|
||||||
Ok(create_apub_response(serde_json::to_string(&collection)?))
|
Ok(create_apub_response(&collection))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_apub_community_outbox(
|
pub async fn get_apub_community_outbox(
|
||||||
|
@ -111,5 +115,5 @@ pub async fn get_apub_community_outbox(
|
||||||
)?
|
)?
|
||||||
.set_total_items(community_posts.len() as u64)?;
|
.set_total_items(community_posts.len() as u64)?;
|
||||||
|
|
||||||
Ok(create_apub_response(serde_json::to_string(&collection)?))
|
Ok(create_apub_response(&collection))
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,13 @@ use actix_web::body::Body;
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
fn create_apub_response(json_data: String) -> HttpResponse<Body> {
|
fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
|
||||||
|
where
|
||||||
|
T: serde::ser::Serialize,
|
||||||
|
{
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("application/activity+json")
|
.content_type("application/activity+json")
|
||||||
.body(json_data)
|
.json(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EndpointType {
|
enum EndpointType {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
||||||
use crate::convert_datetime;
|
use crate::convert_datetime;
|
||||||
use crate::db::post_view::PostView;
|
use crate::db::post_view::PostView;
|
||||||
use activitystreams::{object::apub::Page, object::properties::ObjectProperties};
|
use activitystreams::{object::properties::ObjectProperties, object::Page};
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
use actix_web::web::Path;
|
use actix_web::web::Path;
|
||||||
use actix_web::{web, HttpResponse};
|
use actix_web::{web, HttpResponse};
|
||||||
|
@ -22,9 +22,7 @@ pub async fn get_apub_post(
|
||||||
let id = info.post_id.parse::<i32>()?;
|
let id = info.post_id.parse::<i32>()?;
|
||||||
// TODO: shows error: missing field `user_name`
|
// TODO: shows error: missing field `user_name`
|
||||||
let post = PostView::read(&&db.get()?, id, None)?;
|
let post = PostView::read(&&db.get()?, id, None)?;
|
||||||
Ok(create_apub_response(serde_json::to_string(
|
Ok(create_apub_response(&post.as_page()?))
|
||||||
&post.as_page()?,
|
|
||||||
)?))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PostView {
|
impl PostView {
|
||||||
|
|
|
@ -8,10 +8,11 @@ use crate::db::post_view::PostView;
|
||||||
use crate::naive_now;
|
use crate::naive_now;
|
||||||
use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
|
use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
use activitystreams::actor::apub::Group;
|
use activitystreams::actor::{properties::ApActorProperties, Group};
|
||||||
use activitystreams::collection::apub::{OrderedCollection, UnorderedCollection};
|
use activitystreams::collection::{OrderedCollection, UnorderedCollection};
|
||||||
use activitystreams::object::apub::Page;
|
use activitystreams::ext::Ext;
|
||||||
use activitystreams::object::ObjectBox;
|
use activitystreams::object::ObjectBox;
|
||||||
|
use activitystreams::object::Page;
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -71,8 +72,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_remote_community_posts(identifier: &str) -> Result<GetPostsResponse, Error> {
|
pub fn get_remote_community_posts(identifier: &str) -> Result<GetPostsResponse, Error> {
|
||||||
let community = fetch_remote_object::<Group>(&get_remote_community_uri(identifier))?;
|
let community =
|
||||||
let outbox_uri = &community.ap_actor_props.get_outbox().to_string();
|
fetch_remote_object::<Ext<Group, ApActorProperties>>(&get_remote_community_uri(identifier))?;
|
||||||
|
let outbox_uri = &community.extension.get_outbox().to_string();
|
||||||
let outbox = fetch_remote_object::<OrderedCollection>(outbox_uri)?;
|
let outbox = fetch_remote_object::<OrderedCollection>(outbox_uri)?;
|
||||||
let items = outbox.collection_props.get_many_items_object_boxs();
|
let items = outbox.collection_props.get_many_items_object_boxs();
|
||||||
|
|
||||||
|
@ -125,13 +127,10 @@ pub fn get_remote_community_posts(identifier: &str) -> Result<GetPostsResponse,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_remote_community(identifier: &str) -> Result<GetCommunityResponse, failure::Error> {
|
pub fn get_remote_community(identifier: &str) -> Result<GetCommunityResponse, failure::Error> {
|
||||||
let community = fetch_remote_object::<Group>(&get_remote_community_uri(identifier))?;
|
let community =
|
||||||
let followers_uri = &community
|
fetch_remote_object::<Ext<Group, ApActorProperties>>(&get_remote_community_uri(identifier))?;
|
||||||
.ap_actor_props
|
let followers_uri = &community.extension.get_followers().unwrap().to_string();
|
||||||
.get_followers()
|
let outbox_uri = &community.extension.get_outbox().to_string();
|
||||||
.unwrap()
|
|
||||||
.to_string();
|
|
||||||
let outbox_uri = &community.ap_actor_props.get_outbox().to_string();
|
|
||||||
let outbox = fetch_remote_object::<OrderedCollection>(outbox_uri)?;
|
let outbox = fetch_remote_object::<OrderedCollection>(outbox_uri)?;
|
||||||
let followers = fetch_remote_object::<UnorderedCollection>(followers_uri)?;
|
let followers = fetch_remote_object::<UnorderedCollection>(followers_uri)?;
|
||||||
// TODO: this is only for testing until we can call that function from GetPosts
|
// TODO: this is only for testing until we can call that function from GetPosts
|
||||||
|
@ -146,26 +145,26 @@ pub fn get_remote_community(identifier: &str) -> Result<GetCommunityResponse, fa
|
||||||
id: 1337, //community.object_props.get_id()
|
id: 1337, //community.object_props.get_id()
|
||||||
name: identifier.to_string(),
|
name: identifier.to_string(),
|
||||||
title: community
|
title: community
|
||||||
.object_props
|
.as_ref()
|
||||||
.get_name_xsd_string()
|
.get_name_xsd_string()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string(),
|
.to_string(),
|
||||||
description: community
|
description: community
|
||||||
.object_props
|
.as_ref()
|
||||||
.get_summary_xsd_string()
|
.get_summary_xsd_string()
|
||||||
.map(|s| s.to_string()),
|
.map(|s| s.to_string()),
|
||||||
category_id: -1,
|
category_id: -1,
|
||||||
creator_id: -1, //community.object_props.get_attributed_to_xsd_any_uri()
|
creator_id: -1, //community.object_props.get_attributed_to_xsd_any_uri()
|
||||||
removed: false,
|
removed: false,
|
||||||
published: community
|
published: community
|
||||||
.object_props
|
.as_ref()
|
||||||
.get_published()
|
.get_published()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.naive_local()
|
.naive_local()
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
updated: community
|
updated: community
|
||||||
.object_props
|
.as_ref()
|
||||||
.get_updated()
|
.get_updated()
|
||||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||||
deleted: false,
|
deleted: false,
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
||||||
use crate::convert_datetime;
|
use crate::convert_datetime;
|
||||||
use crate::db::user::User_;
|
use crate::db::user::User_;
|
||||||
use activitystreams::{actor::apub::Person, context, object::properties::ObjectProperties};
|
use activitystreams::{
|
||||||
|
actor::{properties::ApActorProperties, Person},
|
||||||
|
context,
|
||||||
|
ext::Extensible,
|
||||||
|
object::properties::ObjectProperties,
|
||||||
|
};
|
||||||
use actix_web::body::Body;
|
use actix_web::body::Body;
|
||||||
use actix_web::web::Path;
|
use actix_web::web::Path;
|
||||||
use actix_web::HttpResponse;
|
use actix_web::HttpResponse;
|
||||||
|
@ -38,12 +43,13 @@ pub async fn get_apub_user(
|
||||||
oprops.set_name_xsd_string(i.to_owned())?;
|
oprops.set_name_xsd_string(i.to_owned())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
person
|
let mut actor_props = ApActorProperties::default();
|
||||||
.ap_actor_props
|
|
||||||
|
actor_props
|
||||||
.set_inbox(format!("{}/inbox", &base_url))?
|
.set_inbox(format!("{}/inbox", &base_url))?
|
||||||
.set_outbox(format!("{}/outbox", &base_url))?
|
.set_outbox(format!("{}/outbox", &base_url))?
|
||||||
.set_following(format!("{}/following", &base_url))?
|
.set_following(format!("{}/following", &base_url))?
|
||||||
.set_liked(format!("{}/liked", &base_url))?;
|
.set_liked(format!("{}/liked", &base_url))?;
|
||||||
|
|
||||||
Ok(create_apub_response(serde_json::to_string(&person)?))
|
Ok(create_apub_response(&person.extend(actor_props)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue