about summary refs log tree commit diff
path: root/kittybox-rs/src/webmentions/check.rs
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs/src/webmentions/check.rs')
-rw-r--r--kittybox-rs/src/webmentions/check.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/kittybox-rs/src/webmentions/check.rs b/kittybox-rs/src/webmentions/check.rs
index eb4afcf..f7322f7 100644
--- a/kittybox-rs/src/webmentions/check.rs
+++ b/kittybox-rs/src/webmentions/check.rs
@@ -12,7 +12,9 @@ pub enum Error {
     UrlParse(#[from] url::ParseError),
 }
 
-pub fn check_mention(document: impl AsRef<str>, base_url: &url::Url, link: &url::Url) -> Result<Option<(MentionType, serde_json::Value)>, Error> {
+#[tracing::instrument]
+pub fn check_mention(document: impl AsRef<str> + std::fmt::Debug, base_url: &url::Url, link: &url::Url) -> Result<Option<(MentionType, serde_json::Value)>, Error> {
+    tracing::debug!("Parsing MF2 markup...");
     // First, check the document for MF2 markup
     let document = microformats::from_html(document.as_ref(), base_url.clone())?;
 
@@ -22,15 +24,19 @@ pub fn check_mention(document: impl AsRef<str>, base_url: &url::Url, link: &url:
         .map(RefCell::borrow);
 
     for item in items_iter {
+        tracing::debug!("Processing item: {:?}", item);
+
         let props = item.properties.borrow();
         for (prop, interaction_type) in [
             ("in-reply-to", MentionType::Reply), ("like-of", MentionType::Like),
             ("bookmark-of", MentionType::Bookmark), ("repost-of", MentionType::Repost)
         ] {
             if let Some(propvals) = props.get(prop) {
+                tracing::debug!("Has a u-{} property", prop);
                 for val in propvals {
                     if let PropertyValue::Url(url) = val {
                         if url == link {
+                            tracing::debug!("URL matches! Webmention is valid");
                             return Ok(Some((interaction_type, serde_json::to_value(&*item).unwrap())))
                         }
                     }
@@ -38,11 +44,13 @@ pub fn check_mention(document: impl AsRef<str>, base_url: &url::Url, link: &url:
             }
         }
         // Process `content`
+        tracing::debug!("Processing e-content...");
         if let Some(PropertyValue::Fragment(content)) = props.get("content")
             .map(Vec::as_slice)
             .unwrap_or_default()
             .first()
         {
+            tracing::debug!("Parsing HTML data...");
             let root = html5ever::parse_document(html5ever::rcdom::RcDom::default(), Default::default())
                 .from_utf8()
                 .one(content.html.to_owned().as_bytes())
@@ -60,6 +68,7 @@ pub fn check_mention(document: impl AsRef<str>, base_url: &url::Url, link: &url:
             while !unprocessed_nodes.is_empty() {
                 // "Take" the list out of its memory slot, replace it with an empty list
                 let nodes = std::mem::take(&mut unprocessed_nodes);
+                tracing::debug!("Processing list of {} nodes", nodes.len());
                 'nodes_loop: for node in nodes.into_iter() {
                     // Add children nodes to the list for the next iteration
                     unprocessed_nodes.extend(node.children.borrow().iter().cloned());