X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fdb_schema%2Fsrc%2Futils.rs;h=93404da3ff23c2736ffa0a0d287f0cab6de380ec;hb=9c3efe32e7b2ef7978b7957eac10691beb551dde;hp=bd9435e3ef93df3fbe96821de64854f04cf6371d;hpb=becb8b4f66bdacca23b0b169e07d845afcb3d204;p=lemmy.git diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs index bd9435e3..93404da3 100644 --- a/crates/db_schema/src/utils.rs +++ b/crates/db_schema/src/utils.rs @@ -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 = Lazy::new(|| { Regex::new(r"^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$") .expect("compile email regex")