use post url instead of instance or, better error handling

support-webmentions
Felix Ableitner 2021-09-17 15:29:17 +02:00
parent 53079c113a
commit 75e758b557
1 changed files with 14 additions and 13 deletions

View File

@ -21,7 +21,6 @@ use lemmy_db_queries::{source::post::Post_, Crud, Likeable};
use lemmy_db_schema::source::post::*; use lemmy_db_schema::source::post::*;
use lemmy_utils::{ use lemmy_utils::{
request::fetch_site_data, request::fetch_site_data,
settings::structs::Settings,
utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title}, utils::{check_slurs, check_slurs_opt, clean_url_params, is_valid_post_title},
ApiError, ApiError,
ConnectionId, ConnectionId,
@ -29,8 +28,7 @@ use lemmy_utils::{
}; };
use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud}; use lemmy_websocket::{send::send_post_ws_message, LemmyContext, UserOperationCrud};
use log::warn; use log::warn;
use url::Url; use webmention::{Webmention, WebmentionError};
use webmention::Webmention;
#[async_trait::async_trait(?Send)] #[async_trait::async_trait(?Send)]
impl PerformCrud for CreatePost { impl PerformCrud for CreatePost {
@ -129,7 +127,19 @@ impl PerformCrud for CreatePost {
// Mark the post as read // Mark the post as read
mark_post_as_read(person_id, post_id, context.pool()).await?; 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)); let object = PostOrComment::Post(Box::new(updated_post));
Vote::send( Vote::send(
&object, &object,
@ -140,15 +150,6 @@ impl PerformCrud for CreatePost {
) )
.await?; .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( send_post_ws_message(
inserted_post.id, inserted_post.id,
UserOperationCrud::CreatePost, UserOperationCrud::CreatePost,