forked from nutomic/lemmy
Various minor federation improvements
This commit is contained in:
parent
a52a954eb4
commit
70995dab8c
4 changed files with 33 additions and 39 deletions
11
docker/federation-test/Dockerfile
vendored
11
docker/federation-test/Dockerfile
vendored
|
@ -1,14 +1,15 @@
|
||||||
FROM ekidd/rust-musl-builder:1.38.0-openssl11
|
FROM ekidd/rust-musl-builder:1.38.0-openssl11
|
||||||
|
|
||||||
|
USER root
|
||||||
|
RUN mkdir /app/dist/documentation/ -p \
|
||||||
|
&& addgroup --gid 1001 lemmy \
|
||||||
|
&& adduser --disabled-password --shell /bin/sh -u 1001 --ingroup lemmy lemmy
|
||||||
|
|
||||||
# Copy resources
|
# Copy resources
|
||||||
COPY server/config/defaults.hjson /app/config/defaults.hjson
|
COPY server/config/defaults.hjson /app/config/defaults.hjson
|
||||||
COPY server/target/debug/lemmy_server /app/lemmy
|
|
||||||
COPY ui/dist /app/dist
|
COPY ui/dist /app/dist
|
||||||
|
COPY server/target/debug/lemmy_server /app/lemmy
|
||||||
|
|
||||||
USER root
|
|
||||||
RUN mkdir /app/dist/documentation/
|
|
||||||
RUN addgroup --gid 1001 lemmy
|
|
||||||
RUN adduser --disabled-password --shell /bin/sh -u 1001 --ingroup lemmy lemmy
|
|
||||||
RUN chown lemmy:lemmy /app/ -R
|
RUN chown lemmy:lemmy /app/ -R
|
||||||
USER lemmy
|
USER lemmy
|
||||||
EXPOSE 8536
|
EXPOSE 8536
|
||||||
|
|
|
@ -18,6 +18,7 @@ impl Community {
|
||||||
|
|
||||||
// TODO: why the hell is this code so awkward?
|
// TODO: why the hell is this code so awkward?
|
||||||
group.object_props.set_context_object(context()).ok();
|
group.object_props.set_context_object(context()).ok();
|
||||||
|
// TODO: id really needs to be a url
|
||||||
group.object_props.set_id_string(self.id.to_string()).ok();
|
group.object_props.set_id_string(self.id.to_string()).ok();
|
||||||
group
|
group
|
||||||
.object_props
|
.object_props
|
||||||
|
@ -64,17 +65,12 @@ impl Community {
|
||||||
|
|
||||||
let connection = establish_unpooled_connection();
|
let connection = establish_unpooled_connection();
|
||||||
//As we are an object, we validated that the community id was valid
|
//As we are an object, we validated that the community id was valid
|
||||||
|
// TODO: add a method that only returns count for better performance
|
||||||
let community_followers = CommunityFollowerView::for_community(&connection, self.id).unwrap();
|
let community_followers = CommunityFollowerView::for_community(&connection, self.id).unwrap();
|
||||||
|
|
||||||
// TODO: we definitely dont want to make our follower list public, we should only expose the count
|
|
||||||
let ap_followers = community_followers
|
|
||||||
.iter()
|
|
||||||
.map(|follower| make_apub_endpoint("u", &follower.user_name))
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
collection
|
collection
|
||||||
.collection_props
|
.collection_props
|
||||||
.set_items_string_vec(ap_followers)
|
.set_total_items_u64(community_followers.len() as u64)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
collection
|
collection
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,9 +96,14 @@ mod tests {
|
||||||
|
|
||||||
pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String {
|
pub fn make_apub_endpoint<S: Display, T: Display>(point: S, value: T) -> String {
|
||||||
format!(
|
format!(
|
||||||
"https://{}/federation/{}/{}",
|
"{}://{}/federation/{}/{}",
|
||||||
|
get_apub_protocol_string(),
|
||||||
Settings::get().hostname,
|
Settings::get().hostname,
|
||||||
point,
|
point,
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_apub_protocol_string() -> &'static str {
|
||||||
|
"http"
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::api::post::GetPosts;
|
||||||
use crate::db::community_view::CommunityView;
|
use crate::db::community_view::CommunityView;
|
||||||
use crate::naive_now;
|
use crate::naive_now;
|
||||||
use crate::settings::Settings;
|
use crate::settings::Settings;
|
||||||
|
use serde_json::Value;
|
||||||
|
|
||||||
// TODO: right now all of the data is requested on demand, for production we will need to store
|
// TODO: right now all of the data is requested on demand, for production we will need to store
|
||||||
// things in the local database to not ruin the performance
|
// things in the local database to not ruin the performance
|
||||||
|
@ -32,7 +33,7 @@ pub fn get_remote_community_posts(name: String) -> Result<GetPosts, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse, Error> {
|
pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse, failure::Error> {
|
||||||
let x: Vec<&str> = identifier.split('@').collect();
|
let x: Vec<&str> = identifier.split('@').collect();
|
||||||
let name = x[0].replace("!", "");
|
let name = x[0].replace("!", "");
|
||||||
let instance = x[1];
|
let instance = x[1];
|
||||||
|
@ -48,34 +49,13 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
|
||||||
admins: vec![],
|
admins: vec![],
|
||||||
community: CommunityView {
|
community: CommunityView {
|
||||||
// TODO: why does the stupid library have everything stored as value without working autocomplete for methods???
|
// TODO: why does the stupid library have everything stored as value without working autocomplete for methods???
|
||||||
// i want to pull that whole lib in here and treat it as part of lemmy so we can fix this shit
|
|
||||||
// TODO: we need to merge id and name into a single thing (stuff like @user@instance.com)
|
// TODO: we need to merge id and name into a single thing (stuff like @user@instance.com)
|
||||||
id: community
|
id: get_string_value(community.object_props.id).parse::<i32>()?,
|
||||||
.object_props
|
|
||||||
.id
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.unwrap()
|
|
||||||
.parse::<i32>()
|
|
||||||
.unwrap(),
|
|
||||||
name,
|
name,
|
||||||
title: community
|
title: get_string_value(community.object_props.name),
|
||||||
.object_props
|
description: get_string_value_opt(community.object_props.summary),
|
||||||
.name
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.unwrap()
|
|
||||||
.to_string(), // TODO: why does it still show !main@lemmy_beta:8541
|
|
||||||
description: community.object_props.summary.map(|c| c.to_string()), // TODO: this has an extra quote somehow
|
|
||||||
category_id: -1,
|
category_id: -1,
|
||||||
creator_id: community
|
creator_id: get_string_value(community.object_props.attributed_to).parse::<i32>()?,
|
||||||
.object_props
|
|
||||||
.attributed_to
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
|
||||||
.unwrap()
|
|
||||||
.parse::<i32>()
|
|
||||||
.unwrap(),
|
|
||||||
removed: false,
|
removed: false,
|
||||||
published: naive_now(), // TODO: need to handle time conversion (or handle it in apub lib)
|
published: naive_now(), // TODO: need to handle time conversion (or handle it in apub lib)
|
||||||
updated: Some(naive_now()), // TODO: community.object_props.updated
|
updated: Some(naive_now()), // TODO: community.object_props.updated
|
||||||
|
@ -95,6 +75,18 @@ pub fn get_remote_community(identifier: String) -> Result<GetCommunityResponse,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_string_value_opt(value: Option<Value>) -> Option<String> {
|
||||||
|
value
|
||||||
|
.as_ref()
|
||||||
|
.map(Value::as_str)
|
||||||
|
.flatten()
|
||||||
|
.map(str::to_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_string_value(value: Option<Value>) -> String {
|
||||||
|
get_string_value_opt(value).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_following_instances() -> Result<Vec<String>, Error> {
|
pub fn get_following_instances() -> Result<Vec<String>, Error> {
|
||||||
let instance_list = match Settings::get().federated_instance.clone() {
|
let instance_list = match Settings::get().federated_instance.clone() {
|
||||||
Some(f) => vec![f, Settings::get().hostname.clone()],
|
Some(f) => vec![f, Settings::get().hostname.clone()],
|
||||||
|
|
Loading…
Reference in a new issue