1 use crate::structs::{LocalUserView, PostView};
4 dsl::{now, IntervalDsl},
12 NullableExpressionMethods,
13 PgTextExpressionMethods,
16 use diesel_async::RunQueryDsl;
17 use lemmy_db_schema::{
18 aggregates::structs::PostAggregates,
19 newtypes::{CommunityId, LocalUserId, PersonId, PostId},
28 person_post_aggregates,
36 community::{Community, CommunityFollower, CommunityPersonBan},
38 person_block::PersonBlock,
39 post::{Post, PostRead, PostSaved},
42 utils::{fuzzy_search, get_conn, limit_and_offset, DbPool},
48 type PostViewTuple = (
52 Option<CommunityPersonBan>,
54 Option<CommunityFollower>,
62 sql_function!(fn coalesce(x: sql_types::Nullable<sql_types::BigInt>, y: sql_types::BigInt) -> sql_types::BigInt);
66 pool: &mut DbPool<'_>,
68 my_person_id: Option<PersonId>,
69 is_mod_or_admin: Option<bool>,
70 ) -> Result<Self, Error> {
71 let conn = &mut get_conn(pool).await?;
73 // The left join below will return None in this case
74 let person_id_join = my_person_id.unwrap_or(PersonId(-1));
75 let mut query = post_aggregates::table
76 .filter(post_aggregates::post_id.eq(post_id))
77 .inner_join(person::table)
78 .inner_join(community::table)
80 community_person_ban::table.on(
81 post_aggregates::community_id
82 .eq(community_person_ban::community_id)
83 .and(community_person_ban::person_id.eq(post_aggregates::creator_id)),
86 .inner_join(post::table)
88 community_follower::table.on(
89 post_aggregates::community_id
90 .eq(community_follower::community_id)
91 .and(community_follower::person_id.eq(person_id_join)),
96 post_aggregates::post_id
97 .eq(post_saved::post_id)
98 .and(post_saved::person_id.eq(person_id_join)),
103 post_aggregates::post_id
104 .eq(post_read::post_id)
105 .and(post_read::person_id.eq(person_id_join)),
109 person_block::table.on(
110 post_aggregates::creator_id
111 .eq(person_block::target_id)
112 .and(person_block::person_id.eq(person_id_join)),
117 post_aggregates::post_id
118 .eq(post_like::post_id)
119 .and(post_like::person_id.eq(person_id_join)),
123 person_post_aggregates::table.on(
124 post_aggregates::post_id
125 .eq(person_post_aggregates::post_id)
126 .and(person_post_aggregates::person_id.eq(person_id_join)),
132 community::all_columns,
133 community_person_ban::all_columns.nullable(),
134 post_aggregates::all_columns,
135 community_follower::all_columns.nullable(),
136 post_saved::all_columns.nullable(),
137 post_read::all_columns.nullable(),
138 person_block::all_columns.nullable(),
139 post_like::score.nullable(),
141 post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
142 post_aggregates::comments,
147 // Hide deleted and removed for non-admins or mods
148 if !is_mod_or_admin.unwrap_or(false) {
150 .filter(community::removed.eq(false))
151 .filter(post::removed.eq(false))
152 // users can see their own deleted posts
156 .or(post::creator_id.eq(person_id_join)),
161 .or(post::creator_id.eq(person_id_join)),
169 creator_banned_from_community,
177 ) = query.first::<PostViewTuple>(conn).await?;
179 // If a person is given, then my_vote, if None, should be 0, not null
180 // Necessary to differentiate between other person's votes
181 let my_vote = if my_person_id.is_some() && post_like.is_none() {
191 creator_banned_from_community: creator_banned_from_community.is_some(),
193 subscribed: CommunityFollower::to_subscribed_type(&follower),
194 saved: saved.is_some(),
195 read: read.is_some(),
196 creator_blocked: creator_blocked.is_some(),
204 pub struct PostQuery<'a> {
205 pub listing_type: Option<ListingType>,
206 pub sort: Option<SortType>,
207 pub creator_id: Option<PersonId>,
208 pub community_id: Option<CommunityId>,
209 pub local_user: Option<&'a LocalUserView>,
210 pub search_term: Option<String>,
211 pub url_search: Option<String>,
212 pub saved_only: Option<bool>,
213 pub is_profile_view: Option<bool>,
214 pub page: Option<i64>,
215 pub limit: Option<i64>,
218 impl<'a> PostQuery<'a> {
219 pub async fn list(self, pool: &mut DbPool<'_>) -> Result<Vec<PostView>, Error> {
220 let conn = &mut get_conn(pool).await?;
222 // The left join below will return None in this case
223 let person_id_join = self.local_user.map(|l| l.person.id).unwrap_or(PersonId(-1));
224 let local_user_id_join = self
226 .map(|l| l.local_user.id)
227 .unwrap_or(LocalUserId(-1));
229 let mut query = post_aggregates::table
230 .inner_join(person::table)
231 .inner_join(post::table)
232 .inner_join(community::table)
234 community_person_ban::table.on(
235 post_aggregates::community_id
236 .eq(community_person_ban::community_id)
237 .and(community_person_ban::person_id.eq(post_aggregates::creator_id)),
241 community_follower::table.on(
242 post_aggregates::community_id
243 .eq(community_follower::community_id)
244 .and(community_follower::person_id.eq(person_id_join)),
248 post_saved::table.on(
249 post_aggregates::post_id
250 .eq(post_saved::post_id)
251 .and(post_saved::person_id.eq(person_id_join)),
256 post_aggregates::post_id
257 .eq(post_read::post_id)
258 .and(post_read::person_id.eq(person_id_join)),
262 person_block::table.on(
263 post_aggregates::creator_id
264 .eq(person_block::target_id)
265 .and(person_block::person_id.eq(person_id_join)),
269 community_block::table.on(
270 post_aggregates::community_id
271 .eq(community_block::community_id)
272 .and(community_block::person_id.eq(person_id_join)),
277 post_aggregates::post_id
278 .eq(post_like::post_id)
279 .and(post_like::person_id.eq(person_id_join)),
283 person_post_aggregates::table.on(
284 post_aggregates::post_id
285 .eq(person_post_aggregates::post_id)
286 .and(person_post_aggregates::person_id.eq(person_id_join)),
290 local_user_language::table.on(
292 .eq(local_user_language::language_id)
293 .and(local_user_language::local_user_id.eq(local_user_id_join)),
299 community::all_columns,
300 community_person_ban::all_columns.nullable(),
301 post_aggregates::all_columns,
302 community_follower::all_columns.nullable(),
303 post_saved::all_columns.nullable(),
304 post_read::all_columns.nullable(),
305 person_block::all_columns.nullable(),
306 post_like::score.nullable(),
308 post_aggregates::comments.nullable() - person_post_aggregates::read_comments.nullable(),
309 post_aggregates::comments,
314 let is_profile_view = self.is_profile_view.unwrap_or(false);
315 let is_creator = self.creator_id == self.local_user.map(|l| l.person.id);
316 // only show deleted posts to creator
319 .filter(community::deleted.eq(false))
320 .filter(post::deleted.eq(false));
323 let is_admin = self.local_user.map(|l| l.person.admin).unwrap_or(false);
324 // only show removed posts to admin when viewing user profile
325 if !(is_profile_view && is_admin) {
327 .filter(community::removed.eq(false))
328 .filter(post::removed.eq(false));
331 if self.community_id.is_none() {
332 query = query.then_order_by(post_aggregates::featured_local.desc());
333 } else if let Some(community_id) = self.community_id {
335 .filter(post_aggregates::community_id.eq(community_id))
336 .then_order_by(post_aggregates::featured_community.desc());
339 if let Some(creator_id) = self.creator_id {
340 query = query.filter(post_aggregates::creator_id.eq(creator_id));
343 if let Some(listing_type) = self.listing_type {
345 ListingType::Subscribed => {
346 query = query.filter(community_follower::person_id.is_not_null())
348 ListingType::Local => {
349 query = query.filter(community::local.eq(true)).filter(
352 .or(community_follower::person_id.eq(person_id_join)),
355 ListingType::All => {
356 query = query.filter(
359 .or(community_follower::person_id.eq(person_id_join)),
365 if let Some(url_search) = self.url_search {
366 query = query.filter(post::url.eq(url_search));
369 if let Some(search_term) = self.search_term {
370 let searcher = fuzzy_search(&search_term);
371 query = query.filter(
373 .ilike(searcher.clone())
374 .or(post::body.ilike(searcher)),
380 .map(|l| l.local_user.show_nsfw)
384 .filter(post::nsfw.eq(false))
385 .filter(community::nsfw.eq(false));
390 .map(|l| l.local_user.show_bot_accounts)
393 query = query.filter(person::bot_account.eq(false));
396 if self.saved_only.unwrap_or(false) {
397 query = query.filter(post_saved::post_id.is_not_null());
399 // Only hide the read posts, if the saved_only is false. Otherwise ppl with the hide_read
400 // setting wont be able to see saved posts.
403 .map(|l| l.local_user.show_read_posts)
406 query = query.filter(post_read::post_id.is_null());
409 if self.local_user.is_some() {
410 // Filter out the rows with missing languages
411 query = query.filter(local_user_language::language_id.is_not_null());
413 // Don't show blocked communities or persons
414 query = query.filter(community_block::person_id.is_null());
415 query = query.filter(person_block::person_id.is_null());
418 query = match self.sort.unwrap_or(SortType::Hot) {
419 SortType::Active => query
420 .then_order_by(post_aggregates::hot_rank_active.desc())
421 .then_order_by(post_aggregates::published.desc()),
422 SortType::Hot => query
423 .then_order_by(post_aggregates::hot_rank.desc())
424 .then_order_by(post_aggregates::published.desc()),
425 SortType::New => query.then_order_by(post_aggregates::published.desc()),
426 SortType::Old => query.then_order_by(post_aggregates::published.asc()),
427 SortType::NewComments => query.then_order_by(post_aggregates::newest_comment_time.desc()),
428 SortType::MostComments => query
429 .then_order_by(post_aggregates::comments.desc())
430 .then_order_by(post_aggregates::published.desc()),
431 SortType::TopAll => query
432 .then_order_by(post_aggregates::score.desc())
433 .then_order_by(post_aggregates::published.desc()),
434 SortType::TopYear => query
435 .filter(post_aggregates::published.gt(now - 1.years()))
436 .then_order_by(post_aggregates::score.desc())
437 .then_order_by(post_aggregates::published.desc()),
438 SortType::TopMonth => query
439 .filter(post_aggregates::published.gt(now - 1.months()))
440 .then_order_by(post_aggregates::score.desc())
441 .then_order_by(post_aggregates::published.desc()),
442 SortType::TopWeek => query
443 .filter(post_aggregates::published.gt(now - 1.weeks()))
444 .then_order_by(post_aggregates::score.desc())
445 .then_order_by(post_aggregates::published.desc()),
446 SortType::TopDay => query
447 .filter(post_aggregates::published.gt(now - 1.days()))
448 .then_order_by(post_aggregates::score.desc())
449 .then_order_by(post_aggregates::published.desc()),
450 SortType::TopHour => query
451 .filter(post_aggregates::published.gt(now - 1.hours()))
452 .then_order_by(post_aggregates::score.desc())
453 .then_order_by(post_aggregates::published.desc()),
454 SortType::TopSixHour => query
455 .filter(post_aggregates::published.gt(now - 6.hours()))
456 .then_order_by(post_aggregates::score.desc())
457 .then_order_by(post_aggregates::published.desc()),
458 SortType::TopTwelveHour => query
459 .filter(post_aggregates::published.gt(now - 12.hours()))
460 .then_order_by(post_aggregates::score.desc())
461 .then_order_by(post_aggregates::published.desc()),
462 SortType::TopThreeMonths => query
463 .filter(post_aggregates::published.gt(now - 3.months()))
464 .then_order_by(post_aggregates::score.desc())
465 .then_order_by(post_aggregates::published.desc()),
466 SortType::TopSixMonths => query
467 .filter(post_aggregates::published.gt(now - 6.months()))
468 .then_order_by(post_aggregates::score.desc())
469 .then_order_by(post_aggregates::published.desc()),
470 SortType::TopNineMonths => query
471 .filter(post_aggregates::published.gt(now - 9.months()))
472 .then_order_by(post_aggregates::score.desc())
473 .then_order_by(post_aggregates::published.desc()),
476 let (limit, offset) = limit_and_offset(self.page, self.limit)?;
478 query = query.limit(limit).offset(offset);
480 debug!("Post View Query: {:?}", debug_query::<Pg, _>(&query));
482 let res = query.load::<PostViewTuple>(conn).await?;
484 Ok(res.into_iter().map(PostView::from_tuple).collect())
488 impl JoinView for PostView {
489 type JoinTuple = PostViewTuple;
490 fn from_tuple(a: Self::JoinTuple) -> Self {
495 creator_banned_from_community: a.3.is_some(),
497 subscribed: CommunityFollower::to_subscribed_type(&a.5),
498 saved: a.6.is_some(),
500 creator_blocked: a.8.is_some(),
502 unread_comments: a.10,
509 #![allow(clippy::unwrap_used)]
510 #![allow(clippy::indexing_slicing)]
513 post_view::{PostQuery, PostView},
514 structs::LocalUserView,
516 use lemmy_db_schema::{
517 aggregates::structs::PostAggregates,
518 impls::actor_language::UNDETERMINED_ID,
519 newtypes::LanguageId,
521 actor_language::LocalUserLanguage,
522 community::{Community, CommunityInsertForm},
523 community_block::{CommunityBlock, CommunityBlockForm},
526 local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
527 person::{Person, PersonInsertForm},
528 person_block::{PersonBlock, PersonBlockForm},
529 post::{Post, PostInsertForm, PostLike, PostLikeForm, PostUpdateForm},
531 traits::{Blockable, Crud, Likeable},
532 utils::{build_db_pool_for_tests, DbPool},
536 use serial_test::serial;
539 inserted_instance: Instance,
540 local_user_view: LocalUserView,
541 inserted_blocked_person: Person,
542 inserted_bot: Person,
543 inserted_community: Community,
547 async fn init_data(pool: &mut DbPool<'_>) -> Data {
548 let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
552 let person_name = "tegan".to_string();
554 let new_person = PersonInsertForm::builder()
555 .name(person_name.clone())
556 .public_key("pubkey".to_string())
557 .instance_id(inserted_instance.id)
560 let inserted_person = Person::create(pool, &new_person).await.unwrap();
562 let local_user_form = LocalUserInsertForm::builder()
563 .person_id(inserted_person.id)
564 .password_encrypted(String::new())
566 let inserted_local_user = LocalUser::create(pool, &local_user_form).await.unwrap();
568 let new_bot = PersonInsertForm::builder()
569 .name("mybot".to_string())
570 .bot_account(Some(true))
571 .public_key("pubkey".to_string())
572 .instance_id(inserted_instance.id)
575 let inserted_bot = Person::create(pool, &new_bot).await.unwrap();
577 let new_community = CommunityInsertForm::builder()
578 .name("test_community_3".to_string())
579 .title("nada".to_owned())
580 .public_key("pubkey".to_string())
581 .instance_id(inserted_instance.id)
584 let inserted_community = Community::create(pool, &new_community).await.unwrap();
586 // Test a person block, make sure the post query doesn't include their post
587 let blocked_person = PersonInsertForm::builder()
589 .public_key("pubkey".to_string())
590 .instance_id(inserted_instance.id)
593 let inserted_blocked_person = Person::create(pool, &blocked_person).await.unwrap();
595 let post_from_blocked_person = PostInsertForm::builder()
596 .name("blocked_person_post".to_string())
597 .creator_id(inserted_blocked_person.id)
598 .community_id(inserted_community.id)
599 .language_id(Some(LanguageId(1)))
602 Post::create(pool, &post_from_blocked_person).await.unwrap();
605 let person_block = PersonBlockForm {
606 person_id: inserted_person.id,
607 target_id: inserted_blocked_person.id,
610 PersonBlock::block(pool, &person_block).await.unwrap();
613 let new_post = PostInsertForm::builder()
614 .name("test post 3".to_string())
615 .creator_id(inserted_person.id)
616 .community_id(inserted_community.id)
617 .language_id(Some(LanguageId(47)))
620 let inserted_post = Post::create(pool, &new_post).await.unwrap();
622 let new_bot_post = PostInsertForm::builder()
623 .name("test bot post".to_string())
624 .creator_id(inserted_bot.id)
625 .community_id(inserted_community.id)
628 let _inserted_bot_post = Post::create(pool, &new_bot_post).await.unwrap();
629 let local_user_view = LocalUserView {
630 local_user: inserted_local_user,
631 person: inserted_person,
632 counts: Default::default(),
638 inserted_blocked_person,
647 async fn post_listing_with_person() {
648 let pool = &build_db_pool_for_tests().await;
649 let pool = &mut pool.into();
650 let mut data = init_data(pool).await;
652 let local_user_form = LocalUserUpdateForm::builder()
653 .show_bot_accounts(Some(false))
655 let inserted_local_user =
656 LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form)
659 data.local_user_view.local_user = inserted_local_user;
661 let read_post_listing = PostQuery {
662 sort: (Some(SortType::New)),
663 community_id: (Some(data.inserted_community.id)),
664 local_user: (Some(&data.local_user_view)),
671 let post_listing_single_with_person = PostView::read(
673 data.inserted_post.id,
674 Some(data.local_user_view.person.id),
680 let mut expected_post_listing_with_user = expected_post_view(&data, pool).await;
682 // Should be only one person, IE the bot post, and blocked should be missing
683 assert_eq!(1, read_post_listing.len());
685 assert_eq!(expected_post_listing_with_user, read_post_listing[0]);
686 expected_post_listing_with_user.my_vote = Some(0);
688 expected_post_listing_with_user,
689 post_listing_single_with_person
692 let local_user_form = LocalUserUpdateForm::builder()
693 .show_bot_accounts(Some(true))
695 let inserted_local_user =
696 LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form)
699 data.local_user_view.local_user = inserted_local_user;
701 let post_listings_with_bots = PostQuery {
702 sort: (Some(SortType::New)),
703 community_id: (Some(data.inserted_community.id)),
704 local_user: (Some(&data.local_user_view)),
710 // should include bot post which has "undetermined" language
711 assert_eq!(2, post_listings_with_bots.len());
713 cleanup(data, pool).await;
718 async fn post_listing_no_person() {
719 let pool = &build_db_pool_for_tests().await;
720 let pool = &mut pool.into();
721 let data = init_data(pool).await;
723 let read_post_listing_multiple_no_person = PostQuery {
724 sort: (Some(SortType::New)),
725 community_id: (Some(data.inserted_community.id)),
732 let read_post_listing_single_no_person =
733 PostView::read(pool, data.inserted_post.id, None, None)
737 let expected_post_listing_no_person = expected_post_view(&data, pool).await;
739 // Should be 2 posts, with the bot post, and the blocked
740 assert_eq!(3, read_post_listing_multiple_no_person.len());
743 expected_post_listing_no_person,
744 read_post_listing_multiple_no_person[1]
747 expected_post_listing_no_person,
748 read_post_listing_single_no_person
751 cleanup(data, pool).await;
756 async fn post_listing_block_community() {
757 let pool = &build_db_pool_for_tests().await;
758 let pool = &mut pool.into();
759 let data = init_data(pool).await;
761 let community_block = CommunityBlockForm {
762 person_id: data.local_user_view.person.id,
763 community_id: data.inserted_community.id,
765 CommunityBlock::block(pool, &community_block).await.unwrap();
767 let read_post_listings_with_person_after_block = PostQuery {
768 sort: (Some(SortType::New)),
769 community_id: (Some(data.inserted_community.id)),
770 local_user: (Some(&data.local_user_view)),
776 // Should be 0 posts after the community block
777 assert_eq!(0, read_post_listings_with_person_after_block.len());
779 CommunityBlock::unblock(pool, &community_block)
782 cleanup(data, pool).await;
787 async fn post_listing_like() {
788 let pool = &build_db_pool_for_tests().await;
789 let pool = &mut pool.into();
790 let mut data = init_data(pool).await;
792 let post_like_form = PostLikeForm {
793 post_id: data.inserted_post.id,
794 person_id: data.local_user_view.person.id,
798 let inserted_post_like = PostLike::like(pool, &post_like_form).await.unwrap();
800 let expected_post_like = PostLike {
801 id: inserted_post_like.id,
802 post_id: data.inserted_post.id,
803 person_id: data.local_user_view.person.id,
804 published: inserted_post_like.published,
807 assert_eq!(expected_post_like, inserted_post_like);
809 let post_listing_single_with_person = PostView::read(
811 data.inserted_post.id,
812 Some(data.local_user_view.person.id),
818 let mut expected_post_with_upvote = expected_post_view(&data, pool).await;
819 expected_post_with_upvote.my_vote = Some(1);
820 expected_post_with_upvote.counts.score = 1;
821 expected_post_with_upvote.counts.upvotes = 1;
822 assert_eq!(expected_post_with_upvote, post_listing_single_with_person);
824 let local_user_form = LocalUserUpdateForm::builder()
825 .show_bot_accounts(Some(false))
827 let inserted_local_user =
828 LocalUser::update(pool, data.local_user_view.local_user.id, &local_user_form)
831 data.local_user_view.local_user = inserted_local_user;
833 let read_post_listing = PostQuery {
834 sort: (Some(SortType::New)),
835 community_id: (Some(data.inserted_community.id)),
836 local_user: (Some(&data.local_user_view)),
842 assert_eq!(1, read_post_listing.len());
844 assert_eq!(expected_post_with_upvote, read_post_listing[0]);
847 PostLike::remove(pool, data.local_user_view.person.id, data.inserted_post.id)
850 assert_eq!(1, like_removed);
851 cleanup(data, pool).await;
856 async fn post_listing_person_language() {
857 let pool = &build_db_pool_for_tests().await;
858 let pool = &mut pool.into();
859 let data = init_data(pool).await;
861 let spanish_id = Language::read_id_from_code(pool, Some("es"))
865 let post_spanish = PostInsertForm::builder()
866 .name("asffgdsc".to_string())
867 .creator_id(data.local_user_view.person.id)
868 .community_id(data.inserted_community.id)
869 .language_id(Some(spanish_id))
872 Post::create(pool, &post_spanish).await.unwrap();
874 let post_listings_all = PostQuery {
875 sort: (Some(SortType::New)),
876 local_user: (Some(&data.local_user_view)),
883 // no language filters specified, all posts should be returned
884 assert_eq!(3, post_listings_all.len());
886 let french_id = Language::read_id_from_code(pool, Some("fr"))
890 LocalUserLanguage::update(pool, vec![french_id], data.local_user_view.local_user.id)
894 let post_listing_french = PostQuery {
895 sort: (Some(SortType::New)),
896 local_user: (Some(&data.local_user_view)),
903 // only one post in french and one undetermined should be returned
904 assert_eq!(2, post_listing_french.len());
905 assert!(post_listing_french
907 .any(|p| p.post.language_id == french_id));
909 LocalUserLanguage::update(
911 vec![french_id, UNDETERMINED_ID],
912 data.local_user_view.local_user.id,
916 let post_listings_french_und = PostQuery {
917 sort: (Some(SortType::New)),
918 local_user: (Some(&data.local_user_view)),
925 // french post and undetermined language post should be returned
926 assert_eq!(2, post_listings_french_und.len());
929 post_listings_french_und[0].post.language_id
931 assert_eq!(french_id, post_listings_french_und[1].post.language_id);
933 cleanup(data, pool).await;
938 async fn post_listings_removed() {
939 let pool = &build_db_pool_for_tests().await;
940 let pool = &mut pool.into();
941 let mut data = init_data(pool).await;
946 data.inserted_post.id,
947 &PostUpdateForm::builder().removed(Some(true)).build(),
952 // Make sure you don't see the removed post in the results
953 let post_listings_no_admin = PostQuery {
954 sort: Some(SortType::New),
955 local_user: Some(&data.local_user_view),
961 assert_eq!(1, post_listings_no_admin.len());
963 // Removed post is shown to admins on profile page
964 data.local_user_view.person.admin = true;
965 let post_listings_is_admin = PostQuery {
966 sort: Some(SortType::New),
967 local_user: Some(&data.local_user_view),
968 is_profile_view: Some(true),
974 assert_eq!(2, post_listings_is_admin.len());
976 cleanup(data, pool).await;
981 async fn post_listings_deleted() {
982 let pool = &build_db_pool_for_tests().await;
983 let pool = &mut pool.into();
984 let data = init_data(pool).await;
989 data.inserted_post.id,
990 &PostUpdateForm::builder().deleted(Some(true)).build(),
995 // Make sure you don't see the deleted post in the results
996 let post_listings_no_creator = PostQuery {
997 sort: Some(SortType::New),
1003 let not_contains_deleted = post_listings_no_creator
1006 .all(|p| p != data.inserted_post.id);
1007 assert!(not_contains_deleted);
1009 // Deleted post is shown to creator
1010 let post_listings_is_creator = PostQuery {
1011 sort: Some(SortType::New),
1012 local_user: Some(&data.local_user_view),
1013 ..Default::default()
1018 let contains_deleted = post_listings_is_creator
1021 .any(|p| p == data.inserted_post.id);
1022 assert!(contains_deleted);
1024 cleanup(data, pool).await;
1027 async fn cleanup(data: Data, pool: &mut DbPool<'_>) {
1028 let num_deleted = Post::delete(pool, data.inserted_post.id).await.unwrap();
1029 Community::delete(pool, data.inserted_community.id)
1032 Person::delete(pool, data.local_user_view.person.id)
1035 Person::delete(pool, data.inserted_bot.id).await.unwrap();
1036 Person::delete(pool, data.inserted_blocked_person.id)
1039 Instance::delete(pool, data.inserted_instance.id)
1042 assert_eq!(1, num_deleted);
1045 async fn expected_post_view(data: &Data, pool: &mut DbPool<'_>) -> PostView {
1046 let (inserted_person, inserted_community, inserted_post) = (
1047 &data.local_user_view.person,
1048 &data.inserted_community,
1049 &data.inserted_post,
1051 let agg = PostAggregates::read(pool, inserted_post.id).await.unwrap();
1055 id: inserted_post.id,
1056 name: inserted_post.name.clone(),
1057 creator_id: inserted_person.id,
1060 published: inserted_post.published,
1062 community_id: inserted_community.id,
1068 embed_description: None,
1069 embed_video_url: None,
1070 thumbnail_url: None,
1071 ap_id: inserted_post.ap_id.clone(),
1073 language_id: LanguageId(47),
1074 featured_community: false,
1075 featured_local: false,
1080 id: inserted_person.id,
1081 name: inserted_person.name.clone(),
1083 published: inserted_person.published,
1085 actor_id: inserted_person.actor_id.clone(),
1094 inbox_url: inserted_person.inbox_url.clone(),
1095 shared_inbox_url: None,
1096 matrix_user_id: None,
1098 instance_id: data.inserted_instance.id,
1099 private_key: inserted_person.private_key.clone(),
1100 public_key: inserted_person.public_key.clone(),
1101 last_refreshed_at: inserted_person.last_refreshed_at,
1103 creator_banned_from_community: false,
1104 community: Community {
1105 id: inserted_community.id,
1106 name: inserted_community.name.clone(),
1111 actor_id: inserted_community.actor_id.clone(),
1113 title: "nada".to_owned(),
1118 posting_restricted_to_mods: false,
1119 published: inserted_community.published,
1120 instance_id: data.inserted_instance.id,
1121 private_key: inserted_community.private_key.clone(),
1122 public_key: inserted_community.public_key.clone(),
1123 last_refreshed_at: inserted_community.last_refreshed_at,
1124 followers_url: inserted_community.followers_url.clone(),
1125 inbox_url: inserted_community.inbox_url.clone(),
1126 shared_inbox_url: inserted_community.shared_inbox_url.clone(),
1127 moderators_url: inserted_community.moderators_url.clone(),
1128 featured_url: inserted_community.featured_url.clone(),
1130 counts: PostAggregates {
1132 post_id: inserted_post.id,
1137 published: agg.published,
1138 newest_comment_time_necro: inserted_post.published,
1139 newest_comment_time: inserted_post.published,
1140 featured_community: false,
1141 featured_local: false,
1143 hot_rank_active: 1728,
1144 community_id: inserted_post.community_id,
1145 creator_id: inserted_post.creator_id,
1147 subscribed: SubscribedType::NotSubscribed,
1150 creator_blocked: false,