Adjustments to make Lemmy compile
This commit is contained in:
parent
68e4cce4ec
commit
1cdb2b098d
4 changed files with 35 additions and 17 deletions
|
@ -4,7 +4,11 @@ use crate::{
|
||||||
instance::InstanceHandle,
|
instance::InstanceHandle,
|
||||||
objects::person::MyUser,
|
objects::person::MyUser,
|
||||||
};
|
};
|
||||||
use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler};
|
use activitypub_federation::{
|
||||||
|
core::object_id::ObjectId,
|
||||||
|
data::Data,
|
||||||
|
traits::{ActivityHandler, Actor},
|
||||||
|
};
|
||||||
use activitystreams_kinds::activity::FollowType;
|
use activitystreams_kinds::activity::FollowType;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -73,7 +77,11 @@ impl ActivityHandler for Follow {
|
||||||
let id = generate_object_id(data.local_instance().hostname())?;
|
let id = generate_object_id(data.local_instance().hostname())?;
|
||||||
let accept = Accept::new(local_user.ap_id.clone(), self, id.clone());
|
let accept = Accept::new(local_user.ap_id.clone(), self, id.clone());
|
||||||
local_user
|
local_user
|
||||||
.send(accept, &[follower], data.local_instance())
|
.send(
|
||||||
|
accept,
|
||||||
|
vec![follower.shared_inbox_or_inbox()],
|
||||||
|
data.local_instance(),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,11 @@ impl MyUser {
|
||||||
pub async fn follow(&self, other: &MyUser, instance: &InstanceHandle) -> Result<(), Error> {
|
pub async fn follow(&self, other: &MyUser, instance: &InstanceHandle) -> Result<(), Error> {
|
||||||
let id = generate_object_id(instance.local_instance().hostname())?;
|
let id = generate_object_id(instance.local_instance().hostname())?;
|
||||||
let follow = Follow::new(self.ap_id.clone(), other.ap_id.clone(), id.clone());
|
let follow = Follow::new(self.ap_id.clone(), other.ap_id.clone(), id.clone());
|
||||||
self.send(follow, &[other.clone()], instance.local_instance())
|
self.send(
|
||||||
|
follow,
|
||||||
|
vec![other.shared_inbox_or_inbox()],
|
||||||
|
instance.local_instance(),
|
||||||
|
)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -92,27 +96,26 @@ impl MyUser {
|
||||||
pub async fn post(&self, post: MyPost, instance: &InstanceHandle) -> Result<(), Error> {
|
pub async fn post(&self, post: MyPost, instance: &InstanceHandle) -> Result<(), Error> {
|
||||||
let id = generate_object_id(instance.local_instance().hostname())?;
|
let id = generate_object_id(instance.local_instance().hostname())?;
|
||||||
let create = CreateNote::new(post.into_apub(instance).await?, id.clone());
|
let create = CreateNote::new(post.into_apub(instance).await?, id.clone());
|
||||||
let mut recipients = vec![];
|
let mut inboxes = vec![];
|
||||||
for f in self.followers.clone() {
|
for f in self.followers.clone() {
|
||||||
let user: MyUser = ObjectId::new(f)
|
let user: MyUser = ObjectId::new(f)
|
||||||
.dereference(instance, instance.local_instance(), &mut 0)
|
.dereference(instance, instance.local_instance(), &mut 0)
|
||||||
.await?;
|
.await?;
|
||||||
recipients.push(user);
|
inboxes.push(user.shared_inbox_or_inbox());
|
||||||
}
|
}
|
||||||
self.send(create, &recipients, instance.local_instance())
|
self.send(create, inboxes, instance.local_instance())
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn send<Activity, ActorT>(
|
pub(crate) async fn send<Activity>(
|
||||||
&self,
|
&self,
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
recipients: &[ActorT],
|
recipients: Vec<Url>,
|
||||||
local_instance: &LocalInstance,
|
local_instance: &LocalInstance,
|
||||||
) -> Result<(), <Activity as ActivityHandler>::Error>
|
) -> Result<(), <Activity as ActivityHandler>::Error>
|
||||||
where
|
where
|
||||||
Activity: ActivityHandler + Serialize,
|
Activity: ActivityHandler + Serialize,
|
||||||
ActorT: Actor,
|
|
||||||
<Activity as ActivityHandler>::Error: From<anyhow::Error> + From<serde_json::Error>,
|
<Activity as ActivityHandler>::Error: From<anyhow::Error> + From<serde_json::Error>,
|
||||||
{
|
{
|
||||||
let activity = WithContext::new_default(activity);
|
let activity = WithContext::new_default(activity);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
core::signatures::{sign_request, PublicKey},
|
core::signatures::{sign_request, PublicKey},
|
||||||
traits::{ActivityHandler, Actor},
|
traits::ActivityHandler,
|
||||||
utils::verify_url_valid,
|
utils::verify_url_valid,
|
||||||
Error,
|
Error,
|
||||||
InstanceSettings,
|
InstanceSettings,
|
||||||
|
@ -33,23 +33,21 @@ use url::Url;
|
||||||
/// - `private_key`: The sending actor's private key for signing HTTP signature
|
/// - `private_key`: The sending actor's private key for signing HTTP signature
|
||||||
/// - `recipients`: List of actors who should receive the activity. This gets deduplicated, and
|
/// - `recipients`: List of actors who should receive the activity. This gets deduplicated, and
|
||||||
/// local/invalid inbox urls removed
|
/// local/invalid inbox urls removed
|
||||||
pub async fn send_activity<Activity, ActorT: Actor>(
|
pub async fn send_activity<Activity>(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
public_key: PublicKey,
|
public_key: PublicKey,
|
||||||
private_key: String,
|
private_key: String,
|
||||||
recipients: &[ActorT],
|
recipients: Vec<Url>,
|
||||||
instance: &LocalInstance,
|
instance: &LocalInstance,
|
||||||
) -> Result<(), <Activity as ActivityHandler>::Error>
|
) -> Result<(), <Activity as ActivityHandler>::Error>
|
||||||
where
|
where
|
||||||
Activity: ActivityHandler + Serialize,
|
Activity: ActivityHandler + Serialize,
|
||||||
ActorT: Actor,
|
|
||||||
<Activity as ActivityHandler>::Error: From<anyhow::Error> + From<serde_json::Error>,
|
<Activity as ActivityHandler>::Error: From<anyhow::Error> + From<serde_json::Error>,
|
||||||
{
|
{
|
||||||
let activity_id = activity.id();
|
let activity_id = activity.id();
|
||||||
let activity_serialized = serde_json::to_string_pretty(&activity)?;
|
let activity_serialized = serde_json::to_string_pretty(&activity)?;
|
||||||
let inboxes: Vec<Url> = recipients
|
let inboxes: Vec<Url> = recipients
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|r| r.inbox())
|
|
||||||
.unique()
|
.unique()
|
||||||
.filter(|i| !instance.is_local_url(i))
|
.filter(|i| !instance.is_local_url(i))
|
||||||
.filter(|i| verify_url_valid(i, &instance.settings).is_ok())
|
.filter(|i| verify_url_valid(i, &instance.settings).is_ok())
|
||||||
|
|
|
@ -94,6 +94,15 @@ pub trait Actor: ApubObject {
|
||||||
/// Returns the actor's public key for verification of HTTP signatures
|
/// Returns the actor's public key for verification of HTTP signatures
|
||||||
fn public_key(&self) -> &str;
|
fn public_key(&self) -> &str;
|
||||||
|
|
||||||
/// The inbox or shared inbox where activities for this user should be sent to
|
/// The inbox where activities for this user should be sent to
|
||||||
fn inbox(&self) -> Url;
|
fn inbox(&self) -> Url;
|
||||||
|
|
||||||
|
/// The actor's shared inbox, if any
|
||||||
|
fn shared_inbox(&self) -> Option<Url> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn shared_inbox_or_inbox(&self) -> Url {
|
||||||
|
self.shared_inbox().unwrap_or_else(|| self.inbox())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue