From b8b2398d32908c982635070ce1ce58eee504dc1d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 3 May 2020 22:41:45 -0400 Subject: Adding undo follow community. --- server/src/api/community.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'server/src/api/community.rs') diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 9659469b..9855b788 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -483,12 +483,12 @@ impl Perform for Oper { let conn = pool.get()?; let community = Community::read(&conn, data.community_id)?; - if community.local { - let community_follower_form = CommunityFollowerForm { - community_id: data.community_id, - user_id, - }; + let community_follower_form = CommunityFollowerForm { + community_id: data.community_id, + user_id, + }; + if community.local { if data.follow { match CommunityFollower::follow(&conn, &community_follower_form) { Ok(user) => user, @@ -501,9 +501,19 @@ impl Perform for Oper { }; } } else { - // TODO: still have to implement unfollow let user = User_::read(&conn, user_id)?; - user.send_follow(&community.actor_id, &conn)?; + + if data.follow { + // Dont actually add to the community followers here, because you need + // to wait for the accept + user.send_follow(&community.actor_id, &conn)?; + } else { + user.send_unfollow(&community.actor_id, &conn)?; + match CommunityFollower::ignore(&conn, &community_follower_form) { + Ok(user) => user, + Err(_e) => return Err(APIError::err("community_follower_already_exists").into()), + }; + } // TODO: this needs to return a "pending" state, until Accept is received from the remote server } -- cgit v1.2.3