Update to latest activitystreams

This commit is contained in:
Aode (Lion)
2022-01-17 16:54:45 -06:00
parent 6b0d3298cc
commit 8893895c71
27 changed files with 338 additions and 264 deletions
+5 -5
View File
@@ -7,13 +7,13 @@ use crate::{
DeliverMany, JobState,
},
};
use activitystreams::{activity::Announce as AsAnnounce, url::Url};
use activitystreams::{activity::Announce as AsAnnounce, iri_string::types::IriString};
use background_jobs::ActixJob;
use std::{future::Future, pin::Pin};
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct Announce {
object_id: Url,
object_id: IriString,
actor: Actor,
}
@@ -27,7 +27,7 @@ impl std::fmt::Debug for Announce {
}
impl Announce {
pub fn new(object_id: Url, actor: Actor) -> Self {
pub fn new(object_id: IriString, actor: Actor) -> Self {
Announce { object_id, actor }
}
@@ -49,8 +49,8 @@ impl Announce {
// Generate a type that says "Look at this object"
fn generate_announce(
config: &Config,
activity_id: &Url,
object_id: &Url,
activity_id: &IriString,
object_id: &IriString,
) -> Result<AsAnnounce, Error> {
let announce = AsAnnounce::new(config.generate_url(UrlKind::Actor), object_id.clone());
+5 -5
View File
@@ -8,7 +8,7 @@ use crate::{
use activitystreams::{
activity::{Accept as AsAccept, Follow as AsFollow},
prelude::*,
url::Url,
iri_string::types::IriString,
};
use background_jobs::ActixJob;
use std::{future::Future, pin::Pin};
@@ -62,7 +62,7 @@ impl Follow {
}
// Generate a type that says "I want to follow you"
fn generate_follow(config: &Config, actor_id: &Url, my_id: &Url) -> Result<AsFollow, Error> {
fn generate_follow(config: &Config, actor_id: &IriString, my_id: &IriString) -> Result<AsFollow, Error> {
let follow = AsFollow::new(my_id.clone(), actor_id.clone());
prepare_activity(
@@ -75,9 +75,9 @@ fn generate_follow(config: &Config, actor_id: &Url, my_id: &Url) -> Result<AsFol
// Generate a type that says "I accept your follow request"
fn generate_accept_follow(
config: &Config,
actor_id: &Url,
input_id: &Url,
my_id: &Url,
actor_id: &IriString,
input_id: &IriString,
my_id: &IriString,
) -> Result<AsAccept, Error> {
let mut follow = AsFollow::new(actor_id.clone(), my_id.clone());
+3 -2
View File
@@ -23,7 +23,7 @@ impl Forward {
async fn perform(self, state: JobState) -> Result<(), Error> {
let object_id = self
.input
.object()
.object_unchecked()
.as_single_id()
.ok_or(ErrorKind::MissingId)?;
@@ -31,7 +31,8 @@ impl Forward {
state
.job_server
.queue(DeliverMany::new(inboxes, self.input)?).await?;
.queue(DeliverMany::new(inboxes, self.input)?)
.await?;
Ok(())
}
+18 -7
View File
@@ -7,9 +7,9 @@ use crate::{
use activitystreams::{
activity::{Follow as AsFollow, Undo as AsUndo},
context,
iri_string::types::IriString,
prelude::*,
security,
url::Url,
};
use std::convert::TryInto;
@@ -23,16 +23,23 @@ pub(crate) use self::{
announce::Announce, follow::Follow, forward::Forward, reject::Reject, undo::Undo,
};
async fn get_inboxes(state: &State, actor: &Actor, object_id: &Url) -> Result<Vec<Url>, Error> {
let domain = object_id.host().ok_or(ErrorKind::Domain)?.to_string();
async fn get_inboxes(
state: &State,
actor: &Actor,
object_id: &IriString,
) -> Result<Vec<IriString>, Error> {
let authority = object_id
.authority_str()
.ok_or(ErrorKind::Domain)?
.to_string();
state.inboxes_without(&actor.inbox, &domain).await
state.inboxes_without(&actor.inbox, &authority).await
}
fn prepare_activity<T, U, V, Kind>(
mut t: T,
id: impl TryInto<Url, Error = U>,
to: impl TryInto<Url, Error = V>,
id: impl TryInto<IriString, Error = U>,
to: impl TryInto<IriString, Error = V>,
) -> Result<T, Error>
where
T: ObjectExt<Kind> + BaseExt<Kind>,
@@ -45,7 +52,11 @@ where
}
// Generate a type that says "I want to stop following you"
fn generate_undo_follow(config: &Config, actor_id: &Url, my_id: &Url) -> Result<AsUndo, Error> {
fn generate_undo_follow(
config: &Config,
actor_id: &IriString,
my_id: &IriString,
) -> Result<AsUndo, Error> {
let mut follow = AsFollow::new(my_id.clone(), actor_id.clone());
follow.set_id(config.generate_url(UrlKind::Activity));
+5 -5
View File
@@ -3,14 +3,14 @@ use crate::{
error::{Error, ErrorKind},
jobs::JobState,
};
use activitystreams::{object::Image, prelude::*, url::Url};
use activitystreams::{object::Image, prelude::*, iri_string::types::IriString};
use background_jobs::ActixJob;
use std::{future::Future, pin::Pin};
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct QueryContact {
actor_id: Url,
contact_id: Url,
actor_id: IriString,
contact_id: IriString,
}
impl std::fmt::Debug for QueryContact {
@@ -23,7 +23,7 @@ impl std::fmt::Debug for QueryContact {
}
impl QueryContact {
pub(crate) fn new(actor_id: Url, contact_id: Url) -> Self {
pub(crate) fn new(actor_id: IriString, contact_id: IriString) -> Self {
QueryContact {
actor_id,
contact_id,
@@ -57,7 +57,7 @@ impl QueryContact {
}
}
fn to_contact(contact: AcceptedActors) -> Option<(String, String, Url, Url)> {
fn to_contact(contact: AcceptedActors) -> Option<(String, String, IriString, IriString)> {
let username = contact.preferred_username()?.to_owned();
let display_name = contact.name()?.as_one()?.as_xsd_string()?.to_owned();
+3 -3
View File
@@ -1,11 +1,11 @@
use crate::{error::Error, jobs::JobState};
use activitystreams::url::Url;
use activitystreams::iri_string::types::IriString;
use background_jobs::{ActixJob, Backoff};
use std::{future::Future, pin::Pin};
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct Deliver {
to: Url,
to: IriString,
data: serde_json::Value,
}
@@ -19,7 +19,7 @@ impl std::fmt::Debug for Deliver {
}
impl Deliver {
pub(crate) fn new<T>(to: Url, data: T) -> Result<Self, Error>
pub(crate) fn new<T>(to: IriString, data: T) -> Result<Self, Error>
where
T: serde::ser::Serialize,
{
+3 -3
View File
@@ -2,13 +2,13 @@ use crate::{
error::Error,
jobs::{Deliver, JobState},
};
use activitystreams::url::Url;
use activitystreams::iri_string::types::IriString;
use background_jobs::ActixJob;
use futures_util::future::LocalBoxFuture;
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct DeliverMany {
to: Vec<Url>,
to: Vec<IriString>,
data: serde_json::Value,
}
@@ -30,7 +30,7 @@ impl std::fmt::Debug for DeliverMany {
}
impl DeliverMany {
pub(crate) fn new<T>(to: Vec<Url>, data: T) -> Result<Self, Error>
pub(crate) fn new<T>(to: Vec<IriString>, data: T) -> Result<Self, Error>
where
T: serde::ser::Serialize,
{
+12 -10
View File
@@ -1,15 +1,15 @@
use crate::{
config::UrlKind,
error::Error,
error::{Error, ErrorKind},
jobs::{cache_media::CacheMedia, JobState},
};
use activitystreams::url::Url;
use activitystreams::{iri, iri_string::types::IriString};
use background_jobs::ActixJob;
use std::{future::Future, pin::Pin};
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct QueryInstance {
actor_id: Url,
actor_id: IriString,
}
impl std::fmt::Debug for QueryInstance {
@@ -21,7 +21,7 @@ impl std::fmt::Debug for QueryInstance {
}
impl QueryInstance {
pub(crate) fn new(actor_id: Url) -> Self {
pub(crate) fn new(actor_id: IriString) -> Self {
QueryInstance { actor_id }
}
@@ -40,10 +40,12 @@ impl QueryInstance {
return Ok(());
}
let mut instance_uri = self.actor_id.clone();
instance_uri.set_fragment(None);
instance_uri.set_query(None);
instance_uri.set_path("api/v1/instance");
let authority = self
.actor_id
.authority_str()
.ok_or(ErrorKind::MissingDomain)?;
let scheme = self.actor_id.scheme_str();
let instance_uri = iri!(format!("{}://{}/api/v1/instance", scheme, authority));
let instance = state
.requests
@@ -132,6 +134,6 @@ struct Instance {
struct Contact {
username: String,
display_name: String,
url: Url,
avatar: Url,
url: IriString,
avatar: IriString,
}
+13 -11
View File
@@ -1,14 +1,14 @@
use crate::{
error::Error,
error::{Error, ErrorKind},
jobs::{JobState, QueryContact},
};
use activitystreams::url::Url;
use activitystreams::{iri, iri_string::types::IriString};
use background_jobs::ActixJob;
use std::{fmt::Debug, future::Future, pin::Pin};
#[derive(Clone, serde::Deserialize, serde::Serialize)]
pub(crate) struct QueryNodeinfo {
actor_id: Url,
actor_id: IriString,
}
impl Debug for QueryNodeinfo {
@@ -20,7 +20,7 @@ impl Debug for QueryNodeinfo {
}
impl QueryNodeinfo {
pub(crate) fn new(actor_id: Url) -> Self {
pub(crate) fn new(actor_id: IriString) -> Self {
QueryNodeinfo { actor_id }
}
@@ -34,10 +34,12 @@ impl QueryNodeinfo {
return Ok(());
}
let mut well_known_uri = self.actor_id.clone();
well_known_uri.set_fragment(None);
well_known_uri.set_query(None);
well_known_uri.set_path(".well-known/nodeinfo");
let authority = self
.actor_id
.authority_str()
.ok_or(ErrorKind::MissingDomain)?;
let scheme = self.actor_id.scheme_str();
let well_known_uri = iri!(format!("{}://{}/.well-known/nodeinfo", scheme, authority));
let well_known = state
.requests
@@ -100,7 +102,7 @@ struct Nodeinfo {
#[derive(serde::Deserialize)]
#[serde(rename_all = "camelCase")]
struct Metadata {
staff_accounts: Option<Vec<Url>>,
staff_accounts: Option<Vec<IriString>>,
}
#[derive(serde::Deserialize)]
@@ -202,7 +204,7 @@ impl<'de> serde::de::Deserialize<'de> for SupportedNodeinfo {
#[cfg(test)]
mod tests {
use super::{Nodeinfo, WellKnown};
use activitystreams::url::Url;
use activitystreams::iri_string::types::IriString;
const BANANA_DOG: &'static str = r#"{"links":[{"rel":"http://nodeinfo.diaspora.software/ns/schema/2.0","href":"https://banana.dog/nodeinfo/2.0"},{"rel":"http://nodeinfo.diaspora.software/ns/schema/2.1","href":"https://banana.dog/nodeinfo/2.1"}]}"#;
const ASONIX_DOG: &'static str = r#"{"links":[{"rel":"http://nodeinfo.diaspora.software/ns/schema/2.0","href":"https://asonix.dog/nodeinfo/2.0"}]}"#;
@@ -224,7 +226,7 @@ mod tests {
assert_eq!(
accounts[0],
"https://soc.hyena.network/users/HyNET"
.parse::<Url>()
.parse::<IriString>()
.unwrap()
);
}