Compare commits

..

No commits in common. "072c7c4b8bce37e3db9d8088a541f59e570b7707" and "11fb6d617c934c37b097abcb4d8762720392e9ae" have entirely different histories.

2 changed files with 45 additions and 62 deletions

View file

@ -8,8 +8,6 @@ pkgs.mkShell {
rust-analyzer rust-analyzer
clippy clippy
bacon
pkg-config pkg-config
openssl openssl
]; ];

View file

@ -130,70 +130,55 @@ async fn _post_comment(
} }
None => return Err(Error::InvalidUrl), // e.g. 404 None => return Err(Error::InvalidUrl), // e.g. 404
}; };
// TODO: Use web::block // TODO: Clean up webhook integration
// Create comment in database {
let database = data.get_db(&origin)?; let database = data.get_db(&origin)?;
if comment.author.is_none() && database.settings.name_required { if let Some(webhook) = &database.settings.webhook {
return Err(Error::NameRequired); let client = WebhookClient::new(&webhook);
} client.send(|message| {
if comment.email.is_none() && database.settings.email_required { let author = match &comment.author {
return Err(Error::EmailRequired); Some(author) => &author,
} None => "Annonymous",
if let Some(parent) = comment.parent { };
'outer2: loop { message
let comments = database.get_comments(&comment.content_id)?; .username(&author)
for other_comment in comments.iter() { .avatar_url(&format!(
if other_comment.id.unwrap() == parent { "https://www.gravatar.com/avatar/{}?d=mp",
if other_comment.parent.is_none() { get_gravatar(&comment.email)
break 'outer2; ))
} .embed(|embed| embed
break; .title(&format!("New comment on {}", page_data.content_id))
.description(&comment.text)
)
} }
} ).await.unwrap();
return Err(Error::InvalidParent);
} }
} }
database.create_comment(&comment)?; web::block(move || {
// Send notification webhook let database = data.get_db(&origin)?;
if let Some(webhook) = &database.settings.webhook { if comment.author.is_none() && database.settings.name_required {
let client = WebhookClient::new(&webhook); return Err(Error::NameRequired);
client.send(|message| { }
let author = match &comment.author { if comment.email.is_none() && database.settings.email_required {
Some(author) => &author, return Err(Error::EmailRequired);
None => "Annonymous", }
}; if let Some(parent) = comment.parent {
message 'outer2: loop {
.username(&author) let comments = database.get_comments(&comment.content_id)?;
.avatar_url(&format!( for other_comment in comments.iter() {
"https://www.gravatar.com/avatar/{}?d=mp", if other_comment.id.unwrap() == parent {
get_gravatar(&comment.email) if other_comment.parent.is_none() {
)) break 'outer2;
.embed(|embed| embed }
.title(&format!("New comment on {}", page_data.content_id)) break;
.description(&comment.text) }
.field("Link", &format!("{}#{}", }
&url // Remove any trailing hash from URL return Err(Error::InvalidParent);
.split("#")
.next()
.unwrap(),
&database // Get ID of just created comment
.get_comments(&page_data.content_id)
.unwrap()
.first() // returned in reverse chronological order
.unwrap()
.id
.unwrap()
), true)
.field("Content ID", &page_data.content_id, true)
.field("Email", match &comment.email {
Some(email) => email,
None => "None",
}, false)
)
} }
).await.unwrap(); }
} database.create_comment(&comment)?;
Ok(())
}).await?.unwrap();
Ok(()) Ok(())
} }