]> Untitled Git - lemmy.git/blobdiff - crates/routes/src/feeds.rs
Make functions work with both connection and pool (#3420)
[lemmy.git] / crates / routes / src / feeds.rs
index 3b4c2cd77bbcf9879d5d5caa6d0134a2b0607be7..8429f86061d32d75d59f6facfaa5b0579ad962e2 100644 (file)
@@ -122,10 +122,10 @@ async fn get_feed_data(
   limit: i64,
   page: i64,
 ) -> Result<HttpResponse, LemmyError> {
-  let site_view = SiteView::read_local(context.pool()).await?;
+  let site_view = SiteView::read_local(&mut context.pool()).await?;
 
   let posts = PostQuery::builder()
-    .pool(context.pool())
+    .pool(&mut context.pool())
     .listing_type(Some(listing_type))
     .sort(Some(sort_type))
     .limit(Some(limit))
@@ -178,7 +178,7 @@ async fn get_feed(
   let builder = match request_type {
     RequestType::User => {
       get_feed_user(
-        context.pool(),
+        &mut context.pool(),
         &info.sort_type()?,
         &info.get_limit(),
         &info.get_page(),
@@ -189,7 +189,7 @@ async fn get_feed(
     }
     RequestType::Community => {
       get_feed_community(
-        context.pool(),
+        &mut context.pool(),
         &info.sort_type()?,
         &info.get_limit(),
         &info.get_page(),
@@ -200,7 +200,7 @@ async fn get_feed(
     }
     RequestType::Front => {
       get_feed_front(
-        context.pool(),
+        &mut context.pool(),
         &jwt_secret,
         &info.sort_type()?,
         &info.get_limit(),
@@ -211,7 +211,13 @@ async fn get_feed(
       .await
     }
     RequestType::Inbox => {
-      get_feed_inbox(context.pool(), &jwt_secret, &param, &protocol_and_hostname).await
+      get_feed_inbox(
+        &mut context.pool(),
+        &jwt_secret,
+        &param,
+        &protocol_and_hostname,
+      )
+      .await
     }
   }
   .map_err(ErrorBadRequest)?;
@@ -227,7 +233,7 @@ async fn get_feed(
 
 #[tracing::instrument(skip_all)]
 async fn get_feed_user(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   sort_type: &SortType,
   limit: &i64,
   page: &i64,
@@ -262,7 +268,7 @@ async fn get_feed_user(
 
 #[tracing::instrument(skip_all)]
 async fn get_feed_community(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   sort_type: &SortType,
   limit: &i64,
   page: &i64,
@@ -300,7 +306,7 @@ async fn get_feed_community(
 
 #[tracing::instrument(skip_all)]
 async fn get_feed_front(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   jwt_secret: &str,
   sort_type: &SortType,
   limit: &i64,
@@ -341,7 +347,7 @@ async fn get_feed_front(
 
 #[tracing::instrument(skip_all)]
 async fn get_feed_inbox(
-  pool: &DbPool,
+  pool: &mut DbPool<'_>,
   jwt_secret: &str,
   jwt: &str,
   protocol_and_hostname: &str,
@@ -475,7 +481,6 @@ fn create_post_items(
     i.pub_date(dt.to_rfc2822());
 
     let post_url = format!("{}/post/{}", protocol_and_hostname, p.post.id);
-    i.link(post_url.clone());
     i.comments(post_url.clone());
     let guid = GuidBuilder::default()
       .permalink(true)
@@ -499,6 +504,9 @@ fn create_post_items(
     if let Some(url) = p.post.url {
       let link_html = format!("<br><a href=\"{url}\">{url}</a>");
       description.push_str(&link_html);
+      i.link(url.to_string());
+    } else {
+      i.link(post_url.clone());
     }
 
     if let Some(body) = p.post.body {