Skip to content

Commit

Permalink
Testing domainservd
Browse files Browse the repository at this point in the history
Signed-off-by: Till Wegmueller <[email protected]>
  • Loading branch information
Toasterson committed Jul 25, 2023
1 parent ab9f383 commit 02f852e
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 155 deletions.
46 changes: 37 additions & 9 deletions crates/activitypub/src/activities.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,43 @@
use crate::*;
use activitypub_federation::protocol::helpers::deserialize_skip_error;
use serde_json::Value;
use std::collections::HashMap;

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum Activity {
Create {
context: Context,
id: Url,
actor: Url,
published: chrono::NaiveDateTime,
to: Vec<Url>,
cc: Vec<Url>,
object: Object,
},
Create(Create),
Follow(Follow),
Accept(Accept),
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Create {
pub context: Context,
pub id: Url,
pub actor: Url,
pub published: chrono::NaiveDateTime,
pub to: Vec<Url>,
pub cc: Option<Vec<Url>>,
pub object: HashMap<String, Value>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Follow {
pub context: Context,
pub id: Url,
pub actor: Url,
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub to: Option<[Url; 1]>,
pub object: Url,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Accept {
pub context: Context,
pub id: Url,
pub actor: Url,
#[serde(deserialize_with = "deserialize_skip_error", default)]
pub to: Option<[Url; 1]>,
pub object: Follow,
}
6 changes: 4 additions & 2 deletions crates/activitypub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use serde_json::Value;
use serde_with::skip_serializing_none;
use url::Url;

pub const PUBLIC_ACTOR_URL: &str = "";

/// Public key of actors which is used for HTTP signatures.
///
/// This needs to be federated in the `public_key` field of all actors.
Expand Down Expand Up @@ -42,14 +44,14 @@ pub fn main_key_id(owner: &Url) -> String {
format!("{}#main-key", &owner)
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(untagged)]
pub enum Context {
Single(KnownContext),
List(Vec<KnownContext>),
}

#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum KnownContext {
#[serde(rename = "https://www.w3.org/ns/activitystreams")]
ActivityStreams,
Expand Down
2 changes: 2 additions & 0 deletions crates/domainservd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
domainservd.toml
keys
2 changes: 1 addition & 1 deletion crates/domainservd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ serde.workspace = true
serde_json.workspace = true
activitypub.workspace = true
thiserror.workspace = true
miette.workspace = true
miette = { workspace = true, features = ["fancy"] }
clap.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
Expand Down
13 changes: 13 additions & 0 deletions crates/domainservd/sample_data/follow_toasterson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"context": [
"https://www.w3.org/ns/activitystreams",
"https://w3id.org/security/v1"
],
"type": "Follow",
"id": "https://abomb.zip/objects/blubber",
"actor": "https://abomb.zip/actors/Toasterson",
"to": [
"https://hephaistos.taileff33.ts.net/actors/Toasterson"
],
"object": "https://hephaistos.taileff33.ts.net/actors/Toasterson"
}
Loading

0 comments on commit 02f852e

Please sign in to comment.