From: Dessalines Date: Wed, 22 Jun 2022 12:05:41 +0000 (-0400) Subject: Expose pending 2 (#2282) X-Git-Url: http://these/git/readmes/README.ja.md?a=commitdiff_plain;h=92d17639cd860799dabe12b29a2aaa66193a3b7d;p=lemmy.git Expose pending 2 (#2282) * Exposing SubscribedType. Fixes #2281 * Fixing other subscribed fields. * Fix federation tests * Add comment about follower row. --- diff --git a/api_tests/package.json b/api_tests/package.json index 3aa57d49..571202bf 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -16,7 +16,7 @@ "eslint": "^7.30.0", "eslint-plugin-jane": "^9.0.3", "jest": "^27.0.6", - "lemmy-js-client": "0.16.0-rc.1", + "lemmy-js-client": "0.17.0-rc.11", "node-fetch": "^2.6.1", "prettier": "^2.3.2", "ts-jest": "^27.0.3", diff --git a/api_tests/src/follow.spec.ts b/api_tests/src/follow.spec.ts index 078c382c..0515aff4 100644 --- a/api_tests/src/follow.spec.ts +++ b/api_tests/src/follow.spec.ts @@ -1,4 +1,5 @@ jest.setTimeout(120000); +import {SubscribedType} from 'lemmy-js-client'; import { alpha, setupLogins, @@ -27,6 +28,7 @@ test('Follow federated community', async () => { // Make sure the follow response went through expect(follow.community_view.community.local).toBe(false); expect(follow.community_view.community.name).toBe('main'); + expect(follow.community_view.subscribed).toBe(SubscribedType.Pending); // Check it from local let site = await getSite(alpha); @@ -37,7 +39,7 @@ test('Follow federated community', async () => { // Test an unfollow let unfollow = await followCommunity(alpha, false, remoteCommunityId); - expect(unfollow.community_view.community.local).toBe(false); + expect(unfollow.community_view.subscribed).toBe(SubscribedType.NotSubscribed); // Make sure you are unsubbed locally let siteUnfollowCheck = await getSite(alpha); diff --git a/api_tests/src/shared.ts b/api_tests/src/shared.ts index d5be61ac..7080485e 100644 --- a/api_tests/src/shared.ts +++ b/api_tests/src/shared.ts @@ -298,7 +298,7 @@ export async function banPersonFromSite( api: API, person_id: number, ban: boolean, - remove_data: boolean, + remove_data: boolean ): Promise { // Make sure lemmy-beta/c/main is cached on lemmy_alpha let form: BanPerson = { @@ -558,7 +558,7 @@ export async function saveUserSettings( } export async function deleteUser( - api: API, + api: API ): Promise { let form: DeleteAccount = { auth: api.auth, @@ -613,7 +613,7 @@ export async function followBeta(api: API): Promise { export async function reportPost( api: API, post_id: number, - reason: string, + reason: string ): Promise { let form: CreatePostReport = { post_id, @@ -633,7 +633,7 @@ export async function listPostReports(api: API): Promise { let form: CreateCommentReport = { comment_id, diff --git a/api_tests/yarn.lock b/api_tests/yarn.lock index c60da9da..47a1a52b 100644 --- a/api_tests/yarn.lock +++ b/api_tests/yarn.lock @@ -3076,10 +3076,10 @@ language-tags@^1.0.5: dependencies: language-subtag-registry "~0.3.2" -lemmy-js-client@0.16.0-rc.1: - version "0.16.0-rc.1" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.16.0-rc.1.tgz#14c4a526abf4b171c8afe4efbe2a62dcaf6a6f17" - integrity sha512-0hR/gHHsokp46whIHGMBQO2zBKWM7bT6mwKNMZxPvyJo+YW9EbKTO5edjF5E4v8nf3FuIE+gFtm5NFAjCaeWJg== +lemmy-js-client@0.17.0-rc.11: + version "0.17.0-rc.11" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.11.tgz#fa78dbff5134f270b52dfcc0fe5124bcae8348bb" + integrity sha512-GB0SWguQ/u2slIVLK3YjmCEQDx139xEPTXYFKldZdhSosrmSl4AfbI7FuqxceCDLxlbPjVeMqIFPL8AhuVZR6Q== leven@^3.1.0: version "3.1.0" diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index 53da4f2e..66689204 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -82,18 +82,11 @@ impl Perform for FollowCommunity { let community_id = data.community_id; let person_id = local_user_view.person.id; - let mut community_view = blocking(context.pool(), move |conn| { + let community_view = blocking(context.pool(), move |conn| { CommunityView::read(conn, community_id, Some(person_id)) }) .await??; - // TODO: this needs to return a "pending" state, until Accept is received from the remote server - // For now, just assume that remote follows are accepted. - // Otherwise, the subscribed will be null - if !community.local { - community_view.subscribed = data.follow; - } - - Ok(CommunityResponse { community_view }) + Ok(Self::Response { community_view }) } } diff --git a/crates/db_schema/src/impls/community.rs b/crates/db_schema/src/impls/community.rs index dc539c69..f957fb26 100644 --- a/crates/db_schema/src/impls/community.rs +++ b/crates/db_schema/src/impls/community.rs @@ -13,6 +13,7 @@ use crate::{ }, traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable}, utils::{functions::lower, naive_now}, + SubscribedType, }; use diesel::{ dsl::*, @@ -249,6 +250,22 @@ impl Bannable for CommunityPersonBan { } } +impl CommunityFollower { + pub fn to_subscribed_type(follower: &Option) -> SubscribedType { + match follower { + Some(f) => { + if f.pending.unwrap_or(false) { + SubscribedType::Pending + } else { + SubscribedType::Subscribed + } + } + // If the row doesn't exist, the person isn't a follower. + None => SubscribedType::NotSubscribed, + } + } +} + impl Followable for CommunityFollower { type Form = CommunityFollowerForm; fn follow( diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 5c63f393..718c7768 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -56,3 +56,10 @@ pub enum SearchType { Users, Url, } + +#[derive(EnumString, Display, Debug, PartialEq, Serialize, Deserialize, Clone, Copy)] +pub enum SubscribedType { + Subscribed, + NotSubscribed, + Pending, +} diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 53aac951..2852a6ca 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -64,7 +64,7 @@ impl CommentView { community, counts, creator_banned_from_community, - subscribed, + follower, saved, creator_blocked, comment_like, @@ -149,7 +149,7 @@ impl CommentView { community, counts, creator_banned_from_community: creator_banned_from_community.is_some(), - subscribed: subscribed.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&follower), saved: saved.is_some(), creator_blocked: creator_blocked.is_some(), my_vote, @@ -514,7 +514,7 @@ impl ViewToVec for CommentView { community: a.5.to_owned(), counts: a.6.to_owned(), creator_banned_from_community: a.7.is_some(), - subscribed: a.8.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&a.8), saved: a.9.is_some(), creator_blocked: a.10.is_some(), my_vote: a.11, @@ -531,6 +531,7 @@ mod tests { source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*}, traits::{Blockable, Crud, Likeable}, utils::establish_unpooled_connection, + SubscribedType, }; use serial_test::serial; @@ -619,7 +620,7 @@ mod tests { let expected_comment_view_no_person = CommentView { creator_banned_from_community: false, my_vote: None, - subscribed: false, + subscribed: SubscribedType::NotSubscribed, saved: false, creator_blocked: false, comment: Comment { diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 809b9986..8b02c91a 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -142,7 +142,7 @@ impl PostView { community, creator_banned_from_community: creator_banned_from_community.is_some(), counts, - subscribed: follower.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&follower), saved: saved.is_some(), read: read.is_some(), creator_blocked: creator_blocked.is_some(), @@ -484,7 +484,7 @@ impl ViewToVec for PostView { community: a.2.to_owned(), creator_banned_from_community: a.3.is_some(), counts: a.4.to_owned(), - subscribed: a.5.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&a.5), saved: a.6.is_some(), read: a.7.is_some(), creator_blocked: a.8.is_some(), @@ -510,6 +510,7 @@ mod tests { utils::establish_unpooled_connection, ListingType, SortType, + SubscribedType, }; use serial_test::serial; @@ -702,7 +703,7 @@ mod tests { newest_comment_time_necro: inserted_post.published, newest_comment_time: inserted_post.published, }, - subscribed: false, + subscribed: SubscribedType::NotSubscribed, read: false, saved: false, creator_blocked: false, diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index 59a5f0fe..b92bb271 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -12,6 +12,7 @@ use lemmy_db_schema::{ registration_application::RegistrationApplication, site::Site, }, + SubscribedType, }; use serde::{Deserialize, Serialize}; @@ -38,7 +39,7 @@ pub struct CommentView { pub community: CommunitySafe, pub counts: CommentAggregates, pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan - pub subscribed: bool, // Left join to CommunityFollower + pub subscribed: SubscribedType, // Left join to CommunityFollower pub saved: bool, // Left join to CommentSaved pub creator_blocked: bool, // Left join to PersonBlock pub my_vote: Option, // Left join to CommentLike @@ -78,11 +79,11 @@ pub struct PostView { pub community: CommunitySafe, pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan pub counts: PostAggregates, - pub subscribed: bool, // Left join to CommunityFollower - pub saved: bool, // Left join to PostSaved - pub read: bool, // Left join to PostRead - pub creator_blocked: bool, // Left join to PersonBlock - pub my_vote: Option, // Left join to PostLike + pub subscribed: SubscribedType, // Left join to CommunityFollower + pub saved: bool, // Left join to PostSaved + pub read: bool, // Left join to PostRead + pub creator_blocked: bool, // Left join to PersonBlock + pub my_vote: Option, // Left join to PostLike } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/crates/db_views_actor/src/community_view.rs b/crates/db_views_actor/src/community_view.rs index e6f82812..99546992 100644 --- a/crates/db_views_actor/src/community_view.rs +++ b/crates/db_views_actor/src/community_view.rs @@ -57,7 +57,7 @@ impl CommunityView { Ok(CommunityView { community, - subscribed: follower.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&follower), blocked: blocked.is_some(), counts, }) @@ -262,7 +262,7 @@ impl ViewToVec for CommunityView { .map(|a| Self { community: a.0.to_owned(), counts: a.1.to_owned(), - subscribed: a.2.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&a.2), blocked: a.3.is_some(), }) .collect::>() diff --git a/crates/db_views_actor/src/person_mention_view.rs b/crates/db_views_actor/src/person_mention_view.rs index 43c7f594..d65c165c 100644 --- a/crates/db_views_actor/src/person_mention_view.rs +++ b/crates/db_views_actor/src/person_mention_view.rs @@ -63,7 +63,7 @@ impl PersonMentionView { recipient, counts, creator_banned_from_community, - subscribed, + follower, saved, creator_blocked, my_vote, @@ -140,7 +140,7 @@ impl PersonMentionView { recipient, counts, creator_banned_from_community: creator_banned_from_community.is_some(), - subscribed: subscribed.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&follower), saved: saved.is_some(), creator_blocked: creator_blocked.is_some(), my_vote, @@ -336,7 +336,7 @@ impl ViewToVec for PersonMentionView { recipient: a.5.to_owned(), counts: a.6.to_owned(), creator_banned_from_community: a.7.is_some(), - subscribed: a.8.is_some(), + subscribed: CommunityFollower::to_subscribed_type(&a.8), saved: a.9.is_some(), creator_blocked: a.10.is_some(), my_vote: a.11, diff --git a/crates/db_views_actor/src/structs.rs b/crates/db_views_actor/src/structs.rs index a6ec9710..b45728af 100644 --- a/crates/db_views_actor/src/structs.rs +++ b/crates/db_views_actor/src/structs.rs @@ -7,6 +7,7 @@ use lemmy_db_schema::{ person_mention::PersonMention, post::Post, }, + SubscribedType, }; use serde::{Deserialize, Serialize}; @@ -37,7 +38,7 @@ pub struct CommunityPersonBanView { #[derive(Debug, Serialize, Deserialize, Clone)] pub struct CommunityView { pub community: CommunitySafe, - pub subscribed: bool, + pub subscribed: SubscribedType, pub blocked: bool, pub counts: CommunityAggregates, } @@ -58,7 +59,7 @@ pub struct PersonMentionView { pub recipient: PersonSafeAlias1, pub counts: CommentAggregates, pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan - pub subscribed: bool, // Left join to CommunityFollower + pub subscribed: SubscribedType, // Left join to CommunityFollower pub saved: bool, // Left join to CommentSaved pub creator_blocked: bool, // Left join to PersonBlock pub my_vote: Option, // Left join to CommentLike diff --git a/crates/websocket/src/send.rs b/crates/websocket/src/send.rs index 2e3cf059..7c6820c9 100644 --- a/crates/websocket/src/send.rs +++ b/crates/websocket/src/send.rs @@ -19,6 +19,7 @@ use lemmy_db_schema::{ post::Post, }, traits::{Crud, DeleteableOrRemoveable}, + SubscribedType, }; use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView}; use lemmy_db_views_actor::structs::CommunityView; @@ -115,7 +116,7 @@ pub async fn send_community_ws_message