forked from nutomic/lemmy
Merge pull request 'Update to latest activitystreams' (#1) from asonix/lemmy:federation into federation
This commit is contained in:
commit
785509e14c
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"
|
||||
dotenv = "0.15.0"
|
||||
bcrypt = "0.6.1"
|
||||
activitystreams = "0.5.0-alpha.7"
|
||||
activitystreams = "0.5.0-alpha.10"
|
||||
chrono = { version = "0.4.7", features = ["serde"] }
|
||||
failure = "0.1.5"
|
||||
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::establish_unpooled_connection;
|
||||
use crate::db::post_view::{PostQueryBuilder, PostView};
|
||||
use activitystreams::collection::apub::OrderedCollection;
|
||||
use activitystreams::collection::OrderedCollection;
|
||||
use activitystreams::{
|
||||
actor::apub::Group, collection::apub::UnorderedCollection, context,
|
||||
actor::{properties::ApActorProperties, Group},
|
||||
collection::UnorderedCollection,
|
||||
context,
|
||||
ext::Extensible,
|
||||
object::properties::ObjectProperties,
|
||||
};
|
||||
use actix_web::body::Body;
|
||||
|
@ -50,13 +53,14 @@ pub async fn get_apub_community(
|
|||
oprops.set_summary_xsd_string(d)?;
|
||||
}
|
||||
|
||||
group
|
||||
.ap_actor_props
|
||||
let mut actor_props = ApActorProperties::default();
|
||||
|
||||
actor_props
|
||||
.set_inbox(format!("{}/inbox", &base_url))?
|
||||
.set_outbox(format!("{}/outbox", &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(
|
||||
|
@ -79,7 +83,7 @@ pub async fn get_apub_community_followers(
|
|||
collection
|
||||
.collection_props
|
||||
.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(
|
||||
|
@ -111,5 +115,5 @@ pub async fn get_apub_community_outbox(
|
|||
)?
|
||||
.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 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()
|
||||
.content_type("application/activity+json")
|
||||
.body(json_data)
|
||||
.json(json)
|
||||
}
|
||||
|
||||
enum EndpointType {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
||||
use crate::convert_datetime;
|
||||
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::web::Path;
|
||||
use actix_web::{web, HttpResponse};
|
||||
|
@ -22,9 +22,7 @@ pub async fn get_apub_post(
|
|||
let id = info.post_id.parse::<i32>()?;
|
||||
// TODO: shows error: missing field `user_name`
|
||||
let post = PostView::read(&&db.get()?, id, None)?;
|
||||
Ok(create_apub_response(serde_json::to_string(
|
||||
&post.as_page()?,
|
||||
)?))
|
||||
Ok(create_apub_response(&post.as_page()?))
|
||||
}
|
||||
|
||||
impl PostView {
|
||||
|
|
|
@ -8,10 +8,11 @@ use crate::db::post_view::PostView;
|
|||
use crate::naive_now;
|
||||
use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
|
||||
use crate::settings::Settings;
|
||||
use activitystreams::actor::apub::Group;
|
||||
use activitystreams::collection::apub::{OrderedCollection, UnorderedCollection};
|
||||
use activitystreams::object::apub::Page;
|
||||
use activitystreams::actor::{properties::ApActorProperties, Group};
|
||||
use activitystreams::collection::{OrderedCollection, UnorderedCollection};
|
||||
use activitystreams::ext::Ext;
|
||||
use activitystreams::object::ObjectBox;
|
||||
use activitystreams::object::Page;
|
||||
use failure::Error;
|
||||
use log::warn;
|
||||
use serde::Deserialize;
|
||||
|
@ -71,8 +72,9 @@ where
|
|||
}
|
||||
|
||||
pub fn get_remote_community_posts(identifier: &str) -> Result<GetPostsResponse, Error> {
|
||||
let community = fetch_remote_object::<Group>(&get_remote_community_uri(identifier))?;
|
||||
let outbox_uri = &community.ap_actor_props.get_outbox().to_string();
|
||||
let community =
|
||||
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 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> {
|
||||
let community = fetch_remote_object::<Group>(&get_remote_community_uri(identifier))?;
|
||||
let followers_uri = &community
|
||||
.ap_actor_props
|
||||
.get_followers()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let outbox_uri = &community.ap_actor_props.get_outbox().to_string();
|
||||
let community =
|
||||
fetch_remote_object::<Ext<Group, ApActorProperties>>(&get_remote_community_uri(identifier))?;
|
||||
let followers_uri = &community.extension.get_followers().unwrap().to_string();
|
||||
let outbox_uri = &community.extension.get_outbox().to_string();
|
||||
let outbox = fetch_remote_object::<OrderedCollection>(outbox_uri)?;
|
||||
let followers = fetch_remote_object::<UnorderedCollection>(followers_uri)?;
|
||||
// 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()
|
||||
name: identifier.to_string(),
|
||||
title: community
|
||||
.object_props
|
||||
.as_ref()
|
||||
.get_name_xsd_string()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
description: community
|
||||
.object_props
|
||||
.as_ref()
|
||||
.get_summary_xsd_string()
|
||||
.map(|s| s.to_string()),
|
||||
category_id: -1,
|
||||
creator_id: -1, //community.object_props.get_attributed_to_xsd_any_uri()
|
||||
removed: false,
|
||||
published: community
|
||||
.object_props
|
||||
.as_ref()
|
||||
.get_published()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.naive_local()
|
||||
.to_owned(),
|
||||
updated: community
|
||||
.object_props
|
||||
.as_ref()
|
||||
.get_updated()
|
||||
.map(|u| u.as_ref().to_owned().naive_local()),
|
||||
deleted: false,
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
|
||||
use crate::convert_datetime;
|
||||
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::web::Path;
|
||||
use actix_web::HttpResponse;
|
||||
|
@ -38,12 +43,13 @@ pub async fn get_apub_user(
|
|||
oprops.set_name_xsd_string(i.to_owned())?;
|
||||
}
|
||||
|
||||
person
|
||||
.ap_actor_props
|
||||
let mut actor_props = ApActorProperties::default();
|
||||
|
||||
actor_props
|
||||
.set_inbox(format!("{}/inbox", &base_url))?
|
||||
.set_outbox(format!("{}/outbox", &base_url))?
|
||||
.set_following(format!("{}/following", &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