]> Untitled Git - lemmy.git/commitdiff
Expose pending 2 (#2282)
authorDessalines <dessalines@users.noreply.github.com>
Wed, 22 Jun 2022 12:05:41 +0000 (08:05 -0400)
committerGitHub <noreply@github.com>
Wed, 22 Jun 2022 12:05:41 +0000 (12:05 +0000)
* Exposing SubscribedType. Fixes #2281

* Fixing other subscribed fields.

* Fix federation tests

* Add comment about follower row.

14 files changed:
api_tests/package.json
api_tests/src/follow.spec.ts
api_tests/src/shared.ts
api_tests/yarn.lock
crates/api/src/community/follow.rs
crates/db_schema/src/impls/community.rs
crates/db_schema/src/lib.rs
crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs
crates/db_views/src/structs.rs
crates/db_views_actor/src/community_view.rs
crates/db_views_actor/src/person_mention_view.rs
crates/db_views_actor/src/structs.rs
crates/websocket/src/send.rs

index 3aa57d49cca1c06d2fc21bef1a56a9577ff42c5c..571202bf96867e5f342f0dd7a4d3f14c7d9b9478 100644 (file)
@@ -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",
index 078c382c25b07ed1955fccaa1fd17118de86a0c9..0515aff44cdeeb68d96673e7b98a83799106c25e 100644 (file)
@@ -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);
index d5be61ac3f66e4164fd05cd780a5a01838170378..7080485e748d43bf06e0cdc1f25ff0dccbf3ee80 100644 (file)
@@ -298,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 = {
@@ -558,7 +558,7 @@ export async function saveUserSettings(
 }
 
 export async function deleteUser(
-  api: API,
+  api: API
 ): Promise<DeleteAccountResponse> {
   let form: DeleteAccount = {
     auth: api.auth,
@@ -613,7 +613,7 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
 export async function reportPost(
   api: API,
   post_id: number,
-  reason: string,
+  reason: string
 ): Promise<PostReportResponse> {
   let form: CreatePostReport = {
     post_id,
@@ -633,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 c60da9dad1966be4d3ddb398c3300aa817e52f52..47a1a52be9c527d1675eba6866fc439f57cd310d 100644 (file)
@@ -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"
index 53da4f2ef6ae161c92fdb966ecfc7a79cd11c855..666892042f04e493efa68c34d028cd88436bb207 100644 (file)
@@ -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 })
   }
 }
index dc539c693fe56df72749f6a14cb7142870745e02..f957fb2617a258d3cd2dc79a694d0f66b3309ebb 100644 (file)
@@ -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<Self>) -> 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(
index 5c63f393a080be3a04872cb39328e8639d5866ee..718c77689082ffc6ac190eb0d075721e9acfb3ab 100644 (file)
@@ -56,3 +56,10 @@ pub enum SearchType {
   Users,
   Url,
 }
+
+#[derive(EnumString, Display, Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
+pub enum SubscribedType {
+  Subscribed,
+  NotSubscribed,
+  Pending,
+}
index 53aac9519e88bedac25c04e6dfac928d1ad0311d..2852a6ca64106a0f42158bb0e9a831d5cb256948 100644 (file)
@@ -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 {
index 809b9986014057deead56c40070bfea81891506d..8b02c91a301c03ae5198e21cecbdafe280d49fdc 100644 (file)
@@ -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,
index 59a5f0fe3d771c7444d27998ced1aa5d5eac1c3f..b92bb271481a086285a7f36e120d8985f1b63927 100644 (file)
@@ -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<i16>,                // 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<i16>,  // 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<i16>,       // Left join to PostLike
 }
 
 #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
index e6f828122102f8a053051d86afeebcc2cd698cf6..99546992bf33d596cc5afc1c676e1e838fc9a4e8 100644 (file)
@@ -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::<Vec<Self>>()
index 43c7f59464eb0f6d2b5f88be05f0f852773c0a82..d65c165c350e4a6b88cd2e569d9720534ebabada 100644 (file)
@@ -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,
index a6ec9710ed8e13fbc626ac2f014f606afb0c3fb2..b45728af541f5ce1e65dbca5fe32e57e9f1f0699 100644 (file)
@@ -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<i16>,                // Left join to CommentLike
index 2e3cf0597c54daa6e3a7de0e15f0f0662239ea43..7c6820c9a4109699b4eba4d640a0c9de116bc364 100644 (file)
@@ -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<OP: ToString + Send + OperationType + 'st
 
   // Strip out the person id and subscribed when sending to others
   let mut res_mut = res.clone();
-  res_mut.community_view.subscribed = false;
+  res_mut.community_view.subscribed = SubscribedType::NotSubscribed;
 
   context.chat_server().do_send(SendCommunityRoomMessage {
     op,