summaryrefslogtreecommitdiffstats
path: root/server/src/api/community.rs
diff options
context:
space:
mode:
authorFelix <me@nutomic.com>2020-04-14 17:37:23 +0200
committerFelix <me@nutomic.com>2020-04-14 17:37:23 +0200
commit19c84613977724c4008aba3d37141c86901f9ca8 (patch)
treecc530d0c42ba5aab18f4bd50aa494da06b23407a /server/src/api/community.rs
parent13e6c98e47b0a44c2313f086ed2f50b37430f84c (diff)
Implemented follow/accept
Diffstat (limited to 'server/src/api/community.rs')
-rw-r--r--server/src/api/community.rs35
1 files changed, 22 insertions, 13 deletions
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<CommunityResponse> for Oper<FollowCommunity> {
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))?;