From 19c84613977724c4008aba3d37141c86901f9ca8 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 14 Apr 2020 17:37:23 +0200 Subject: Implemented follow/accept --- server/src/api/community.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'server/src/api/community.rs') diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 3edecb4f..35ca1d26 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -1,4 +1,5 @@ use super::*; +use crate::apub::activities::follow_community; use crate::apub::{format_community_name, gen_keypair_str, make_apub_endpoint, EndpointType}; use diesel::PgConnection; use std::str::FromStr; @@ -401,21 +402,29 @@ impl Perform for Oper { let user_id = claims.id; - let community_follower_form = CommunityFollowerForm { - community_id: data.community_id, - user_id, - }; - - if data.follow { - match CommunityFollower::follow(&conn, &community_follower_form) { - Ok(user) => user, - Err(_e) => return Err(APIError::err("community_follower_already_exists").into()), + let community = Community::read(conn, data.community_id)?; + if community.local { + let community_follower_form = CommunityFollowerForm { + community_id: data.community_id, + user_id, }; + + if data.follow { + match CommunityFollower::follow(&conn, &community_follower_form) { + Ok(user) => user, + Err(_e) => return Err(APIError::err("community_follower_already_exists").into()), + }; + } else { + match CommunityFollower::ignore(&conn, &community_follower_form) { + Ok(user) => user, + Err(_e) => return Err(APIError::err("community_follower_already_exists").into()), + }; + } } else { - match CommunityFollower::ignore(&conn, &community_follower_form) { - Ok(user) => user, - Err(_e) => return Err(APIError::err("community_follower_already_exists").into()), - }; + // TODO: still have to implement unfollow + let user = User_::read(conn, user_id)?; + follow_community(&community, &user, conn)?; + // TODO: this needs to return a "pending" state, until Accept is received from the remote server } let community_view = CommunityView::read(&conn, data.community_id, Some(user_id))?; -- cgit v1.2.3