From: Felix Ableitner Date: Tue, 6 Oct 2020 16:28:31 +0000 (+0200) Subject: Avoid duplicate comment send, better activity logging X-Git-Url: http://these/git/%24%7BgetStaticDir%28%29%7D/styles/static/%7BpictshareAvatarThumbnail%28?a=commitdiff_plain;h=60730e81d9ef6b069ae7e63b79740366d2d44645;p=lemmy.git Avoid duplicate comment send, better activity logging --- diff --git a/lemmy_apub/src/activity_queue.rs b/lemmy_apub/src/activity_queue.rs index 2f11024c..84675659 100644 --- a/lemmy_apub/src/activity_queue.rs +++ b/lemmy_apub/src/activity_queue.rs @@ -6,7 +6,7 @@ use crate::{ ActorType, }; use activitystreams::{ - base::{Extends, ExtendsExt}, + base::{BaseExt, Extends, ExtendsExt}, object::AsObject, }; use anyhow::{anyhow, Context, Error}; @@ -23,9 +23,9 @@ use itertools::Itertools; use lemmy_db::{community::Community, user::User_, DbPool}; use lemmy_utils::{location_info, settings::Settings, LemmyError}; use lemmy_websocket::LemmyContext; -use log::warn; +use log::{debug, warn}; use reqwest::Client; -use serde::{Deserialize, Serialize}; +use serde::{export::fmt::Debug, Deserialize, Serialize}; use std::{collections::BTreeMap, future::Future, pin::Pin}; use url::Url; @@ -36,11 +36,12 @@ pub async fn send_activity_single_dest( context: &LemmyContext, ) -> Result<(), LemmyError> where - T: AsObject + Extends, + T: AsObject + Extends + Debug + BaseExt, Kind: Serialize, >::Error: From + Send + Sync + 'static, { if check_is_apub_id_valid(&to).is_ok() { + debug!("Sending activity {:?} to {}", &activity.id_unchecked(), &to); send_activity_internal( context.activity_queue(), activity, @@ -62,7 +63,7 @@ pub async fn send_to_community_followers( sender_shared_inbox: Option, ) -> Result<(), LemmyError> where - T: AsObject + Extends, + T: AsObject + Extends + Debug + BaseExt, Kind: Serialize, >::Error: From + Send + Sync + 'static, { @@ -79,6 +80,11 @@ where .unique() .map(|inbox| inbox.to_owned()) .collect(); + debug!( + "Sending activity {:?} to followers of {}", + &activity.id_unchecked(), + &community.actor_id + ); send_activity_internal( context.activity_queue(), @@ -100,7 +106,7 @@ pub async fn send_to_community( context: &LemmyContext, ) -> Result<(), LemmyError> where - T: AsObject + Extends, + T: AsObject + Extends + Debug + BaseExt, Kind: Serialize, >::Error: From + Send + Sync + 'static, { @@ -110,6 +116,11 @@ where } else { let inbox = community.get_shared_inbox_url()?; check_is_apub_id_valid(&inbox)?; + debug!( + "Sending activity {:?} to community {}", + &activity.id_unchecked(), + &community.actor_id + ); send_activity_internal( context.activity_queue(), activity, @@ -131,10 +142,16 @@ pub async fn send_comment_mentions( context: &LemmyContext, ) -> Result<(), LemmyError> where - T: AsObject + Extends, + T: AsObject + Extends + Debug + BaseExt, Kind: Serialize, >::Error: From + Send + Sync + 'static, { + dbg!(&mentions, &activity.id_unchecked()); + debug!( + "Sending mentions activity {:?} to {:?}", + &activity.id_unchecked(), + &mentions + ); let mentions = mentions .iter() .filter(|inbox| check_is_apub_id_valid(inbox).is_ok()) @@ -165,7 +182,7 @@ async fn send_activity_internal( insert_into_db: bool, ) -> Result<(), LemmyError> where - T: AsObject + Extends, + T: AsObject + Extends + Debug, Kind: Serialize, >::Error: From + Send + Sync + 'static, { diff --git a/lemmy_apub/src/comment.rs b/lemmy_apub/src/comment.rs index 35be5522..33ad1d8a 100644 --- a/lemmy_apub/src/comment.rs +++ b/lemmy_apub/src/comment.rs @@ -506,12 +506,7 @@ async fn collect_non_local_mentions_and_addresses( } } - let mut inboxes: Vec = vec![]; - if !community.local { - inboxes.push(community.get_shared_inbox_url()?); - } - inboxes.extend(mention_inboxes); - inboxes = inboxes.into_iter().unique().collect(); + let inboxes = mention_inboxes.into_iter().unique().collect(); Ok(MentionsAndAddresses { addressed_ccs, diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index ee75fa00..d979e27f 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -57,14 +57,16 @@ pub async fn community_inbox( .into(), ); } - debug!( - "Community {} received activity {:?}", - &community.name, &activity - ); let user_uri = activity .actor()? .as_single_xsd_any_uri() .context(location_info!())?; + debug!( + "Community {} inbox received activity {:?} from {}", + community.name, + &activity.id_unchecked(), + &user_uri + ); check_is_apub_id_valid(user_uri)?; let user = get_or_fetch_and_upsert_user(&user_uri, &context).await?; diff --git a/lemmy_apub/src/inbox/shared_inbox.rs b/lemmy_apub/src/inbox/shared_inbox.rs index 677ceadf..2d69336f 100644 --- a/lemmy_apub/src/inbox/shared_inbox.rs +++ b/lemmy_apub/src/inbox/shared_inbox.rs @@ -60,17 +60,17 @@ pub async fn shared_inbox( ) -> Result { let activity = input.into_inner(); - let json = serde_json::to_string_pretty(&activity)?; - debug!("Shared inbox received activity: {}", json); - - // TODO: if we already received an activity with identical ID, then ignore this (same in other inboxes) - let sender = &activity .actor()? .to_owned() .single_xsd_any_uri() .context(location_info!())?; let community = get_community_id_from_activity(&activity)?; + debug!( + "Shared inbox received activity {:?} from {}", + &activity.id_unchecked(), + &sender + ); check_is_apub_id_valid(sender)?; check_is_apub_id_valid(&community)?; diff --git a/lemmy_apub/src/inbox/user_inbox.rs b/lemmy_apub/src/inbox/user_inbox.rs index a7050c45..c411f5b7 100644 --- a/lemmy_apub/src/inbox/user_inbox.rs +++ b/lemmy_apub/src/inbox/user_inbox.rs @@ -50,12 +50,17 @@ pub async fn user_inbox( ) -> Result { let activity = input.into_inner(); let username = path.into_inner(); - debug!("User {} received activity: {:?}", &username, &activity); let actor_uri = activity .actor()? .as_single_xsd_any_uri() .context(location_info!())?; + debug!( + "User {} inbox received activity {:?} from {}", + username, + &activity.id_unchecked(), + &actor_uri + ); check_is_apub_id_valid(actor_uri)?;