Expose pending 2 (#2282)

* Exposing SubscribedType. Fixes #2281

* Fixing other subscribed fields.

* Fix federation tests

* Add comment about follower row.
This commit is contained in:
Dessalines 2022-06-22 08:05:41 -04:00 committed by GitHub
parent dc35ab9c2b
commit 92d17639cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 64 additions and 40 deletions

View file

@ -16,7 +16,7 @@
"eslint": "^7.30.0", "eslint": "^7.30.0",
"eslint-plugin-jane": "^9.0.3", "eslint-plugin-jane": "^9.0.3",
"jest": "^27.0.6", "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", "node-fetch": "^2.6.1",
"prettier": "^2.3.2", "prettier": "^2.3.2",
"ts-jest": "^27.0.3", "ts-jest": "^27.0.3",

View file

@ -1,4 +1,5 @@
jest.setTimeout(120000); jest.setTimeout(120000);
import {SubscribedType} from 'lemmy-js-client';
import { import {
alpha, alpha,
setupLogins, setupLogins,
@ -27,6 +28,7 @@ test('Follow federated community', async () => {
// Make sure the follow response went through // Make sure the follow response went through
expect(follow.community_view.community.local).toBe(false); expect(follow.community_view.community.local).toBe(false);
expect(follow.community_view.community.name).toBe('main'); expect(follow.community_view.community.name).toBe('main');
expect(follow.community_view.subscribed).toBe(SubscribedType.Pending);
// Check it from local // Check it from local
let site = await getSite(alpha); let site = await getSite(alpha);
@ -37,7 +39,7 @@ test('Follow federated community', async () => {
// Test an unfollow // Test an unfollow
let unfollow = await followCommunity(alpha, false, remoteCommunityId); 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 // Make sure you are unsubbed locally
let siteUnfollowCheck = await getSite(alpha); let siteUnfollowCheck = await getSite(alpha);

View file

@ -298,7 +298,7 @@ export async function banPersonFromSite(
api: API, api: API,
person_id: number, person_id: number,
ban: boolean, ban: boolean,
remove_data: boolean, remove_data: boolean
): Promise<BanPersonResponse> { ): Promise<BanPersonResponse> {
// Make sure lemmy-beta/c/main is cached on lemmy_alpha // Make sure lemmy-beta/c/main is cached on lemmy_alpha
let form: BanPerson = { let form: BanPerson = {
@ -558,7 +558,7 @@ export async function saveUserSettings(
} }
export async function deleteUser( export async function deleteUser(
api: API, api: API
): Promise<DeleteAccountResponse> { ): Promise<DeleteAccountResponse> {
let form: DeleteAccount = { let form: DeleteAccount = {
auth: api.auth, auth: api.auth,
@ -613,7 +613,7 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
export async function reportPost( export async function reportPost(
api: API, api: API,
post_id: number, post_id: number,
reason: string, reason: string
): Promise<PostReportResponse> { ): Promise<PostReportResponse> {
let form: CreatePostReport = { let form: CreatePostReport = {
post_id, post_id,
@ -633,7 +633,7 @@ export async function listPostReports(api: API): Promise<ListPostReportsResponse
export async function reportComment( export async function reportComment(
api: API, api: API,
comment_id: number, comment_id: number,
reason: string, reason: string
): Promise<CommentReportResponse> { ): Promise<CommentReportResponse> {
let form: CreateCommentReport = { let form: CreateCommentReport = {
comment_id, comment_id,

View file

@ -3076,10 +3076,10 @@ language-tags@^1.0.5:
dependencies: dependencies:
language-subtag-registry "~0.3.2" language-subtag-registry "~0.3.2"
lemmy-js-client@0.16.0-rc.1: lemmy-js-client@0.17.0-rc.11:
version "0.16.0-rc.1" version "0.17.0-rc.11"
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.16.0-rc.1.tgz#14c4a526abf4b171c8afe4efbe2a62dcaf6a6f17" resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.11.tgz#fa78dbff5134f270b52dfcc0fe5124bcae8348bb"
integrity sha512-0hR/gHHsokp46whIHGMBQO2zBKWM7bT6mwKNMZxPvyJo+YW9EbKTO5edjF5E4v8nf3FuIE+gFtm5NFAjCaeWJg== integrity sha512-GB0SWguQ/u2slIVLK3YjmCEQDx139xEPTXYFKldZdhSosrmSl4AfbI7FuqxceCDLxlbPjVeMqIFPL8AhuVZR6Q==
leven@^3.1.0: leven@^3.1.0:
version "3.1.0" version "3.1.0"

View file

@ -82,18 +82,11 @@ impl Perform for FollowCommunity {
let community_id = data.community_id; let community_id = data.community_id;
let person_id = local_user_view.person.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)) CommunityView::read(conn, community_id, Some(person_id))
}) })
.await??; .await??;
// TODO: this needs to return a "pending" state, until Accept is received from the remote server Ok(Self::Response { community_view })
// 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 })
} }
} }

View file

@ -13,6 +13,7 @@ use crate::{
}, },
traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable}, traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
utils::{functions::lower, naive_now}, utils::{functions::lower, naive_now},
SubscribedType,
}; };
use diesel::{ use diesel::{
dsl::*, 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 { impl Followable for CommunityFollower {
type Form = CommunityFollowerForm; type Form = CommunityFollowerForm;
fn follow( fn follow(

View file

@ -56,3 +56,10 @@ pub enum SearchType {
Users, Users,
Url, Url,
} }
#[derive(EnumString, Display, Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
pub enum SubscribedType {
Subscribed,
NotSubscribed,
Pending,
}

View file

@ -64,7 +64,7 @@ impl CommentView {
community, community,
counts, counts,
creator_banned_from_community, creator_banned_from_community,
subscribed, follower,
saved, saved,
creator_blocked, creator_blocked,
comment_like, comment_like,
@ -149,7 +149,7 @@ impl CommentView {
community, community,
counts, counts,
creator_banned_from_community: creator_banned_from_community.is_some(), creator_banned_from_community: creator_banned_from_community.is_some(),
subscribed: subscribed.is_some(), subscribed: CommunityFollower::to_subscribed_type(&follower),
saved: saved.is_some(), saved: saved.is_some(),
creator_blocked: creator_blocked.is_some(), creator_blocked: creator_blocked.is_some(),
my_vote, my_vote,
@ -514,7 +514,7 @@ impl ViewToVec for CommentView {
community: a.5.to_owned(), community: a.5.to_owned(),
counts: a.6.to_owned(), counts: a.6.to_owned(),
creator_banned_from_community: a.7.is_some(), 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(), saved: a.9.is_some(),
creator_blocked: a.10.is_some(), creator_blocked: a.10.is_some(),
my_vote: a.11, my_vote: a.11,
@ -531,6 +531,7 @@ mod tests {
source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*}, source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*},
traits::{Blockable, Crud, Likeable}, traits::{Blockable, Crud, Likeable},
utils::establish_unpooled_connection, utils::establish_unpooled_connection,
SubscribedType,
}; };
use serial_test::serial; use serial_test::serial;
@ -619,7 +620,7 @@ mod tests {
let expected_comment_view_no_person = CommentView { let expected_comment_view_no_person = CommentView {
creator_banned_from_community: false, creator_banned_from_community: false,
my_vote: None, my_vote: None,
subscribed: false, subscribed: SubscribedType::NotSubscribed,
saved: false, saved: false,
creator_blocked: false, creator_blocked: false,
comment: Comment { comment: Comment {

View file

@ -142,7 +142,7 @@ impl PostView {
community, community,
creator_banned_from_community: creator_banned_from_community.is_some(), creator_banned_from_community: creator_banned_from_community.is_some(),
counts, counts,
subscribed: follower.is_some(), subscribed: CommunityFollower::to_subscribed_type(&follower),
saved: saved.is_some(), saved: saved.is_some(),
read: read.is_some(), read: read.is_some(),
creator_blocked: creator_blocked.is_some(), creator_blocked: creator_blocked.is_some(),
@ -484,7 +484,7 @@ impl ViewToVec for PostView {
community: a.2.to_owned(), community: a.2.to_owned(),
creator_banned_from_community: a.3.is_some(), creator_banned_from_community: a.3.is_some(),
counts: a.4.to_owned(), counts: a.4.to_owned(),
subscribed: a.5.is_some(), subscribed: CommunityFollower::to_subscribed_type(&a.5),
saved: a.6.is_some(), saved: a.6.is_some(),
read: a.7.is_some(), read: a.7.is_some(),
creator_blocked: a.8.is_some(), creator_blocked: a.8.is_some(),
@ -510,6 +510,7 @@ mod tests {
utils::establish_unpooled_connection, utils::establish_unpooled_connection,
ListingType, ListingType,
SortType, SortType,
SubscribedType,
}; };
use serial_test::serial; use serial_test::serial;
@ -702,7 +703,7 @@ mod tests {
newest_comment_time_necro: inserted_post.published, newest_comment_time_necro: inserted_post.published,
newest_comment_time: inserted_post.published, newest_comment_time: inserted_post.published,
}, },
subscribed: false, subscribed: SubscribedType::NotSubscribed,
read: false, read: false,
saved: false, saved: false,
creator_blocked: false, creator_blocked: false,

View file

@ -12,6 +12,7 @@ use lemmy_db_schema::{
registration_application::RegistrationApplication, registration_application::RegistrationApplication,
site::Site, site::Site,
}, },
SubscribedType,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -38,7 +39,7 @@ pub struct CommentView {
pub community: CommunitySafe, pub community: CommunitySafe,
pub counts: CommentAggregates, pub counts: CommentAggregates,
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan 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 saved: bool, // Left join to CommentSaved
pub creator_blocked: bool, // Left join to PersonBlock pub creator_blocked: bool, // Left join to PersonBlock
pub my_vote: Option<i16>, // Left join to CommentLike pub my_vote: Option<i16>, // Left join to CommentLike
@ -78,7 +79,7 @@ pub struct PostView {
pub community: CommunitySafe, pub community: CommunitySafe,
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan
pub counts: PostAggregates, pub counts: PostAggregates,
pub subscribed: bool, // Left join to CommunityFollower pub subscribed: SubscribedType, // Left join to CommunityFollower
pub saved: bool, // Left join to PostSaved pub saved: bool, // Left join to PostSaved
pub read: bool, // Left join to PostRead pub read: bool, // Left join to PostRead
pub creator_blocked: bool, // Left join to PersonBlock pub creator_blocked: bool, // Left join to PersonBlock

View file

@ -57,7 +57,7 @@ impl CommunityView {
Ok(CommunityView { Ok(CommunityView {
community, community,
subscribed: follower.is_some(), subscribed: CommunityFollower::to_subscribed_type(&follower),
blocked: blocked.is_some(), blocked: blocked.is_some(),
counts, counts,
}) })
@ -262,7 +262,7 @@ impl ViewToVec for CommunityView {
.map(|a| Self { .map(|a| Self {
community: a.0.to_owned(), community: a.0.to_owned(),
counts: a.1.to_owned(), counts: a.1.to_owned(),
subscribed: a.2.is_some(), subscribed: CommunityFollower::to_subscribed_type(&a.2),
blocked: a.3.is_some(), blocked: a.3.is_some(),
}) })
.collect::<Vec<Self>>() .collect::<Vec<Self>>()

View file

@ -63,7 +63,7 @@ impl PersonMentionView {
recipient, recipient,
counts, counts,
creator_banned_from_community, creator_banned_from_community,
subscribed, follower,
saved, saved,
creator_blocked, creator_blocked,
my_vote, my_vote,
@ -140,7 +140,7 @@ impl PersonMentionView {
recipient, recipient,
counts, counts,
creator_banned_from_community: creator_banned_from_community.is_some(), creator_banned_from_community: creator_banned_from_community.is_some(),
subscribed: subscribed.is_some(), subscribed: CommunityFollower::to_subscribed_type(&follower),
saved: saved.is_some(), saved: saved.is_some(),
creator_blocked: creator_blocked.is_some(), creator_blocked: creator_blocked.is_some(),
my_vote, my_vote,
@ -336,7 +336,7 @@ impl ViewToVec for PersonMentionView {
recipient: a.5.to_owned(), recipient: a.5.to_owned(),
counts: a.6.to_owned(), counts: a.6.to_owned(),
creator_banned_from_community: a.7.is_some(), 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(), saved: a.9.is_some(),
creator_blocked: a.10.is_some(), creator_blocked: a.10.is_some(),
my_vote: a.11, my_vote: a.11,

View file

@ -7,6 +7,7 @@ use lemmy_db_schema::{
person_mention::PersonMention, person_mention::PersonMention,
post::Post, post::Post,
}, },
SubscribedType,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -37,7 +38,7 @@ pub struct CommunityPersonBanView {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CommunityView { pub struct CommunityView {
pub community: CommunitySafe, pub community: CommunitySafe,
pub subscribed: bool, pub subscribed: SubscribedType,
pub blocked: bool, pub blocked: bool,
pub counts: CommunityAggregates, pub counts: CommunityAggregates,
} }
@ -58,7 +59,7 @@ pub struct PersonMentionView {
pub recipient: PersonSafeAlias1, pub recipient: PersonSafeAlias1,
pub counts: CommentAggregates, pub counts: CommentAggregates,
pub creator_banned_from_community: bool, // Left Join to CommunityPersonBan 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 saved: bool, // Left join to CommentSaved
pub creator_blocked: bool, // Left join to PersonBlock pub creator_blocked: bool, // Left join to PersonBlock
pub my_vote: Option<i16>, // Left join to CommentLike pub my_vote: Option<i16>, // Left join to CommentLike

View file

@ -19,6 +19,7 @@ use lemmy_db_schema::{
post::Post, post::Post,
}, },
traits::{Crud, DeleteableOrRemoveable}, traits::{Crud, DeleteableOrRemoveable},
SubscribedType,
}; };
use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView}; use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView};
use lemmy_db_views_actor::structs::CommunityView; 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 // Strip out the person id and subscribed when sending to others
let mut res_mut = res.clone(); 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 { context.chat_server().do_send(SendCommunityRoomMessage {
op, op,