"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",
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);
// 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';
);
// 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,
);
// 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,
);
// 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);
// 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);
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);
PostResponse,
SearchResponse,
FollowCommunity,
- FollowCommunityResponse,
CommunityResponse,
GetPostResponse,
Register,
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 = {
api: API,
follow: boolean,
community_id: number
-): Promise<FollowCommunityResponse> {
+): Promise<CommunityResponse> {
let form: FollowCommunity = {
community_id,
follow,
}
export async function deleteUser(
- api: API
+ api: API,
): Promise<DeleteAccountResponse> {
let form: DeleteAccount = {
auth: api.auth,
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);
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,
saveUserSettings,
getSite,
createPost,
- // gamma,
+ gamma,
resolveCommunity,
createComment,
resolveBetaCommunity,
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"
use crate::Perform;
use actix_web::web::Data;
use lemmy_api_common::{
- community::{FollowCommunity, FollowCommunityResponse},
+ community::{CommunityResponse, FollowCommunity},
utils::{
blocking,
check_community_ban,
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?;
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 {
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 })
}
}
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)]
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>,
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,
};
community_id -> Int4,
person_id -> Int4,
published -> Timestamp,
- pending -> Bool,
+ pending -> Nullable<Bool>,
}
}
pub community_id: CommunityId,
pub person_id: PersonId,
pub published: chrono::NaiveDateTime,
- pub pending: bool,
+ pub pending: Option<bool>,
}
#[derive(Clone)]
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> {
.select((
Community::safe_columns_tuple(),
Person::safe_columns_tuple(),
- community_follower::pending,
))
.filter(community_follower::community_id.eq(community_id))
.order_by(community::title)
.select((
Community::safe_columns_tuple(),
Person::safe_columns_tuple(),
- community_follower::pending,
))
.filter(community_follower::person_id.eq(person_id))
.order_by(community::title)
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 {
.map(|a| Self {
community: a.0.to_owned(),
follower: a.1.to_owned(),
- pending: a.2.to_owned(),
})
.collect::<Vec<Self>>()
}
pub struct CommunityFollowerView {
pub community: CommunitySafe,
pub follower: PersonSafe,
- pub pending: bool,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
+++ /dev/null
--- This file should undo anything in `up.sql`
-
-alter table community_follower
- alter column pending drop not null,
- alter column pending set default false;
+++ /dev/null
--- 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;
-