use super::*;
-use crate::apub::puller::{get_all_communities, get_remote_community};
+use crate::apub::puller::{fetch_all_communities, fetch_remote_community};
use crate::apub::{gen_keypair_str, make_apub_endpoint, EndpointType};
use crate::settings::Settings;
use diesel::PgConnection;
&& Settings::get().federation.enabled
&& data.name.as_ref().unwrap().contains('@')
{
- return get_remote_community(data.name.as_ref().unwrap());
+ return fetch_remote_community(data.name.as_ref().unwrap());
}
let user_id: Option<i32> = match &data.auth {
let local_only = data.local_only.unwrap_or(false);
if Settings::get().federation.enabled && !local_only {
return Ok(ListCommunitiesResponse {
- communities: get_all_communities()?,
+ communities: fetch_all_communities()?,
});
}
-use crate::apub::puller::{fetch_remote_object, format_community_name};
-use crate::apub::{
- create_apub_response, get_apub_protocol_string, make_apub_endpoint, EndpointType, GroupExt,
-};
+use crate::apub::puller::fetch_remote_object;
+use crate::apub::*;
use crate::convert_datetime;
use crate::db::community::Community;
use crate::db::community_view::{CommunityFollowerView, CommunityView};
fn vec_bytes_to_str(bytes: Vec<u8>) -> String {
String::from_utf8_lossy(&bytes).into_owned()
}
+
+/// If community is on local instance, don't include the @instance part. This is only for displaying
+/// to the user and should never be used otherwise.
+pub fn format_community_name(name: &str, instance: &str) -> String {
+ if instance == Settings::get().hostname {
+ format!("!{}", name)
+ } else {
+ format!("!{}@{}", name, instance)
+ }
+}
+
+pub fn get_following_instances() -> Vec<&'static str> {
+ Settings::get()
+ .federation
+ .followed_instances
+ .split(',')
+ .collect()
+}
+
+/// Returns a tuple of (username, domain) from an identifier like "main@dev.lemmy.ml"
+fn split_identifier(identifier: &str) -> (String, String) {
+ let x: Vec<&str> = identifier.split('@').collect();
+ (x[0].replace("!", ""), x[1].to_string())
+}
+
+fn get_remote_community_uri(identifier: &str) -> String {
+ let (name, domain) = split_identifier(identifier);
+ format!("http://{}/federation/c/{}", domain, name)
+}
use crate::api::community::GetCommunityResponse;
use crate::api::post::GetPostsResponse;
-use crate::apub::{get_apub_protocol_string, GroupExt};
+use crate::apub::*;
use crate::db::community_view::CommunityView;
use crate::db::post_view::PostView;
use crate::routes::nodeinfo::{NodeInfo, NodeInfoWellKnown};
}
}
-/// Returns a tuple of (username, domain) from an identifier like "main@dev.lemmy.ml"
-fn split_identifier(identifier: &str) -> (String, String) {
- let x: Vec<&str> = identifier.split('@').collect();
- (x[0].replace("!", ""), x[1].to_string())
-}
-
-fn get_remote_community_uri(identifier: &str) -> String {
- let (name, domain) = split_identifier(identifier);
- format!("http://{}/federation/c/{}", domain, name)
-}
-
pub fn fetch_remote_object<Response>(uri: &str) -> Result<Response, Error>
where
Response: for<'de> Deserialize<'de>,
Ok(res)
}
-pub fn get_remote_community_posts(identifier: &str) -> Result<GetPostsResponse, Error> {
+pub fn fetch_remote_community_posts(identifier: &str) -> Result<GetPostsResponse, Error> {
let community = fetch_remote_object::<GroupExt>(&get_remote_community_uri(identifier))?;
let outbox_uri = &community.extension.get_outbox().to_string();
let outbox = fetch_remote_object::<OrderedCollection>(outbox_uri)?;
Ok(GetPostsResponse { posts: posts? })
}
-pub fn get_remote_community(identifier: &str) -> Result<GetCommunityResponse, failure::Error> {
+pub fn fetch_remote_community(identifier: &str) -> Result<GetCommunityResponse, failure::Error> {
let group = fetch_remote_object::<GroupExt>(&get_remote_community_uri(identifier))?;
// TODO: this is only for testing until we can call that function from GetPosts
// (once string ids are supported)
})
}
-pub fn get_following_instances() -> Vec<&'static str> {
- Settings::get()
- .federation
- .followed_instances
- .split(',')
- .collect()
-}
-
-pub fn get_all_communities() -> Result<Vec<CommunityView>, Error> {
+pub fn fetch_all_communities() -> Result<Vec<CommunityView>, Error> {
let mut communities_list: Vec<CommunityView> = vec![];
for instance in &get_following_instances() {
match fetch_communities_from_instance(instance) {
}
Ok(communities_list)
}
-
-/// If community is on local instance, don't include the @instance part. This is only for displaying
-/// to the user and should never be used otherwise.
-pub fn format_community_name(name: &str, instance: &str) -> String {
- if instance == Settings::get().hostname {
- format!("!{}", name)
- } else {
- format!("!{}@{}", name, instance)
- }
-}