summaryrefslogtreecommitdiffstats
path: root/src/entity/user.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity/user.rs')
-rw-r--r--src/entity/user.rs36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/entity/user.rs b/src/entity/user.rs
index af27ea2..e136cb3 100644
--- a/src/entity/user.rs
+++ b/src/entity/user.rs
@@ -2,25 +2,27 @@ use activitypub_federation::{
config::Data,
fetch::object_id::ObjectId,
http_signatures::generate_actor_keypair,
+ kinds::actor::PersonType,
+ protocol::public_key::PublicKey,
traits::{Actor, Object},
};
use async_trait::async_trait;
-use serde::Deserialize;
+use serde::{Deserialize, Serialize};
use tracing::trace;
use url::Url;
use crate::{error::AppError, state::AppHandle};
#[derive(PartialEq, Clone, Debug)]
-pub(crate) struct LocalUser {
+pub(crate) struct User {
pub username: String,
- pub ap_id: ObjectId<LocalUser>,
+ pub ap_id: ObjectId<User>,
pub private_key: Option<String>,
pub public_key: String,
pub inbox: Url,
}
-impl LocalUser {
+impl User {
pub fn new(username: &str) -> Result<Self, AppError> {
trace!("creating a new user");
let keys = generate_actor_keypair()?;
@@ -36,17 +38,25 @@ impl LocalUser {
}
}
-#[derive(Deserialize)]
-pub struct User {}
+#[derive(Clone, Debug, Deserialize, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub struct Person {
+ #[serde(rename = "type")]
+ kind: PersonType,
+ preferred_username: String,
+ id: ObjectId<User>,
+ inbox: Url,
+ public_key: PublicKey,
+}
#[async_trait]
-impl Object for LocalUser {
+impl Object for User {
#[doc = " App data type passed to handlers. Must be identical to"]
#[doc = " [crate::config::FederationConfigBuilder::app_data] type."]
type DataType = AppHandle;
#[doc = " The type of protocol struct which gets sent over network to federate this database struct."]
- type Kind = User;
+ type Kind = Person;
#[doc = " Error type returned by handler methods"]
type Error = AppError;
@@ -69,7 +79,13 @@ impl Object for LocalUser {
#[doc = " Called when a local object gets fetched by another instance over HTTP, or when an object"]
#[doc = " gets sent in an activity."]
async fn into_json(self, data: &Data<Self::DataType>) -> Result<Self::Kind, Self::Error> {
- todo!()
+ Ok(Person {
+ preferred_username: self.username.clone(),
+ kind: Default::default(),
+ id: self.ap_id.clone(),
+ inbox: self.inbox.clone(),
+ public_key: self.public_key(),
+ })
}
#[doc = " Verifies that the received object is valid."]
@@ -94,7 +110,7 @@ impl Object for LocalUser {
}
}
-impl Actor for LocalUser {
+impl Actor for User {
fn public_key_pem(&self) -> &str {
&self.public_key
}