- // Verify that only mods or admins can add mod
- is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
- let community = Community::read(&mut context.pool(), community_id).await?;
- if local_user_view.person.admin && !community.local {
- return Err(LemmyErrorType::NotAModerator)?;
- }
+ // Update in local database
+ let community_moderator_form = CommunityModeratorForm {
+ community_id: data.community_id,
+ person_id: data.person_id,
+ };
+ if data.added {
+ CommunityModerator::join(&mut context.pool(), &community_moderator_form)
+ .await
+ .with_lemmy_type(LemmyErrorType::CommunityModeratorAlreadyExists)?;
+ } else {
+ CommunityModerator::leave(&mut context.pool(), &community_moderator_form)
+ .await
+ .with_lemmy_type(LemmyErrorType::CommunityModeratorAlreadyExists)?;
+ }