-use diesel::{pg::Pg, result::Error, *};
-use lemmy_db_queries::{
+use diesel::{dsl::*, pg::Pg, result::Error, *};
+use lemmy_db_schema::{
aggregates::post_aggregates::PostAggregates,
functions::hot_rank,
fuzzy_search,
limit_and_offset,
- ListingType,
- MaybeOptional,
- SortType,
- ToSafe,
- ViewToVec,
-};
-use lemmy_db_schema::{
+ newtypes::{CommunityId, DbUrl, PersonId, PostId},
schema::{
community,
community_block,
person_block::PersonBlock,
post::{Post, PostRead, PostSaved},
},
- CommunityId,
- DbUrl,
- PersonId,
- PostId,
+ traits::{MaybeOptional, ToSafe, ViewToVec},
+ ListingType,
+ SortType,
};
-use log::debug;
-use serde::Serialize;
+use serde::{Deserialize, Serialize};
+use tracing::debug;
-#[derive(Debug, PartialEq, Serialize, Clone)]
+#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
pub struct PostView {
pub post: Post,
pub creator: PersonSafe,
community_person_ban::table.on(
post::community_id
.eq(community_person_ban::community_id)
- .and(community_person_ban::person_id.eq(post::creator_id)),
+ .and(community_person_ban::person_id.eq(post::creator_id))
+ .and(
+ community_person_ban::expires
+ .is_null()
+ .or(community_person_ban::expires.gt(now)),
+ ),
),
)
.inner_join(post_aggregates::table)
community_person_ban::table.on(
post::community_id
.eq(community_person_ban::community_id)
- .and(community_person_ban::person_id.eq(post::creator_id)),
+ .and(community_person_ban::person_id.eq(post::creator_id))
+ .and(
+ community_person_ban::expires
+ .is_null()
+ .or(community_person_ban::expires.gt(now)),
+ ),
),
)
.inner_join(post_aggregates::table)
query = query.filter(person::bot_account.eq(false));
};
- if !self.show_read_posts.unwrap_or(true) {
- query = query.filter(post_read::id.is_null());
- };
-
if self.saved_only.unwrap_or(false) {
query = query.filter(post_saved::id.is_not_null());
- };
+ }
+ // Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read
+ // setting wont be able to see saved posts.
+ else if !self.show_read_posts.unwrap_or(true) {
+ query = query.filter(post_read::id.is_null());
+ }
// Don't show blocked communities or persons
if self.my_person_id.is_some() {
#[cfg(test)]
mod tests {
use crate::post_view::{PostQueryBuilder, PostView};
- use lemmy_db_queries::{
+ use lemmy_db_schema::{
aggregates::post_aggregates::PostAggregates,
establish_unpooled_connection,
- Blockable,
- Crud,
- Likeable,
+ source::{
+ community::*,
+ community_block::{CommunityBlock, CommunityBlockForm},
+ person::*,
+ person_block::{PersonBlock, PersonBlockForm},
+ post::*,
+ },
+ traits::{Blockable, Crud, Likeable},
ListingType,
SortType,
};
- use lemmy_db_schema::source::{
- community::*,
- community_block::{CommunityBlock, CommunityBlockForm},
- person::*,
- person_block::{PersonBlock, PersonBlockForm},
- post::*,
- };
use serial_test::serial;
#[test]
inbox_url: inserted_person.inbox_url.to_owned(),
shared_inbox_url: None,
matrix_user_id: None,
+ ban_expires: None,
},
creator_banned_from_community: false,
community: CommunitySafe {