]> Untitled Git - lemmy.git/blobdiff - crates/db_schema/src/utils.rs
First pass at adding comment trees. (#2362)
[lemmy.git] / crates / db_schema / src / utils.rs
index bd9435e3ef93df3fbe96821de64854f04cf6371d..93404da3ff23c2736ffa0a0d287f0cab6de380ec 100644 (file)
@@ -1,4 +1,4 @@
-use crate::newtypes::DbUrl;
+use crate::{newtypes::DbUrl, CommentSortType, SortType};
 use activitypub_federation::{core::object_id::ObjectId, traits::ApubObject};
 use chrono::NaiveDateTime;
 use diesel::{
@@ -118,6 +118,19 @@ pub fn naive_now() -> NaiveDateTime {
   chrono::prelude::Utc::now().naive_utc()
 }
 
+pub fn post_to_comment_sort_type(sort: SortType) -> CommentSortType {
+  match sort {
+    SortType::Active | SortType::Hot => CommentSortType::Hot,
+    SortType::New | SortType::NewComments | SortType::MostComments => CommentSortType::New,
+    SortType::Old => CommentSortType::Old,
+    SortType::TopDay
+    | SortType::TopAll
+    | SortType::TopWeek
+    | SortType::TopYear
+    | SortType::TopMonth => CommentSortType::Top,
+  }
+}
+
 static EMAIL_REGEX: Lazy<Regex> = Lazy::new(|| {
   Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$")
     .expect("compile email regex")