diff options
author | Dessalines <tyhou13@gmx.com> | 2020-05-03 22:41:45 -0400 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-05-03 22:41:45 -0400 |
commit | b8b2398d32908c982635070ce1ce58eee504dc1d (patch) | |
tree | cff63e37ab00d71bc43e3c998b1345a308af4ff9 /server/src/api/community.rs | |
parent | fab22e3d8a44ecfd4ccb5a8762ea16845b1b4e1b (diff) |
Adding undo follow community.
Diffstat (limited to 'server/src/api/community.rs')
-rw-r--r-- | server/src/api/community.rs | 24 |
1 files changed, 17 insertions, 7 deletions
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<FollowCommunity> { 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<FollowCommunity> { }; } } 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 } |