about summary refs log tree commit diff
path: root/kittybox-rs/src
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs/src')
-rw-r--r--kittybox-rs/src/database/file/mod.rs2
-rw-r--r--kittybox-rs/src/database/mod.rs4
-rw-r--r--kittybox-rs/src/database/postgres/mod.rs8
-rw-r--r--kittybox-rs/src/webmentions/check.rs11
-rw-r--r--kittybox-rs/src/webmentions/mod.rs2
-rw-r--r--kittybox-rs/src/webmentions/queue.rs7
6 files changed, 25 insertions, 9 deletions
diff --git a/kittybox-rs/src/database/file/mod.rs b/kittybox-rs/src/database/file/mod.rs
index ca8e2ac..27d3da1 100644
--- a/kittybox-rs/src/database/file/mod.rs
+++ b/kittybox-rs/src/database/file/mod.rs
@@ -703,7 +703,7 @@ impl Storage for FileStorage {
         };
 
         let key: &'static str = match mention_type {
-            MentionType::Reply => "reply",
+            MentionType::Reply => "comment",
             MentionType::Like => "like",
             MentionType::Repost => "repost",
             MentionType::Bookmark => "bookmark",
diff --git a/kittybox-rs/src/database/mod.rs b/kittybox-rs/src/database/mod.rs
index 98fe6ca..4f1c4de 100644
--- a/kittybox-rs/src/database/mod.rs
+++ b/kittybox-rs/src/database/mod.rs
@@ -708,13 +708,13 @@ mod tests {
         db.add_or_update_webmention(target, TYPE, reply.clone()).await.unwrap();
 
         let (read_post, _) = db.read_feed_with_cursor(target, None, 20, None).await.unwrap().unwrap();
-        assert_eq!(read_post["properties"]["reply"][0], reply);
+        assert_eq!(read_post["properties"]["comment"][0], reply);
 
         reply["properties"]["content"][0] = json!(rand::random::<faker_rand::lorem::Paragraphs>().to_string());
 
         db.add_or_update_webmention(target, TYPE, reply.clone()).await.unwrap();
         let (read_post, _) = db.read_feed_with_cursor(target, None, 20, None).await.unwrap().unwrap();
-        assert_eq!(read_post["properties"]["reply"][0], reply);
+        assert_eq!(read_post["properties"]["comment"][0], reply);
     }
 
     /// Automatically generates a test suite for
diff --git a/kittybox-rs/src/database/postgres/mod.rs b/kittybox-rs/src/database/postgres/mod.rs
index b1a03b1..4477b9c 100644
--- a/kittybox-rs/src/database/postgres/mod.rs
+++ b/kittybox-rs/src/database/postgres/mod.rs
@@ -130,6 +130,7 @@ impl Storage for PostgresStorage {
             .map(|_| ())
     }
 
+    #[tracing::instrument(skip(self))]
     async fn add_or_update_webmention(&self, target: &str, mention_type: MentionType, mention: serde_json::Value) -> Result<()> {
         let mut txn = self.db.begin().await?;
 
@@ -142,13 +143,18 @@ impl Storage for PostgresStorage {
                 "The specified post wasn't found in the database."
             ))?;
 
+        tracing::debug!("Loaded post for target {} with uid {}", target, uid);
+
         let key: &'static str = match mention_type {
-            MentionType::Reply => "reply",
+            MentionType::Reply => "comment",
             MentionType::Like => "like",
             MentionType::Repost => "repost",
             MentionType::Bookmark => "bookmark",
             MentionType::Mention => "mention",
         };
+
+        tracing::debug!("Mention type -> key: {}", key);
+
         let mention_uid = mention["properties"]["uid"][0].clone();
         if let Some(values) = post["properties"][key].as_array_mut() {
             for value in values.iter_mut() {
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());
diff --git a/kittybox-rs/src/webmentions/mod.rs b/kittybox-rs/src/webmentions/mod.rs
index a47fadb..95ea870 100644
--- a/kittybox-rs/src/webmentions/mod.rs
+++ b/kittybox-rs/src/webmentions/mod.rs
@@ -15,7 +15,7 @@ pub struct Webmention {
 
 impl queue::JobItem for Webmention {}
 impl queue::PostgresJobItem for Webmention {
-    const DATABASE_NAME: &'static str = "kittybox.incoming_webmention_queue";
+    const DATABASE_NAME: &'static str = "kittybox_webmention.incoming_webmention_queue";
     const NOTIFICATION_CHANNEL: &'static str = "incoming_webmention";
 }
 
diff --git a/kittybox-rs/src/webmentions/queue.rs b/kittybox-rs/src/webmentions/queue.rs
index dc7d8f9..b811e71 100644
--- a/kittybox-rs/src/webmentions/queue.rs
+++ b/kittybox-rs/src/webmentions/queue.rs
@@ -205,9 +205,10 @@ impl JobQueue<Webmention> for PostgresJobQueue<Webmention> {
 mod tests {
     use std::sync::Arc;
 
-    use super::{Webmention, PostgresJobQueue, Job, JobQueue};
+    use super::{Webmention, PostgresJobQueue, Job, JobQueue, MIGRATOR};
     use futures_util::StreamExt;
-    #[sqlx::test]
+
+    #[sqlx::test(migrator = "MIGRATOR")]
     #[tracing_test::traced_test]
     async fn test_webmention_queue(pool: sqlx::PgPool) -> Result<(), sqlx::Error> {
         let test_webmention = Webmention {
@@ -248,7 +249,7 @@ mod tests {
         }
     }
 
-    #[sqlx::test]
+    #[sqlx::test(migrator = "MIGRATOR")]
     #[tracing_test::traced_test]
     async fn test_no_hangups_in_queue(pool: sqlx::PgPool) -> Result<(), sqlx::Error> {
         let test_webmention = Webmention {