use crate::{
- check_apub_id_valid_with_strictness,
- fetch_local_site_data,
+ check_apub_id_valid,
+ local_site_data_cached,
objects::instance::fetch_instance_actor_for_object,
protocol::{
objects::{group::Group, Endpoints, LanguageTag},
traits::{Actor, Object},
};
use chrono::NaiveDateTime;
-use itertools::Itertools;
use lemmy_api_common::{
context::LemmyContext,
utils::{generate_featured_url, generate_moderators_url, generate_outbox_url},
context: &Data<Self::DataType>,
) -> Result<Option<Self>, LemmyError> {
Ok(
- Community::read_from_apub_id(context.pool(), &object_id.into())
+ Community::read_from_apub_id(&mut context.pool(), &object_id.into())
.await?
.map(Into::into),
)
#[tracing::instrument(skip_all)]
async fn delete(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
let form = CommunityUpdateForm::builder().deleted(Some(true)).build();
- Community::update(context.pool(), self.id, &form).await?;
+ Community::update(&mut context.pool(), self.id, &form).await?;
Ok(())
}
#[tracing::instrument(skip_all)]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Group, LemmyError> {
let community_id = self.id;
- let langs = CommunityLanguage::read(data.pool(), community_id).await?;
- let language = LanguageTag::new_multiple(langs, data.pool()).await?;
+ let langs = CommunityLanguage::read(&mut data.pool(), community_id).await?;
+ let language = LanguageTag::new_multiple(langs, &mut data.pool()).await?;
let group = Group {
kind: GroupType::Group,
let instance_id = fetch_instance_actor_for_object(&group.id, context).await?;
let form = Group::into_insert_form(group.clone(), instance_id);
- let languages = LanguageTag::to_language_id_multiple(group.language, context.pool()).await?;
+ let languages =
+ LanguageTag::to_language_id_multiple(group.language, &mut context.pool()).await?;
- let community = Community::create(context.pool(), &form).await?;
- CommunityLanguage::update(context.pool(), languages, community.id).await?;
+ let community = Community::create(&mut context.pool(), &form).await?;
+ CommunityLanguage::update(&mut context.pool(), languages, community.id).await?;
let community: ApubCommunity = community.into();
) -> Result<Vec<Url>, LemmyError> {
let id = self.id;
- let local_site_data = fetch_local_site_data(context.pool()).await?;
- let follows = CommunityFollowerView::for_community(context.pool(), id).await?;
+ let local_site_data = local_site_data_cached(&mut context.pool()).await?;
+ let follows =
+ CommunityFollowerView::get_community_follower_inboxes(&mut context.pool(), id).await?;
let inboxes: Vec<Url> = follows
.into_iter()
- .filter(|f| !f.follower.local)
- .map(|f| {
- f.follower
- .shared_inbox_url
- .unwrap_or(f.follower.inbox_url)
- .into()
- })
- .unique()
+ .map(Into::into)
.filter(|inbox: &Url| inbox.host_str() != Some(&context.settings().hostname))
// Don't send to blocked instances
- .filter(|inbox| {
- check_apub_id_valid_with_strictness(inbox, false, &local_site_data, context.settings())
- .is_ok()
- })
+ .filter(|inbox| check_apub_id_valid(inbox, &local_site_data).is_ok())
.collect();
Ok(inboxes)
#[cfg(test)]
pub(crate) mod tests {
+ #![allow(clippy::unwrap_used)]
+ #![allow(clippy::indexing_slicing)]
+
use super::*;
use crate::{
objects::{instance::tests::parse_lemmy_instance, tests::init_context},
assert!(!community.local);
assert_eq!(community.description.as_ref().unwrap().len(), 132);
- Community::delete(context.pool(), community.id)
+ Community::delete(&mut context.pool(), community.id)
.await
.unwrap();
- Site::delete(context.pool(), site.id).await.unwrap();
+ Site::delete(&mut context.pool(), site.id).await.unwrap();
}
}