Fix some TODOs in activitypub code

This commit is contained in:
Felix Ableitner 2020-08-12 14:15:07 +02:00
parent d95bdd61a4
commit 7f2b4c9554
6 changed files with 37 additions and 58 deletions

View file

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

View file

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

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?; 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![ response.communities = vec![
blocking(pool, move |conn| { blocking(pool, move |conn| {
CommunityView::read(conn, community.id, None) CommunityView::read(conn, community.id, None)
@ -166,24 +164,8 @@ pub async fn search_by_apub_id(
response response
} }
SearchAcceptedObjects::Comment(c) => { 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?; 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??; let c = blocking(pool, move |conn| upsert_comment(&comment_form, conn)).await??;
response.comments = response.comments =
vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??]; vec![blocking(pool, move |conn| CommentView::read(conn, c.id, None)).await??];

View file

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

View file

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

View file

@ -80,7 +80,7 @@ impl ToApub for User_ {
let mut ap_actor = ApActor::new(self.get_inbox_url()?, person); let mut ap_actor = ApActor::new(self.get_inbox_url()?, person);
ap_actor ap_actor
.set_outbox(self.get_outbox_url()?) .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_following(self.get_following_url().parse()?)
.set_liked(self.get_liked_url().parse()?) .set_liked(self.get_liked_url().parse()?)
.set_endpoints(Endpoints { .set_endpoints(Endpoints {