Adding linked instances. Fixes #1147
This commit is contained in:
parent
5732fde4d9
commit
f4c0248d7a
4 changed files with 41 additions and 4 deletions
|
@ -154,6 +154,11 @@ impl Community {
|
||||||
Ok(mods_and_admins)
|
Ok(mods_and_admins)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
|
||||||
|
use crate::schema::community::dsl::*;
|
||||||
|
community.select(actor_id).distinct().load::<String>(conn)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
|
pub fn is_mod_or_admin(conn: &PgConnection, user_id: i32, community_id: i32) -> bool {
|
||||||
Self::community_mods_and_admins(conn, community_id)
|
Self::community_mods_and_admins(conn, community_id)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
|
|
|
@ -8,7 +8,8 @@ use lemmy_db::{
|
||||||
Crud,
|
Crud,
|
||||||
};
|
};
|
||||||
use lemmy_structs::blocking;
|
use lemmy_structs::blocking;
|
||||||
use lemmy_utils::{APIError, ConnectionId, LemmyError};
|
use lemmy_utils::{settings::Settings, APIError, ConnectionId, LemmyError};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
pub mod claims;
|
pub mod claims;
|
||||||
pub mod comment;
|
pub mod comment;
|
||||||
|
@ -96,3 +97,33 @@ pub(in crate::api) async fn check_community_ban(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(in crate::api) async fn linked_instances(pool: &DbPool) -> Result<Vec<String>, LemmyError> {
|
||||||
|
let distinct_communities = blocking(pool, move |conn| {
|
||||||
|
Community::distinct_federated_communities(conn)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
|
let mut instances: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
for actor_id in &distinct_communities {
|
||||||
|
instances.push(Url::parse(actor_id)?.host_str().unwrap_or("").to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut allowed_instances = Settings::get().get_allowed_instances();
|
||||||
|
instances.append(&mut allowed_instances);
|
||||||
|
|
||||||
|
let blocked_instances = Settings::get().get_blocked_instances();
|
||||||
|
for blocked in &blocked_instances {
|
||||||
|
instances.retain(|i| !i.eq(blocked));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort and remove dupes
|
||||||
|
instances.sort_unstable();
|
||||||
|
instances.dedup();
|
||||||
|
|
||||||
|
// Remove the empties
|
||||||
|
instances.retain(|d| !d.eq(""));
|
||||||
|
|
||||||
|
Ok(instances)
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
api::{get_user_from_jwt, get_user_from_jwt_opt, is_admin, Perform},
|
api::{get_user_from_jwt, get_user_from_jwt_opt, is_admin, linked_instances, Perform},
|
||||||
apub::fetcher::search_by_apub_id,
|
apub::fetcher::search_by_apub_id,
|
||||||
version,
|
version,
|
||||||
LemmyContext,
|
LemmyContext,
|
||||||
|
@ -314,7 +314,7 @@ impl Perform for GetSite {
|
||||||
online,
|
online,
|
||||||
version: version::VERSION.to_string(),
|
version: version::VERSION.to_string(),
|
||||||
my_user,
|
my_user,
|
||||||
federated_instances: Settings::get().get_allowed_instances(),
|
federated_instances: linked_instances(context.pool()).await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -543,7 +543,7 @@ impl Perform for TransferSite {
|
||||||
online: 0,
|
online: 0,
|
||||||
version: version::VERSION.to_string(),
|
version: version::VERSION.to_string(),
|
||||||
my_user: Some(user),
|
my_user: Some(user),
|
||||||
federated_instances: Settings::get().get_allowed_instances(),
|
federated_instances: linked_instances(context.pool()).await?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,7 @@ fn create_user(conn: &PgConnection, name: &str) -> User_ {
|
||||||
admin: false,
|
admin: false,
|
||||||
banned: false,
|
banned: false,
|
||||||
updated: None,
|
updated: None,
|
||||||
|
published: None,
|
||||||
show_nsfw: false,
|
show_nsfw: false,
|
||||||
theme: "darkly".into(),
|
theme: "darkly".into(),
|
||||||
default_sort_type: SortType::Hot as i16,
|
default_sort_type: SortType::Hot as i16,
|
||||||
|
|
Loading…
Reference in a new issue