mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-07 10:42:19 +00:00
Federate bot status using actor type
field
This commit is contained in:
parent
4e98cea679
commit
0e1f9c5f46
4 changed files with 28 additions and 20 deletions
|
@ -9,18 +9,11 @@ use serde::{Deserialize, Serialize};
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PersonExtension {
|
||||
pub matrix_user_id: Option<String>,
|
||||
pub bot_account: bool,
|
||||
}
|
||||
|
||||
impl PersonExtension {
|
||||
pub fn new(
|
||||
matrix_user_id: Option<String>,
|
||||
bot_account: bool,
|
||||
) -> Result<PersonExtension, LemmyError> {
|
||||
Ok(PersonExtension {
|
||||
matrix_user_id,
|
||||
bot_account,
|
||||
})
|
||||
pub fn new(matrix_user_id: Option<String>) -> Result<PersonExtension, LemmyError> {
|
||||
Ok(PersonExtension { matrix_user_id })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,13 +26,11 @@ where
|
|||
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||
Ok(PersonExtension {
|
||||
matrix_user_id: unparsed_mut.remove("matrix_user_id")?,
|
||||
bot_account: unparsed_mut.remove("bot_account")?,
|
||||
})
|
||||
}
|
||||
|
||||
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
||||
unparsed_mut.insert("matrix_user_id", self.matrix_user_id)?;
|
||||
unparsed_mut.insert("bot_account", self.bot_account)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,11 +46,18 @@ use url::{ParseError, Url};
|
|||
/// Activitystreams type for community
|
||||
type GroupExt = Ext2<actor::ApActor<ApObject<actor::Group>>, GroupExtension, PublicKeyExtension>;
|
||||
/// Activitystreams type for person
|
||||
type PersonExt = Ext2<actor::ApActor<ApObject<actor::Person>>, PersonExtension, PublicKeyExtension>;
|
||||
type PersonExt =
|
||||
Ext2<actor::ApActor<ApObject<actor::Actor<UserTypes>>>, PersonExtension, PublicKeyExtension>;
|
||||
/// Activitystreams type for post
|
||||
pub type PageExt = Ext1<ApObject<Page>, PageExtension>;
|
||||
pub type NoteExt = ApObject<Note>;
|
||||
|
||||
#[derive(Clone, Copy, Debug, serde::Deserialize, serde::Serialize, PartialEq)]
|
||||
pub enum UserTypes {
|
||||
Person,
|
||||
Service,
|
||||
}
|
||||
|
||||
pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
|
||||
|
||||
/// Checks if the ID is allowed for sending or receiving.
|
||||
|
|
|
@ -10,11 +10,12 @@ use crate::{
|
|||
},
|
||||
ActorType,
|
||||
PersonExt,
|
||||
UserTypes,
|
||||
};
|
||||
use activitystreams::{
|
||||
actor::{ApActor, Endpoints, Person},
|
||||
object::{ApObject, Image, Tombstone},
|
||||
prelude::*,
|
||||
actor::{Actor, ApActor, ApActorExt, Endpoints},
|
||||
base::{BaseExt, ExtendsExt},
|
||||
object::{ApObject, Image, Object, ObjectExt, Tombstone},
|
||||
};
|
||||
use activitystreams_ext::Ext2;
|
||||
use anyhow::Context;
|
||||
|
@ -38,7 +39,16 @@ impl ToApub for DbPerson {
|
|||
type ApubType = PersonExt;
|
||||
|
||||
async fn to_apub(&self, _pool: &DbPool) -> Result<PersonExt, LemmyError> {
|
||||
let mut person = ApObject::new(Person::new());
|
||||
let object = Object::<UserTypes>::new_none_type();
|
||||
let mut actor = Actor(object);
|
||||
let kind = if self.bot_account {
|
||||
UserTypes::Service
|
||||
} else {
|
||||
UserTypes::Person
|
||||
};
|
||||
actor.set_kind(kind);
|
||||
let mut person = ApObject::new(actor);
|
||||
|
||||
person
|
||||
.set_many_contexts(lemmy_context()?)
|
||||
.set_id(self.actor_id.to_owned().into_inner())
|
||||
|
@ -78,8 +88,7 @@ impl ToApub for DbPerson {
|
|||
..Default::default()
|
||||
});
|
||||
|
||||
let person_ext =
|
||||
PersonExtension::new(self.matrix_user_id.to_owned(), self.bot_account.to_owned())?;
|
||||
let person_ext = PersonExtension::new(self.matrix_user_id.to_owned())?;
|
||||
Ok(Ext2::new(ap_actor, person_ext, self.get_public_key_ext()?))
|
||||
}
|
||||
fn to_tombstone(&self) -> Result<Tombstone, LemmyError> {
|
||||
|
@ -133,6 +142,8 @@ impl FromApubToForm<PersonExt> for PersonForm {
|
|||
_request_counter: &mut i32,
|
||||
_mod_action_allowed: bool,
|
||||
) -> Result<Self, LemmyError> {
|
||||
dbg!(person);
|
||||
dbg!(person.inner.is_kind(&UserTypes::Service));
|
||||
let avatar = match person.icon() {
|
||||
Some(any_image) => Some(
|
||||
Image::from_any_base(any_image.as_one().context(location_info!())?.clone())?
|
||||
|
@ -194,7 +205,7 @@ impl FromApubToForm<PersonExt> for PersonForm {
|
|||
bio: Some(bio),
|
||||
local: Some(false),
|
||||
admin: Some(false),
|
||||
bot_account: Some(person.ext_one.bot_account),
|
||||
bot_account: Some(person.inner.is_kind(&UserTypes::Service)),
|
||||
private_key: None,
|
||||
public_key: Some(Some(person.ext_two.public_key.to_owned().public_key_pem)),
|
||||
last_refreshed_at: Some(naive_now()),
|
||||
|
|
|
@ -24,7 +24,6 @@ RUN apt-get update -y
|
|||
RUN apt-get install -y libpq-dev
|
||||
|
||||
# Copy resources
|
||||
COPY config/defaults.hjson /config/defaults.hjson
|
||||
COPY --from=rust /app/lemmy_server /app/lemmy
|
||||
|
||||
EXPOSE 8536
|
||||
|
|
Loading…
Reference in a new issue