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