mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 11:21:02 +00:00
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:
parent
dc35ab9c2b
commit
92d17639cd
14 changed files with 64 additions and 40 deletions
|
@ -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",
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -56,3 +56,10 @@ pub enum SearchType {
|
|||
Users,
|
||||
Url,
|
||||
}
|
||||
|
||||
#[derive(EnumString, Display, Debug, PartialEq, Serialize, Deserialize, Clone, Copy)]
|
||||
pub enum SubscribedType {
|
||||
Subscribed,
|
||||
NotSubscribed,
|
||||
Pending,
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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>>()
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue