]> Untitled Git - lemmy.git/commitdiff
Revert "Add pending, and change use specific API response for FollowCommunity…" ...
authorDessalines <dessalines@users.noreply.github.com>
Thu, 26 May 2022 15:17:04 +0000 (11:17 -0400)
committerGitHub <noreply@github.com>
Thu, 26 May 2022 15:17:04 +0000 (11:17 -0400)
17 files changed:
api_tests/package.json
api_tests/src/comment.spec.ts
api_tests/src/community.spec.ts
api_tests/src/follow.spec.ts
api_tests/src/post.spec.ts
api_tests/src/shared.ts
api_tests/src/user.spec.ts
api_tests/yarn.lock
crates/api/src/community/follow.rs
crates/api_common/src/community.rs
crates/db_schema/src/impls/community.rs
crates/db_schema/src/schema.rs
crates/db_schema/src/source/community.rs
crates/db_views_actor/src/community_follower_view.rs
crates/db_views_actor/src/structs.rs
migrations/2022-05-10-173801_change_pending_to_notnull/down.sql [deleted file]
migrations/2022-05-10-173801_change_pending_to_notnull/up.sql [deleted file]

index 4deffe4f686896d65335512f6d9dbe577e11ca3d..3aa57d49cca1c06d2fc21bef1a56a9577ff42c5c 100644 (file)
@@ -16,7 +16,7 @@
     "eslint": "^7.30.0",
     "eslint-plugin-jane": "^9.0.3",
     "jest": "^27.0.6",
-    "lemmy-js-client": "0.17.0-rc.3",
+    "lemmy-js-client": "0.16.0-rc.1",
     "node-fetch": "^2.6.1",
     "prettier": "^2.3.2",
     "ts-jest": "^27.0.3",
index cfb09a5174c0fba8c41b424c78a9764e12be5982..314f18ecc5b06885587c2285e979674819ca6348 100644 (file)
@@ -329,12 +329,12 @@ test('A and G subscribe to B (center) A posts, G mentions B, it gets announced t
 test('Check that activity from another instance is sent to third instance', async () => {
   // Alpha and gamma users follow beta community
   let alphaFollow = await followBeta(alpha);
-  expect(alphaFollow.community_follower_view.community.local).toBe(false);
-  expect(alphaFollow.community_follower_view.community.name).toBe('main');
+  expect(alphaFollow.community_view.community.local).toBe(false);
+  expect(alphaFollow.community_view.community.name).toBe('main');
 
   let gammaFollow = await followBeta(gamma);
-  expect(gammaFollow.community_follower_view.community.local).toBe(false);
-  expect(gammaFollow.community_follower_view.community.name).toBe('main');
+  expect(gammaFollow.community_view.community.local).toBe(false);
+  expect(gammaFollow.community_view.community.name).toBe('main');
 
   // Create a post on beta
   let betaPost = await createPost(beta, 2);
@@ -407,8 +407,8 @@ test('Fetch in_reply_tos: A is unsubbed from B, B makes a post, and some embedde
 
   // Follow beta again
   let follow = await followBeta(alpha);
-  expect(follow.community_follower_view.community.local).toBe(false);
-  expect(follow.community_follower_view.community.name).toBe('main');
+  expect(follow.community_view.community.local).toBe(false);
+  expect(follow.community_view.community.name).toBe('main');
 
   // An update to the child comment on beta, should push the post, parent, and child to alpha now
   let updatedCommentContent = 'An update child comment from beta';
index ba12de5c4b2199b98ab759ede8b29a3143162715..e1f6825ae8ab9fc369061b26309984d314b12572 100644 (file)
@@ -67,7 +67,7 @@ test('Delete community', async () => {
   );
 
   // Make sure the follow response went through
-  expect(follow.community_follower_view.community.local).toBe(false);
+  expect(follow.community_view.community.local).toBe(false);
 
   let deleteCommunityRes = await deleteCommunity(
     beta,
@@ -118,7 +118,7 @@ test('Remove community', async () => {
   );
 
   // Make sure the follow response went through
-  expect(follow.community_follower_view.community.local).toBe(false);
+  expect(follow.community_view.community.local).toBe(false);
 
   let removeCommunityRes = await removeCommunity(
     beta,
index d75735b00e402421ff050842b3974e606c8e075f..078c382c25b07ed1955fccaa1fd17118de86a0c9 100644 (file)
@@ -25,9 +25,8 @@ test('Follow federated community', async () => {
   );
 
   // Make sure the follow response went through
-  expect(follow.community_follower_view.community.local).toBe(false);
-  expect(follow.community_follower_view.community.name).toBe('main');
-  expect(follow.community_follower_view.pending).toBe(true);
+  expect(follow.community_view.community.local).toBe(false);
+  expect(follow.community_view.community.name).toBe('main');
 
   // Check it from local
   let site = await getSite(alpha);
@@ -38,7 +37,7 @@ test('Follow federated community', async () => {
 
   // Test an unfollow
   let unfollow = await followCommunity(alpha, false, remoteCommunityId);
-  expect(unfollow.community_follower_view).toBeNull()
+  expect(unfollow.community_view.community.local).toBe(false);
 
   // Make sure you are unsubbed locally
   let siteUnfollowCheck = await getSite(alpha);
index 82545528e089e7e7ca50bf7308319c12b9119953..b2f12298c309b7ae960e79bc8b2b23e85ec791fc 100644 (file)
@@ -261,7 +261,7 @@ test('Remove a post from admin and community on same instance', async () => {
   expect(removePostRes.post_view.post.removed).toBe(true);
 
   // Make sure lemmy alpha sees post is removed
-  // let alphaPost = await getPost(alpha, postRes.post_view.post.id);
+  let alphaPost = await getPost(alpha, postRes.post_view.post.id);
   // expect(alphaPost.post_view.post.removed).toBe(true); // TODO this shouldn't be commented
   // assertPostFederation(alphaPost.post_view, removePostRes.post_view);
 
index d4b75c7e43b3b78437553fd2e601ebb7cf99a972..d5be61ac3f66e4164fd05cd780a5a01838170378 100644 (file)
@@ -11,7 +11,6 @@ import {
   PostResponse,
   SearchResponse,
   FollowCommunity,
-  FollowCommunityResponse,
   CommunityResponse,
   GetPostResponse,
   Register,
@@ -299,7 +298,7 @@ export async function banPersonFromSite(
   api: API,
   person_id: number,
   ban: boolean,
-  remove_data: boolean
+  remove_data: boolean,
 ): Promise<BanPersonResponse> {
   // Make sure lemmy-beta/c/main is cached on lemmy_alpha
   let form: BanPerson = {
@@ -332,7 +331,7 @@ export async function followCommunity(
   api: API,
   follow: boolean,
   community_id: number
-): Promise<FollowCommunityResponse> {
+): Promise<CommunityResponse> {
   let form: FollowCommunity = {
     community_id,
     follow,
@@ -559,7 +558,7 @@ export async function saveUserSettings(
 }
 
 export async function deleteUser(
-  api: API
+  api: API,
 ): Promise<DeleteAccountResponse> {
   let form: DeleteAccount = {
     auth: api.auth,
@@ -603,7 +602,7 @@ export async function unfollowRemotes(
   return siteRes;
 }
 
-export async function followBeta(api: API): Promise<FollowCommunityResponse> {
+export async function followBeta(api: API): Promise<CommunityResponse> {
   let betaCommunity = (await resolveBetaCommunity(api)).community;
   if (betaCommunity) {
     let follow = await followCommunity(api, true, betaCommunity.community.id);
@@ -614,7 +613,7 @@ export async function followBeta(api: API): Promise<FollowCommunityResponse> {
 export async function reportPost(
   api: API,
   post_id: number,
-  reason: string
+  reason: string,
 ): Promise<PostReportResponse> {
   let form: CreatePostReport = {
     post_id,
@@ -634,7 +633,7 @@ export async function listPostReports(api: API): Promise<ListPostReportsResponse
 export async function reportComment(
   api: API,
   comment_id: number,
-  reason: string
+  reason: string,
 ): Promise<CommentReportResponse> {
   let form: CreateCommentReport = {
     comment_id,
index 7e45760e5948e7619182dd092a1fc7ba3afd71c6..29029ac1e9d231ad212e1bcb10f08024b5e50264 100644 (file)
@@ -7,7 +7,7 @@ import {
   saveUserSettings,
   getSite,
   createPost,
-  // gamma,
+  gamma,
   resolveCommunity,
   createComment,
   resolveBetaCommunity,
index 3b198755d530b3bf376b1a0f51a9194131de22d0..c60da9dad1966be4d3ddb398c3300aa817e52f52 100644 (file)
@@ -3076,10 +3076,10 @@ language-tags@^1.0.5:
   dependencies:
     language-subtag-registry "~0.3.2"
 
-lemmy-js-client@0.17.0-rc.3:
-  version "0.17.0-rc.3"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.3.tgz#3c9b3d5e3346eed8cb8096dad527e72096052223"
-  integrity sha512-VwKSkjqZhsTrtlKTKs9DEVaj9rlmMEjzn/BxkizU9v03Km7OIs9Z7cOEfperOR9A6q5gh2hWfTDp5eV/0kYkVg==
+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==
 
 leven@^3.1.0:
   version "3.1.0"
index a61383b219316bafccc19b1b2ddfe9702c54d96f..aab21a9c217a7361daa0f6395ba2ceebaa2f2cf0 100644 (file)
@@ -1,7 +1,7 @@
 use crate::Perform;
 use actix_web::web::Data;
 use lemmy_api_common::{
-  community::{FollowCommunity, FollowCommunityResponse},
+  community::{CommunityResponse, FollowCommunity},
   utils::{
     blocking,
     check_community_ban,
@@ -20,20 +20,20 @@ use lemmy_db_schema::{
   source::community::{Community, CommunityFollower, CommunityFollowerForm},
   traits::{Crud, Followable},
 };
-use lemmy_db_views_actor::structs::CommunityFollowerView;
+use lemmy_db_views_actor::structs::CommunityView;
 use lemmy_utils::{ConnectionId, LemmyError};
 use lemmy_websocket::LemmyContext;
 
 #[async_trait::async_trait(?Send)]
 impl Perform for FollowCommunity {
-  type Response = FollowCommunityResponse;
+  type Response = CommunityResponse;
 
   #[tracing::instrument(skip(context, _websocket_id))]
   async fn perform(
     &self,
     context: &Data<LemmyContext>,
     _websocket_id: Option<ConnectionId>,
-  ) -> Result<Self::Response, LemmyError> {
+  ) -> Result<CommunityResponse, LemmyError> {
     let data: &FollowCommunity = self;
     let local_user_view =
       get_local_user_view_from_jwt(&data.auth, context.pool(), context.secret()).await?;
@@ -47,7 +47,7 @@ impl Perform for FollowCommunity {
     let community_follower_form = CommunityFollowerForm {
       community_id: data.community_id,
       person_id: local_user_view.person.id,
-      pending: false, // Don't worry, this form isn't used for remote follows
+      pending: false,
     };
 
     if community.local {
@@ -82,14 +82,18 @@ impl Perform for FollowCommunity {
 
     let community_id = data.community_id;
     let person_id = local_user_view.person.id;
-    let community_follower_view = blocking(context.pool(), move |conn| {
-      CommunityFollowerView::read(conn, community_id, person_id)
+    let mut community_view = blocking(context.pool(), move |conn| {
+      CommunityView::read(conn, community_id, Some(person_id))
     })
-    .await?
-    .ok();
+    .await??;
 
-    Ok(Self::Response {
-      community_follower_view,
-    })
+    // 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 })
   }
 }
index 3c0f33d1c6c65fd5a2464c7b13f991f631e2314c..90c86f1c2d3c2671cf112c26e8e941ff13e890da 100644 (file)
@@ -5,12 +5,7 @@ use lemmy_db_schema::{
   ListingType,
   SortType,
 };
-use lemmy_db_views_actor::structs::{
-  CommunityFollowerView,
-  CommunityModeratorView,
-  CommunityView,
-  PersonViewSafe,
-};
+use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView, PersonViewSafe};
 use serde::{Deserialize, Serialize};
 
 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
@@ -46,12 +41,6 @@ pub struct CommunityResponse {
   pub community_view: CommunityView,
 }
 
-#[derive(Debug, Serialize, Deserialize, Clone)]
-/// An unfollow will return None
-pub struct FollowCommunityResponse {
-  pub community_follower_view: Option<CommunityFollowerView>,
-}
-
 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
 pub struct ListCommunities {
   pub type_: Option<ListingType>,
index 073255cdb05c4b95ca14f325269841754ec7c6f1..14a670f51c58ad1c7e33263b582fd8a678f879cc 100644 (file)
@@ -390,7 +390,7 @@ mod tests {
       id: inserted_community_follower.id,
       community_id: inserted_community.id,
       person_id: inserted_person.id,
-      pending: false,
+      pending: Some(false),
       published: inserted_community_follower.published,
     };
 
index 74285e3c693360c12fad3c34c0c20bd85f6d9c65..666986a691cb9e5a476c98a0cf7fcc0132dd5c9b 100644 (file)
@@ -119,7 +119,7 @@ table! {
         community_id -> Int4,
         person_id -> Int4,
         published -> Timestamp,
-        pending -> Bool,
+        pending -> Nullable<Bool>,
     }
 }
 
index 25766b4084743f6e12645f6fcb373ff8ce39db9c..7693f2f419c8d88ac335930632873e333d32bed2 100644 (file)
@@ -128,7 +128,7 @@ pub struct CommunityFollower {
   pub community_id: CommunityId,
   pub person_id: PersonId,
   pub published: chrono::NaiveDateTime,
-  pub pending: bool,
+  pub pending: Option<bool>,
 }
 
 #[derive(Clone)]
index 7bece59d353db42922a969ad1ae571c18ce5dfb9..6d5d94a596cb30c338ad2a8dea0a4ce2cc840973 100644 (file)
@@ -10,7 +10,7 @@ use lemmy_db_schema::{
   traits::{ToSafe, ViewToVec},
 };
 
-type CommunityFollowerViewTuple = (CommunitySafe, PersonSafe, bool);
+type CommunityFollowerViewTuple = (CommunitySafe, PersonSafe);
 
 impl CommunityFollowerView {
   pub fn for_community(conn: &PgConnection, community_id: CommunityId) -> Result<Vec<Self>, Error> {
@@ -20,7 +20,6 @@ impl CommunityFollowerView {
       .select((
         Community::safe_columns_tuple(),
         Person::safe_columns_tuple(),
-        community_follower::pending,
       ))
       .filter(community_follower::community_id.eq(community_id))
       .order_by(community::title)
@@ -36,7 +35,6 @@ impl CommunityFollowerView {
       .select((
         Community::safe_columns_tuple(),
         Person::safe_columns_tuple(),
-        community_follower::pending,
       ))
       .filter(community_follower::person_id.eq(person_id))
       .order_by(community::title)
@@ -44,30 +42,6 @@ impl CommunityFollowerView {
 
     Ok(Self::from_tuple_to_vec(res))
   }
-
-  pub fn read(
-    conn: &PgConnection,
-    community_id: CommunityId,
-    person_id: PersonId,
-  ) -> Result<Self, Error> {
-    let (community, follower, pending) = community_follower::table
-      .inner_join(community::table)
-      .inner_join(person::table)
-      .select((
-        Community::safe_columns_tuple(),
-        Person::safe_columns_tuple(),
-        community_follower::pending,
-      ))
-      .filter(community_follower::person_id.eq(person_id))
-      .filter(community_follower::community_id.eq(community_id))
-      .first::<CommunityFollowerViewTuple>(conn)?;
-
-    Ok(Self {
-      community,
-      follower,
-      pending,
-    })
-  }
 }
 
 impl ViewToVec for CommunityFollowerView {
@@ -78,7 +52,6 @@ impl ViewToVec for CommunityFollowerView {
       .map(|a| Self {
         community: a.0.to_owned(),
         follower: a.1.to_owned(),
-        pending: a.2.to_owned(),
       })
       .collect::<Vec<Self>>()
   }
index a0b1ad4bccc02ceef0ca94fd515a6982a944ffd0..a6ec9710ed8e13fbc626ac2f014f606afb0c3fb2 100644 (file)
@@ -20,7 +20,6 @@ pub struct CommunityBlockView {
 pub struct CommunityFollowerView {
   pub community: CommunitySafe,
   pub follower: PersonSafe,
-  pub pending: bool,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
diff --git a/migrations/2022-05-10-173801_change_pending_to_notnull/down.sql b/migrations/2022-05-10-173801_change_pending_to_notnull/down.sql
deleted file mode 100644 (file)
index 4ef1387..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
--- This file should undo anything in `up.sql`
-
-alter table community_follower
-  alter column pending drop not null,
-  alter column pending set default false;
diff --git a/migrations/2022-05-10-173801_change_pending_to_notnull/up.sql b/migrations/2022-05-10-173801_change_pending_to_notnull/up.sql
deleted file mode 100644 (file)
index 659f321..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
--- Make the pending column not null
-
-update community_follower set pending = true where pending is null;
-
-alter table community_follower
-  alter column pending set not null,
-  alter column pending drop default;
-