mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-10 09:29:22 +00:00
5d837780f5
* Moving settings to Database. - Moves many settings into the database. Fixes #2285 - Adds a local_site and instance table. Fixes #2365 . Fixes #2368 - Separates SQL update an insert forms, to avoid runtime errors. - Adds TypedBuilder to all the SQL forms, instead of default. * Fix weird clippy issue. * Removing extra lines. * Some fixes from suggestions. * Fixing apub tests. * Using instance creation helper function. * Move forms to their own line. * Trying to fix local_site_data, still broken. * Testing out async * Testing out async 2 * Fixing federation tests. * Trying to fix check features 1. * Starting on adding diesel async. 1/4th done. * Added async to views and schema. * Adding some more async * Compiling now. * Added diesel async. Fixes #2465 * Running clippy --fix * Trying to fix cargo test on drone. * Trying new muslrust. * Trying a custom dns * Trying a custom dns 2 * Trying a custom dns 3 * Trying a custom dns 4 * Trying a custom dns 5 * Trying a custom dns 6 * Trying a custom dns 7 * Addressing PR comments. * Adding check_apub to all verify functions. * Reverting back drone. * Fixing merge * Fix docker images. * Adding missing discussion_languages. * Trying to fix federation tests. * Fix site setup user creation. * Fix clippy * Fix clippy 2 * Test api faster * Try to fix 1 * Try to fix 2 * What are these lines about * Trying to fix 3 * Moving federation test back to top. * Remove logging cat.
126 lines
3.3 KiB
Rust
126 lines
3.3 KiB
Rust
use crate::{
|
|
objects::{community::ApubCommunity, instance::ApubSite},
|
|
protocol::objects::{group::Group, instance::Instance},
|
|
ActorType,
|
|
};
|
|
use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
|
|
use chrono::NaiveDateTime;
|
|
use lemmy_db_schema::{source::site::Site, utils::DbPool};
|
|
use lemmy_utils::error::LemmyError;
|
|
use lemmy_websocket::LemmyContext;
|
|
use serde::Deserialize;
|
|
use url::Url;
|
|
|
|
pub mod block_user;
|
|
pub mod undo_block_user;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum SiteOrCommunity {
|
|
Site(ApubSite),
|
|
Community(ApubCommunity),
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
#[serde(untagged)]
|
|
pub enum InstanceOrGroup {
|
|
Instance(Instance),
|
|
Group(Group),
|
|
}
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
impl ApubObject for SiteOrCommunity {
|
|
type DataType = LemmyContext;
|
|
type ApubType = InstanceOrGroup;
|
|
type DbType = ();
|
|
type Error = LemmyError;
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
fn last_refreshed_at(&self) -> Option<NaiveDateTime> {
|
|
Some(match self {
|
|
SiteOrCommunity::Site(i) => i.last_refreshed_at,
|
|
SiteOrCommunity::Community(c) => c.last_refreshed_at,
|
|
})
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn read_from_apub_id(
|
|
object_id: Url,
|
|
data: &Self::DataType,
|
|
) -> Result<Option<Self>, LemmyError>
|
|
where
|
|
Self: Sized,
|
|
{
|
|
let site = ApubSite::read_from_apub_id(object_id.clone(), data).await?;
|
|
Ok(match site {
|
|
Some(o) => Some(SiteOrCommunity::Site(o)),
|
|
None => ApubCommunity::read_from_apub_id(object_id, data)
|
|
.await?
|
|
.map(SiteOrCommunity::Community),
|
|
})
|
|
}
|
|
|
|
async fn delete(self, _data: &Self::DataType) -> Result<(), LemmyError> {
|
|
unimplemented!()
|
|
}
|
|
|
|
async fn into_apub(self, _data: &Self::DataType) -> Result<Self::ApubType, LemmyError> {
|
|
unimplemented!()
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn verify(
|
|
apub: &Self::ApubType,
|
|
expected_domain: &Url,
|
|
data: &Self::DataType,
|
|
request_counter: &mut i32,
|
|
) -> Result<(), LemmyError> {
|
|
match apub {
|
|
InstanceOrGroup::Instance(i) => {
|
|
ApubSite::verify(i, expected_domain, data, request_counter).await
|
|
}
|
|
InstanceOrGroup::Group(g) => {
|
|
ApubCommunity::verify(g, expected_domain, data, request_counter).await
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn from_apub(
|
|
apub: Self::ApubType,
|
|
data: &Self::DataType,
|
|
request_counter: &mut i32,
|
|
) -> Result<Self, LemmyError>
|
|
where
|
|
Self: Sized,
|
|
{
|
|
Ok(match apub {
|
|
InstanceOrGroup::Instance(p) => {
|
|
SiteOrCommunity::Site(ApubSite::from_apub(p, data, request_counter).await?)
|
|
}
|
|
InstanceOrGroup::Group(n) => {
|
|
SiteOrCommunity::Community(ApubCommunity::from_apub(n, data, request_counter).await?)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
impl SiteOrCommunity {
|
|
fn id(&self) -> ObjectId<SiteOrCommunity> {
|
|
match self {
|
|
SiteOrCommunity::Site(s) => ObjectId::new(s.actor_id.clone()),
|
|
SiteOrCommunity::Community(c) => ObjectId::new(c.actor_id.clone()),
|
|
}
|
|
}
|
|
}
|
|
|
|
async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
|
|
Ok(match target {
|
|
SiteOrCommunity::Site(_) => Site::read_remote_sites(pool)
|
|
.await?
|
|
.into_iter()
|
|
.map(|s| s.actor_id.into())
|
|
.collect(),
|
|
SiteOrCommunity::Community(c) => vec![c.actor_id()],
|
|
})
|
|
}
|