about summary refs log tree commit diff
path: root/src/webmentions/check.rs
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-01 22:50:28 +0300
committerVika <vika@fireburn.ru>2024-08-02 16:13:39 +0300
commit2318a33f9b359ae27b52cd9a19db1f6782d8dae3 (patch)
tree5f4dc1ad73d5c4104679a1976781861ec23cb20e /src/webmentions/check.rs
parent61a6bf6b80aea18d8b7af159d504004a29e50576 (diff)
downloadkittybox-2318a33f9b359ae27b52cd9a19db1f6782d8dae3.tar.zst
Upgrade dependencies and fix deprecated functionality
I think I managed to not lose any functionality from my dependencies.

sqlparser remains unupgraded, but that's mostly because it is only
used in one example and it's not worth it to upgrade right now.
Diffstat (limited to 'src/webmentions/check.rs')
-rw-r--r--src/webmentions/check.rs23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/webmentions/check.rs b/src/webmentions/check.rs
index 6dc6a25..178c008 100644
--- a/src/webmentions/check.rs
+++ b/src/webmentions/check.rs
@@ -1,7 +1,11 @@
-use std::{cell::RefCell, rc::Rc};
-use microformats::{types::PropertyValue, html5ever::{self, tendril::TendrilSink}};
+use std::rc::Rc;
+use microformats::types::PropertyValue;
+use html5ever::{self, tendril::TendrilSink};
 use kittybox_util::MentionType;
 
+// TODO: replace.
+mod rcdom;
+
 #[derive(thiserror::Error, Debug)]
 pub enum Error {
     #[error("microformats error: {0}")]
@@ -19,19 +23,16 @@ pub fn check_mention(document: impl AsRef<str> + std::fmt::Debug, base_url: &url
     let document = microformats::from_html(document.as_ref(), base_url.clone())?;
 
     // Get an iterator of all items
-    let items_iter = document.items.iter()
-        .map(AsRef::as_ref)
-        .map(RefCell::borrow);
+    let items_iter = document.items.iter();
 
     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) {
+            if let Some(propvals) = item.properties.get(prop) {
                 tracing::debug!("Has a u-{} property", prop);
                 for val in propvals {
                     if let PropertyValue::Url(url) = val {
@@ -45,13 +46,13 @@ pub fn check_mention(document: impl AsRef<str> + std::fmt::Debug, base_url: &url
         }
         // Process `content`
         tracing::debug!("Processing e-content...");
-        if let Some(PropertyValue::Fragment(content)) = props.get("content")
+        if let Some(PropertyValue::Fragment(content)) = item.properties.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())
+            let root = html5ever::parse_document(rcdom::RcDom::default(), Default::default())
                 .from_utf8()
                 .one(content.html.to_owned().as_bytes())
                 .document;
@@ -64,7 +65,7 @@ pub fn check_mention(document: impl AsRef<str> + std::fmt::Debug, base_url: &url
             // iteration of the loop.
             //
             // Empty list means all nodes were processed.
-            let mut unprocessed_nodes: Vec<Rc<html5ever::rcdom::Node>> = root.children.borrow().iter().cloned().collect();
+            let mut unprocessed_nodes: Vec<Rc<rcdom::Node>> = root.children.borrow().iter().cloned().collect();
             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);
@@ -73,7 +74,7 @@ pub fn check_mention(document: impl AsRef<str> + std::fmt::Debug, base_url: &url
                     // Add children nodes to the list for the next iteration
                     unprocessed_nodes.extend(node.children.borrow().iter().cloned());
 
-                    if let html5ever::rcdom::NodeData::Element { ref name, ref attrs, .. } = node.data {
+                    if let rcdom::NodeData::Element { ref name, ref attrs, .. } = node.data {
                         // If it's not `<a>`, skip it
                         if name.local != *"a" { continue; }
                         let mut is_mention: bool = false;