static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
+pub enum EndpointType {
+ Community,
+ User,
+ Post,
+ Comment,
+}
+
+pub struct Instance {
+ domain: String,
+}
+
fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
where
T: serde::ser::Serialize,
.json(json)
}
-pub enum EndpointType {
- Community,
- User,
- Post,
- Comment,
-}
-
// TODO: we will probably need to change apub endpoint urls so that html and activity+json content
// types are handled at the same endpoint, so that you can copy the url into mastodon search
// and have it fetch the object.
}
}
-pub fn get_following_instances() -> Vec<&'static str> {
+pub fn get_following_instances() -> Vec<Instance> {
Settings::get()
.federation
.followed_instances
.split(',')
+ .map(|i| Instance {
+ domain: i.to_string(),
+ })
.collect()
}
use std::time::Duration;
use url::Url;
-fn fetch_node_info(domain: &str) -> Result<NodeInfo, Error> {
+fn fetch_node_info(instance: &Instance) -> Result<NodeInfo, Error> {
let well_known_uri = Url::parse(&format!(
"{}://{}/.well-known/nodeinfo",
get_apub_protocol_string(),
- domain
+ instance.domain
))?;
let well_known = fetch_remote_object::<NodeInfoWellKnown>(&well_known_uri)?;
Ok(fetch_remote_object::<NodeInfo>(&well_known.links.href)?)
}
fn fetch_remote_community_posts(
- instance: &str,
+ instance: &Instance,
community: &Community,
conn: &PgConnection,
) -> Result<Vec<Post>, Error> {
+ // TODO: need to add outbox field to Community
let endpoint = Url::parse(&format!(
"http://{}/federation/c/{}",
- instance, community.name
+ instance.domain, community.name
))?;
let group = fetch_remote_object::<GroupExt>(&endpoint)?;
let outbox_uri = Url::parse(&group.extension.get_outbox().to_string())?;
- // TODO: outbox url etc should be stored in local db
let outbox = fetch_remote_object::<OrderedCollection>(&outbox_uri)?;
let items = outbox.collection_props.get_many_items_base_boxes();
} else {
warn!(
"{} is not a Lemmy instance, federation is not supported",
- instance
+ instance.domain
);
}
}