Browse Source

Fix some TODOs in activitypub code

fix-todos
Felix Ableitner 6 months ago
parent
commit
7f2b4c9554
6 changed files with 37 additions and 58 deletions
  1. +13
    -13
      server/src/apub/comment.rs
  2. +9
    -12
      server/src/apub/community.rs
  3. +0
    -18
      server/src/apub/fetcher.rs
  4. +2
    -2
      server/src/apub/mod.rs
  5. +12
    -12
      server/src/apub/post.rs
  6. +1
    -1
      server/src/apub/user.rs

+ 13
- 13
server/src/apub/comment.rs View File

@ -297,7 +297,7 @@ impl ApubObjectType for Comment {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -331,7 +331,7 @@ impl ApubObjectType for Comment {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
@ -339,7 +339,7 @@ impl ApubObjectType for Comment {
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -372,7 +372,7 @@ impl ApubObjectType for Comment {
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&mod_,
@ -406,7 +406,7 @@ impl ApubObjectType for Comment {
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@ -414,7 +414,7 @@ impl ApubObjectType for Comment {
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&mod_,
@ -450,7 +450,7 @@ impl ApubLikeableType for Comment {
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -483,7 +483,7 @@ impl ApubLikeableType for Comment {
.set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -516,7 +516,7 @@ impl ApubLikeableType for Comment {
.set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
@ -524,7 +524,7 @@ impl ApubLikeableType for Comment {
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -540,7 +540,7 @@ impl ApubLikeableType for Comment {
}
struct MentionsAndAddresses {
addressed_ccs: Vec<String>,
addressed_ccs: Vec<Url>,
inboxes: Vec<Url>,
tags: Vec<Mention>,
}
@ -564,7 +564,7 @@ async fn collect_non_local_mentions_and_addresses(
client: &Client,
pool: &DbPool,
) -> Result<MentionsAndAddresses, LemmyError> {
let mut addressed_ccs = vec![community.get_followers_url()];
let mut addressed_ccs = vec![community.get_followers_url()?];
// Add the mention tag
let mut tags = Vec::new();
@ -581,7 +581,7 @@ async fn collect_non_local_mentions_and_addresses(
// TODO should it be fetching it every time?
if let Ok(actor_id) = fetch_webfinger_url(mention, client).await {
debug!("mention actor_id: {}", actor_id);
addressed_ccs.push(actor_id.to_owned().to_string());
addressed_ccs.push(actor_id.to_owned().to_string().parse()?);
let mention_user = get_or_fetch_and_upsert_user(&actor_id, client, pool).await?;
let shared_inbox = mention_user.get_shared_inbox_url()?;


+ 9
- 12
server/src/apub/community.rs View File

@ -95,7 +95,7 @@ impl ToApub for Community {
ap_actor
.set_preferred_username(self.title.to_owned())
.set_outbox(self.get_outbox_url()?)
.set_followers(self.get_followers_url().parse()?)
.set_followers(self.get_followers_url()?)
.set_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints {
@ -174,7 +174,7 @@ impl ActorType for Community {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
.set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, delete.clone(), true, pool).await?;
@ -200,16 +200,14 @@ impl ActorType for Community {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
.set_many_ccs(vec![self.get_followers_url()?]);
// TODO
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
undo
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
.set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(self.creator_id, undo.clone(), true, pool).await?;
@ -235,7 +233,7 @@ impl ActorType for Community {
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
.set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, remove.clone(), true, pool).await?;
@ -261,7 +259,7 @@ impl ActorType for Community {
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
.set_many_ccs(vec![self.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@ -269,7 +267,7 @@ impl ActorType for Community {
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![self.get_followers_url()]);
.set_many_ccs(vec![self.get_followers_url()?]);
insert_activity(mod_.id, undo.clone(), true, pool).await?;
@ -474,8 +472,7 @@ pub async fn get_apub_community_followers(
let mut collection = UnorderedCollection::new();
collection
.set_context(context())
// TODO: this needs its own ID
.set_id(community.actor_id.parse()?)
.set_id(community.get_followers_url()?)
.set_total_items(community_followers.len() as u64);
Ok(create_apub_response(&collection))
}
@ -522,7 +519,7 @@ pub async fn do_announce(
.set_context(context())
.set_id(generate_activity_id(AnnounceType::Announce)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
insert_activity(community.creator_id, announce.clone(), true, pool).await?;


+ 0
- 18
server/src/apub/fetcher.rs View File

@ -146,8 +146,6 @@ pub async fn search_by_apub_id(
let community = get_or_fetch_and_upsert_community(community_uri, client, pool).await?;
// TODO Maybe at some point in the future, fetch all the history of a community
// fetch_community_outbox(&c, conn)?;
response.communities = vec![
blocking(pool, move |conn| {
CommunityView::read(conn, community.id, None)
@ -166,24 +164,8 @@ pub async fn search_by_apub_id(
response
}
SearchAcceptedObjects::Comment(c) => {
let post_url = c
.in_reply_to()
.as_ref()
.context(location_info!())?
.as_many()
.context(location_info!())?;
// TODO: also fetch parent comments if any
let x = post_url
.first()
.context(location_info!())?
.as_xsd_any_uri()
.context(location_info!())?;
let post = fetch_remote_object(client, x).await?;
let post_form = PostForm::from_apub(&post, client, pool, Some(query_url.clone())).await?;
let comment_form = CommentForm::from_apub(&c, client, pool, Some(query_url)).await?;
blocking(pool, move |conn| upsert_post(&post_form, conn)).await??;
let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??;
response.comments =
vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??];


+ 2
- 2
server/src/apub/mod.rs View File

@ -328,8 +328,8 @@ pub trait ActorType {
Url::parse(&format!("{}/outbox", &self.actor_id_str()))
}
fn get_followers_url(&self) -> String {
format!("{}/followers", &self.actor_id_str())
fn get_followers_url(&self) -> Result<Url, ParseError> {
Url::parse(&format!("{}/followers", &self.actor_id_str()))
}
fn get_following_url(&self) -> String {


+ 12
- 12
server/src/apub/post.rs View File

@ -316,7 +316,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(CreateType::Create)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
@ -347,7 +347,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(UpdateType::Update)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
@ -377,7 +377,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
@ -407,7 +407,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(DeleteType::Delete)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), delete.into_any_base()?);
@ -415,7 +415,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
creator,
@ -445,7 +445,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
mod_,
@ -475,7 +475,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(RemoveType::Remove)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(mod_.actor_id.to_owned(), remove.into_any_base()?);
@ -483,7 +483,7 @@ impl ApubObjectType for Post {
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
mod_,
@ -516,7 +516,7 @@ impl ApubLikeableType for Post {
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -546,7 +546,7 @@ impl ApubLikeableType for Post {
.set_context(context())
.set_id(generate_activity_id(DislikeType::Dislike)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,
@ -576,7 +576,7 @@ impl ApubLikeableType for Post {
.set_context(context())
.set_id(generate_activity_id(LikeType::Like)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
// Undo that fake activity
let mut undo = Undo::new(creator.actor_id.to_owned(), like.into_any_base()?);
@ -584,7 +584,7 @@ impl ApubLikeableType for Post {
.set_context(context())
.set_id(generate_activity_id(UndoType::Undo)?)
.set_to(public())
.set_many_ccs(vec![community.get_followers_url()]);
.set_many_ccs(vec![community.get_followers_url()?]);
send_activity_to_community(
&creator,


+ 1
- 1
server/src/apub/user.rs View File

@ -80,7 +80,7 @@ impl ToApub for User_ {
let mut ap_actor = ApActor::new(self.get_inbox_url()?, person);
ap_actor
.set_outbox(self.get_outbox_url()?)
.set_followers(self.get_followers_url().parse()?)
.set_followers(self.get_followers_url()?)
.set_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints {


Loading…
Cancel
Save