Fixing broken post_read logic. Fixes #4290 (#4297)

This commit is contained in:
Dessalines 2023-12-19 04:46:41 -05:00 committed by GitHub
parent 8583a85607
commit 2899ba0131
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -412,7 +412,8 @@ fn queries<'a>() -> Queries<
.unwrap_or(true) .unwrap_or(true)
{ {
// Do not hide read posts when it is a user profile view // Do not hide read posts when it is a user profile view
if let (Some(_creator_id), Some(person_id)) = (options.creator_id, my_person_id) { // Or, only hide read posts on non-profile views
if let (None, Some(person_id)) = (options.creator_id, my_person_id) {
query = query.filter(not(is_read(person_id))); query = query.filter(not(is_read(person_id)));
} }
} }
@ -741,7 +742,7 @@ mod tests {
local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm}, local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
person::{Person, PersonInsertForm}, person::{Person, PersonInsertForm},
person_block::{PersonBlock, PersonBlockForm}, person_block::{PersonBlock, PersonBlockForm},
post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm}, post::{Post, PostInsertForm, PostLike, PostLikeForm, PostRead, PostUpdateForm},
}, },
traits::{Blockable, Crud, Joinable, Likeable}, traits::{Blockable, Crud, Joinable, Likeable},
utils::{build_db_pool_for_tests, DbPool, RANK_DEFAULT}, utils::{build_db_pool_for_tests, DbPool, RANK_DEFAULT},
@ -749,7 +750,7 @@ mod tests {
SubscribedType, SubscribedType,
}; };
use serial_test::serial; use serial_test::serial;
use std::time::Duration; use std::{collections::HashSet, time::Duration};
struct Data { struct Data {
inserted_instance: Instance, inserted_instance: Instance,
@ -1497,6 +1498,47 @@ mod tests {
cleanup(data, pool).await; cleanup(data, pool).await;
} }
#[tokio::test]
#[serial]
async fn post_listings_hide_read() {
let pool = &build_db_pool_for_tests().await;
let pool = &mut pool.into();
let mut data = init_data(pool).await;
// Make sure local user hides read posts
let local_user_form = LocalUserUpdateForm {
show_read_posts: Some(false),
..Default::default()
};
let inserted_local_user =
LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form)
.await
.unwrap();
data.local_user_view.local_user = inserted_local_user;
// Mark a post as read
PostRead::mark_as_read(
pool,
HashSet::from([data.inserted_bot_post.id]),
data.local_user_view.person.id,
)
.await
.unwrap();
// Make sure you don't see the read post in the results
let post_listings_hide_read = PostQuery {
sort: Some(SortType::New),
local_user: Some(&data.local_user_view),
..Default::default()
}
.list(pool)
.await
.unwrap();
assert_eq!(1, post_listings_hide_read.len());
cleanup(data, pool).await;
}
async fn cleanup(data: Data, pool: &mut DbPool<'_>) { async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap(); let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
Community::delete(pool, data.inserted_community.id) Community::delete(pool, data.inserted_community.id)