From 75e758b557b9c9f3930dd43c022023c1270814d6 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 17 Sep 2021 15:29:17 +0200 Subject: [PATCH] use post url instead of instance or, better error handling --- crates/api_crud/src/post/create.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 122b5cbfd..3a5883ff3 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -21,7 +21,6 @@ use lemmy_db_queries::{source::post::Post_, Crud, Likeable}; use lemmy_db_schema::source::post::*; use lemmy_utils::{ request::fetch_site_data, - settings::structs::Settings, utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title}, ApiError, ConnectionId, @@ -29,8 +28,7 @@ use lemmy_utils::{ }; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; use log::warn; -use url::Url; -use webmention::Webmention; +use webmention::{Webmention, WebmentionError}; #[async_trait::async_trait(?Send)] impl PerformCrud for CreatePost { @@ -129,7 +127,19 @@ impl PerformCrud for CreatePost { // Mark the post as read mark_post_as_read(person_id, post_id, context.pool()).await?; - let updated_post_url = updated_post.url.clone(); + if let Some(url) = &updated_post.url { + let mut webmention = Webmention::new( + updated_post.ap_id.clone().into_inner(), + url.clone().into_inner(), + )?; + webmention.set_checked(true); + match webmention.send().await { + Ok(_) => {} + Err(WebmentionError::NoEndpointDiscovered(_)) => {} + Err(e) => warn!("Failed to send webmention: {}", e), + } + } + let object = PostOrComment::Post(Box::new(updated_post)); Vote::send( &object, @@ -140,15 +150,6 @@ impl PerformCrud for CreatePost { ) .await?; - if let Some(url) = updated_post_url { - let hostname = Url::parse(&Settings::get().get_protocol_and_hostname())?; - let mut webmention: Webmention = (hostname, url.into_inner()).into(); - webmention.set_checked(true); - if let Err(e) = webmention.send().await { - warn!("Failed to send webmention: {}", e); - } - } - send_post_ws_message( inserted_post.id, UserOperationCrud::CreatePost,