mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-05-12 06:52:39 +00:00
375d9a2a3c
* persistent activity queue * fixes * fixes * make federation workers function callable from outside * log federation instances * dead instance detection not needed here * taplo fmt * split federate bin/lib * minor fix * better logging * log * create struct to hold cancellable task for readability * use boxfuture for readability * reset submodule * fix * fix lint * swap * remove json column, use separate array columns instead * some review comments * make worker a struct for readability * minor readability * add local filter to community follower view * remove separate lemmy_federate entry point * fix remaining duration * address review comments mostly * fix lint * upgrade actitypub-fed to simpler interface * fix sql format * increase delays a bit * fixes after merge * remove selectable * fix instance selectable * add comment * start federation based on latest id at the time * rename federate process args * dead instances in one query * filter follow+report activities by local * remove synchronous federation remove activity sender queue * lint * fix federation tests by waiting for results to change * fix fed test * fix comment report * wait some more * Apply suggestions from code review Co-authored-by: SorteKanin <sortekanin@gmail.com> * fix most remaining tests * wait until private messages * fix community tests * fix community tests * move arg parse * use instance_id instead of domain in federation_queue_state table --------- Co-authored-by: Dessalines <dessalines@users.noreply.github.com> Co-authored-by: SorteKanin <sortekanin@gmail.com>
109 lines
2.8 KiB
Rust
109 lines
2.8 KiB
Rust
use crate::{
|
|
fetcher::user_or_community::{PersonOrGroup, UserOrCommunity},
|
|
objects::instance::ApubSite,
|
|
protocol::objects::instance::Instance,
|
|
};
|
|
use activitypub_federation::{
|
|
config::Data,
|
|
traits::{Actor, Object},
|
|
};
|
|
use chrono::{DateTime, Utc};
|
|
use lemmy_api_common::context::LemmyContext;
|
|
use lemmy_utils::error::LemmyError;
|
|
use reqwest::Url;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
// todo: maybe this enum should be somewhere else?
|
|
#[derive(Debug)]
|
|
pub enum SiteOrCommunityOrUser {
|
|
Site(ApubSite),
|
|
UserOrCommunity(UserOrCommunity),
|
|
}
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
#[serde(untagged)]
|
|
pub enum SiteOrPersonOrGroup {
|
|
Instance(Instance),
|
|
PersonOrGroup(PersonOrGroup),
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl Object for SiteOrCommunityOrUser {
|
|
type DataType = LemmyContext;
|
|
type Kind = SiteOrPersonOrGroup;
|
|
type Error = LemmyError;
|
|
|
|
fn last_refreshed_at(&self) -> Option<DateTime<Utc>> {
|
|
Some(match self {
|
|
SiteOrCommunityOrUser::Site(p) => p.last_refreshed_at,
|
|
SiteOrCommunityOrUser::UserOrCommunity(p) => p.last_refreshed_at()?,
|
|
})
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn read_from_id(
|
|
_object_id: Url,
|
|
_data: &Data<Self::DataType>,
|
|
) -> Result<Option<Self>, LemmyError> {
|
|
unimplemented!();
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn delete(self, data: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
|
match self {
|
|
SiteOrCommunityOrUser::Site(p) => p.delete(data).await,
|
|
SiteOrCommunityOrUser::UserOrCommunity(p) => p.delete(data).await,
|
|
}
|
|
}
|
|
|
|
async fn into_json(self, _data: &Data<Self::DataType>) -> Result<Self::Kind, LemmyError> {
|
|
unimplemented!()
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn verify(
|
|
apub: &Self::Kind,
|
|
expected_domain: &Url,
|
|
data: &Data<Self::DataType>,
|
|
) -> Result<(), LemmyError> {
|
|
match apub {
|
|
SiteOrPersonOrGroup::Instance(a) => ApubSite::verify(a, expected_domain, data).await,
|
|
SiteOrPersonOrGroup::PersonOrGroup(a) => {
|
|
UserOrCommunity::verify(a, expected_domain, data).await
|
|
}
|
|
}
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
async fn from_json(_apub: Self::Kind, _data: &Data<Self::DataType>) -> Result<Self, LemmyError> {
|
|
unimplemented!();
|
|
}
|
|
}
|
|
|
|
impl Actor for SiteOrCommunityOrUser {
|
|
fn id(&self) -> Url {
|
|
match self {
|
|
SiteOrCommunityOrUser::Site(u) => u.id(),
|
|
SiteOrCommunityOrUser::UserOrCommunity(c) => c.id(),
|
|
}
|
|
}
|
|
|
|
fn public_key_pem(&self) -> &str {
|
|
match self {
|
|
SiteOrCommunityOrUser::Site(p) => p.public_key_pem(),
|
|
SiteOrCommunityOrUser::UserOrCommunity(p) => p.public_key_pem(),
|
|
}
|
|
}
|
|
|
|
fn private_key_pem(&self) -> Option<String> {
|
|
match self {
|
|
SiteOrCommunityOrUser::Site(p) => p.private_key_pem(),
|
|
SiteOrCommunityOrUser::UserOrCommunity(p) => p.private_key_pem(),
|
|
}
|
|
}
|
|
|
|
fn inbox(&self) -> Url {
|
|
unimplemented!()
|
|
}
|
|
}
|