"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",
jest.setTimeout(120000);
+import {SubscribedType} from 'lemmy-js-client';
import {
alpha,
setupLogins,
// 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);
// 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);
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 = {
}
export async function deleteUser(
- api: API,
+ api: API
): Promise<DeleteAccountResponse> {
let form: DeleteAccount = {
auth: api.auth,
export async function reportPost(
api: API,
post_id: number,
- reason: string,
+ reason: string
): Promise<PostReportResponse> {
let form: CreatePostReport = {
post_id,
export async function reportComment(
api: API,
comment_id: number,
- reason: string,
+ reason: string
): Promise<CommentReportResponse> {
let form: CreateCommentReport = {
comment_id,
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"
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 })
}
}
},
traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
utils::{functions::lower, naive_now},
+ SubscribedType,
};
use diesel::{
dsl::*,
}
}
+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(
Users,
Url,
}
+
+#[derive(EnumString, Display, Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
+pub enum SubscribedType {
+ Subscribed,
+ NotSubscribed,
+ Pending,
+}
community,
counts,
creator_banned_from_community,
- subscribed,
+ follower,
saved,
creator_blocked,
comment_like,
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,
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,
source::{comment::*, community::*, person::*, person_block::PersonBlockForm, post::*},
traits::{Blockable, Crud, Likeable},
utils::establish_unpooled_connection,
+ SubscribedType,
};
use serial_test::serial;
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 {
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(),
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(),
utils::establish_unpooled_connection,
ListingType,
SortType,
+ SubscribedType,
};
use serial_test::serial;
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,
registration_application::RegistrationApplication,
site::Site,
},
+ SubscribedType,
};
use serde::{Deserialize, Serialize};
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
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)]
Ok(CommunityView {
community,
- subscribed: follower.is_some(),
+ subscribed: CommunityFollower::to_subscribed_type(&follower),
blocked: blocked.is_some(),
counts,
})
.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>>()
recipient,
counts,
creator_banned_from_community,
- subscribed,
+ follower,
saved,
creator_blocked,
my_vote,
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,
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,
person_mention::PersonMention,
post::Post,
},
+ SubscribedType,
};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct CommunityView {
pub community: CommunitySafe,
- pub subscribed: bool,
+ pub subscribed: SubscribedType,
pub blocked: bool,
pub counts: CommunityAggregates,
}
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
post::Post,
},
traits::{Crud, DeleteableOrRemoveable},
+ SubscribedType,
};
use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView};
use lemmy_db_views_actor::structs::CommunityView;
// 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,