mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Compare commits
9 Commits
3d072655a1
...
4fd0803cc0
Author | SHA1 | Date | |
---|---|---|---|
|
4fd0803cc0 | ||
|
f7d881ac78 | ||
|
e82f72d3c8 | ||
|
50ce7961d1 | ||
|
58cd9b5fc3 | ||
|
b363cf6ae9 | ||
|
66c4fed3d6 | ||
|
682604f849 | ||
|
4b7fb0de36 |
@ -76,5 +76,7 @@ pub async fn leave_admin(
|
||||
admin_oauth_providers: None,
|
||||
blocked_urls,
|
||||
tagline,
|
||||
taglines: vec![],
|
||||
custom_emojis: vec![],
|
||||
}))
|
||||
}
|
||||
|
@ -3,9 +3,13 @@ use lemmy_db_schema::{
|
||||
source::site::Site,
|
||||
CommunityVisibility,
|
||||
ListingType,
|
||||
PostSortType,
|
||||
};
|
||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonView};
|
||||
use lemmy_db_views_actor::structs::{
|
||||
CommunityModeratorView,
|
||||
CommunitySortType,
|
||||
CommunityView,
|
||||
PersonView,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
#[cfg(feature = "full")]
|
||||
@ -74,7 +78,7 @@ pub struct CommunityResponse {
|
||||
/// Fetches a list of communities.
|
||||
pub struct ListCommunities {
|
||||
pub type_: Option<ListingType>,
|
||||
pub sort: Option<PostSortType>,
|
||||
pub sort: Option<CommunitySortType>,
|
||||
pub show_nsfw: Option<bool>,
|
||||
pub page: Option<i64>,
|
||||
pub limit: Option<i64>,
|
||||
|
@ -5,6 +5,7 @@ use serde_with::skip_serializing_none;
|
||||
use ts_rs::TS;
|
||||
use url::Url;
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
|
@ -306,6 +306,8 @@ pub struct EditSite {
|
||||
/// The response for a site.
|
||||
pub struct SiteResponse {
|
||||
pub site_view: SiteView,
|
||||
/// deprecated, use field `tagline` or /api/v3/tagline/list
|
||||
pub taglines: Vec<()>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
@ -320,6 +322,10 @@ pub struct GetSiteResponse {
|
||||
pub my_user: Option<MyUserInfo>,
|
||||
pub all_languages: Vec<Language>,
|
||||
pub discussion_languages: Vec<LanguageId>,
|
||||
/// deprecated, use field `tagline` or /api/v3/tagline/list
|
||||
pub taglines: Vec<()>,
|
||||
/// deprecated, use /api/v3/custom_emoji/list
|
||||
pub custom_emojis: Vec<()>,
|
||||
/// If the site has any taglines, a random one is included here for displaying
|
||||
pub tagline: Option<Tagline>,
|
||||
/// A list of external auth methods your site supports.
|
||||
|
@ -139,7 +139,10 @@ pub async fn create_site(
|
||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
||||
context.rate_limit_cell().set_config(rate_limit_config);
|
||||
|
||||
Ok(Json(SiteResponse { site_view }))
|
||||
Ok(Json(SiteResponse {
|
||||
site_view,
|
||||
taglines: vec![],
|
||||
}))
|
||||
}
|
||||
|
||||
fn validate_create_payload(local_site: &LocalSite, create_site: &CreateSite) -> LemmyResult<()> {
|
||||
|
@ -59,6 +59,8 @@ pub async fn get_site(
|
||||
tagline,
|
||||
oauth_providers: Some(oauth_providers),
|
||||
admin_oauth_providers: Some(admin_oauth_providers),
|
||||
taglines: vec![],
|
||||
custom_emojis: vec![],
|
||||
})
|
||||
})
|
||||
.await
|
||||
|
@ -193,7 +193,10 @@ pub async fn update_site(
|
||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
||||
context.rate_limit_cell().set_config(rate_limit_config);
|
||||
|
||||
Ok(Json(SiteResponse { site_view }))
|
||||
Ok(Json(SiteResponse {
|
||||
site_view,
|
||||
taglines: vec![],
|
||||
}))
|
||||
}
|
||||
|
||||
fn validate_update_payload(local_site: &LocalSite, edit_site: &EditSite) -> LemmyResult<()> {
|
||||
|
@ -12,7 +12,11 @@ use lemmy_db_views::{
|
||||
post_view::PostQuery,
|
||||
structs::{LocalUserView, SiteView},
|
||||
};
|
||||
use lemmy_db_views_actor::{community_view::CommunityQuery, person_view::PersonQuery};
|
||||
use lemmy_db_views_actor::{
|
||||
community_view::CommunityQuery,
|
||||
person_view::PersonQuery,
|
||||
structs::CommunitySortType,
|
||||
};
|
||||
use lemmy_utils::error::LemmyResult;
|
||||
|
||||
#[tracing::instrument(skip(context))]
|
||||
@ -102,7 +106,7 @@ pub async fn search(
|
||||
};
|
||||
|
||||
let community_query = CommunityQuery {
|
||||
sort,
|
||||
sort: sort.map(CommunitySortType::from),
|
||||
listing_type,
|
||||
search_term: Some(q.clone()),
|
||||
title_only,
|
||||
|
@ -258,9 +258,9 @@ impl Post {
|
||||
post::table
|
||||
.inner_join(person::table)
|
||||
.inner_join(community::table)
|
||||
// find all posts which have scheduled_publish_time that is in the past
|
||||
// find all posts which have scheduled_publish_time that is in the future
|
||||
.filter(post::scheduled_publish_time.is_not_null())
|
||||
.filter(coalesce(post::scheduled_publish_time, now()).lt(now()))
|
||||
.filter(coalesce(post::scheduled_publish_time, now()).gt(now()))
|
||||
// make sure the post and community are still around
|
||||
.filter(not(post::deleted.or(post::removed)))
|
||||
.filter(not(community::removed.or(community::deleted)))
|
||||
@ -414,6 +414,7 @@ mod tests {
|
||||
traits::{Crud, Likeable, Saveable},
|
||||
utils::build_db_pool_for_tests,
|
||||
};
|
||||
use chrono::DateTime;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serial_test::serial;
|
||||
use std::collections::HashSet;
|
||||
@ -456,6 +457,12 @@ mod tests {
|
||||
);
|
||||
let inserted_post2 = Post::create(pool, &new_post2).await.unwrap();
|
||||
|
||||
let new_scheduled_post = PostInsertForm {
|
||||
scheduled_publish_time: Some(DateTime::from_timestamp_nanos(i64::MAX)),
|
||||
..PostInsertForm::new("beans".into(), inserted_person.id, inserted_community.id)
|
||||
};
|
||||
let inserted_scheduled_post = Post::create(pool, &new_scheduled_post).await.unwrap();
|
||||
|
||||
let expected_post = Post {
|
||||
id: inserted_post.id,
|
||||
name: "A test post".into(),
|
||||
@ -535,6 +542,12 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
// Scheduled post count
|
||||
let scheduled_post_count = Post::user_scheduled_post_count(inserted_person.id, pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(1, scheduled_post_count);
|
||||
|
||||
let like_removed = PostLike::remove(pool, inserted_person.id, inserted_post.id)
|
||||
.await
|
||||
.unwrap();
|
||||
@ -551,8 +564,11 @@ mod tests {
|
||||
assert_eq!(2, read_removed);
|
||||
|
||||
let num_deleted = Post::delete(pool, inserted_post.id).await.unwrap()
|
||||
+ Post::delete(pool, inserted_post2.id).await.unwrap();
|
||||
assert_eq!(2, num_deleted);
|
||||
+ Post::delete(pool, inserted_post2.id).await.unwrap()
|
||||
+ Post::delete(pool, inserted_scheduled_post.id)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(3, num_deleted);
|
||||
Community::delete(pool, inserted_community.id)
|
||||
.await
|
||||
.unwrap();
|
||||
|
@ -769,7 +769,7 @@ diesel::table! {
|
||||
featured_local -> Bool,
|
||||
url_content_type -> Nullable<Text>,
|
||||
alt_text -> Nullable<Text>,
|
||||
scheduled_publish_time -> Nullable<Timestamptz>
|
||||
scheduled_publish_time -> Nullable<Timestamptz>,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::structs::{CommunityModeratorView, CommunityView, PersonView};
|
||||
use crate::structs::{CommunityModeratorView, CommunitySortType, CommunityView, PersonView};
|
||||
use diesel::{
|
||||
pg::Pg,
|
||||
result::Error,
|
||||
@ -103,7 +103,7 @@ fn queries<'a>() -> Queries<
|
||||
};
|
||||
|
||||
let list = move |mut conn: DbConn<'a>, (options, site): (CommunityQuery<'a>, &'a Site)| async move {
|
||||
use PostSortType::*;
|
||||
use CommunitySortType::*;
|
||||
|
||||
// The left join below will return None in this case
|
||||
let person_id_join = options.local_user.person_id().unwrap_or(PersonId(-1));
|
||||
@ -148,6 +148,8 @@ fn queries<'a>() -> Queries<
|
||||
}
|
||||
TopMonth => query = query.order_by(community_aggregates::users_active_month.desc()),
|
||||
TopWeek => query = query.order_by(community_aggregates::users_active_week.desc()),
|
||||
NameAsc => query = query.order_by(community::name.asc()),
|
||||
NameDesc => query = query.order_by(community::name.desc()),
|
||||
};
|
||||
|
||||
if let Some(listing_type) = options.listing_type {
|
||||
@ -228,10 +230,36 @@ impl CommunityView {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PostSortType> for CommunitySortType {
|
||||
fn from(value: PostSortType) -> Self {
|
||||
match value {
|
||||
PostSortType::Active => Self::Active,
|
||||
PostSortType::Hot => Self::Hot,
|
||||
PostSortType::New => Self::New,
|
||||
PostSortType::Old => Self::Old,
|
||||
PostSortType::TopDay => Self::TopDay,
|
||||
PostSortType::TopWeek => Self::TopWeek,
|
||||
PostSortType::TopMonth => Self::TopMonth,
|
||||
PostSortType::TopYear => Self::TopYear,
|
||||
PostSortType::TopAll => Self::TopAll,
|
||||
PostSortType::MostComments => Self::MostComments,
|
||||
PostSortType::NewComments => Self::NewComments,
|
||||
PostSortType::TopHour => Self::TopHour,
|
||||
PostSortType::TopSixHour => Self::TopSixHour,
|
||||
PostSortType::TopTwelveHour => Self::TopTwelveHour,
|
||||
PostSortType::TopThreeMonths => Self::TopThreeMonths,
|
||||
PostSortType::TopSixMonths => Self::TopSixMonths,
|
||||
PostSortType::TopNineMonths => Self::TopNineMonths,
|
||||
PostSortType::Controversial => Self::Controversial,
|
||||
PostSortType::Scaled => Self::Scaled,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CommunityQuery<'a> {
|
||||
pub listing_type: Option<ListingType>,
|
||||
pub sort: Option<PostSortType>,
|
||||
pub sort: Option<CommunitySortType>,
|
||||
pub local_user: Option<&'a LocalUser>,
|
||||
pub search_term: Option<String>,
|
||||
pub title_only: Option<bool>,
|
||||
|
@ -59,6 +59,35 @@ pub struct CommunityView {
|
||||
pub banned_from_community: bool,
|
||||
}
|
||||
|
||||
/// The community sort types. See here for descriptions: https://join-lemmy.org/docs/en/users/03-votes-and-ranking.html
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "full", derive(TS))]
|
||||
#[cfg_attr(feature = "full", ts(export))]
|
||||
pub enum CommunitySortType {
|
||||
#[default]
|
||||
Active,
|
||||
Hot,
|
||||
New,
|
||||
Old,
|
||||
TopDay,
|
||||
TopWeek,
|
||||
TopMonth,
|
||||
TopYear,
|
||||
TopAll,
|
||||
MostComments,
|
||||
NewComments,
|
||||
TopHour,
|
||||
TopSixHour,
|
||||
TopTwelveHour,
|
||||
TopThreeMonths,
|
||||
TopSixMonths,
|
||||
TopNineMonths,
|
||||
Controversial,
|
||||
Scaled,
|
||||
NameAsc,
|
||||
NameDesc,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||
#[cfg_attr(feature = "full", derive(TS, Queryable))]
|
||||
|
Loading…
Reference in New Issue
Block a user