apub::generate_actor_keypair,
location_info,
utils::{check_slurs, check_slurs_opt, is_valid_community_name, naive_from_unix},
- APIError,
+ ApiError,
ConnectionId,
LemmyError,
};
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_community").into()),
}
.id
}
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_community").into()),
};
let moderators: Vec<CommunityModeratorView> = match blocking(context.pool(), move |conn| {
.await?
{
Ok(moderators) => moderators,
- Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_community").into()),
};
let online = context
check_slurs_opt(&data.description)?;
if !is_valid_community_name(&data.name) {
- return Err(APIError::err("invalid_community_name").into());
+ return Err(ApiError::err("invalid_community_name").into());
}
// Double check for duplicate community actor_ids
})
.await?;
if community_dupe.is_ok() {
- return Err(APIError::err("community_already_exists").into());
+ return Err(ApiError::err("community_already_exists").into());
}
// Check to make sure the icon and banners are urls
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("community_already_exists").into()),
+ Err(_e) => return Err(ApiError::err("community_already_exists").into()),
};
// The community creator becomes a moderator
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
if blocking(context.pool(), join).await?.is_err() {
- return Err(APIError::err("community_moderator_already_exists").into());
+ return Err(ApiError::err("community_moderator_already_exists").into());
}
// Follow your own community
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
if blocking(context.pool(), follow).await?.is_err() {
- return Err(APIError::err("community_follower_already_exists").into());
+ return Err(ApiError::err("community_follower_already_exists").into());
}
let user_id = user.id;
})
.await??;
if !mods.contains(&user.id) {
- return Err(APIError::err("not_a_moderator").into());
+ return Err(ApiError::err("not_a_moderator").into());
}
let community_id = data.community_id;
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_update_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_community").into()),
};
// TODO there needs to be some kind of an apub update
})
.await??;
if read_community.creator_id != user.id {
- return Err(APIError::err("no_community_edit_allowed").into());
+ return Err(ApiError::err("no_community_edit_allowed").into());
}
// Do the delete
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_update_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_community").into()),
};
// Send apub messages
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_update_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_update_community").into()),
};
// Mod tables
let follow = move |conn: &'_ _| CommunityFollower::follow(conn, &community_follower_form);
if blocking(context.pool(), follow).await?.is_err() {
- return Err(APIError::err("community_follower_already_exists").into());
+ return Err(ApiError::err("community_follower_already_exists").into());
}
} else {
let unfollow =
move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
if blocking(context.pool(), unfollow).await?.is_err() {
- return Err(APIError::err("community_follower_already_exists").into());
+ return Err(ApiError::err("community_follower_already_exists").into());
}
}
} else if data.follow {
user.send_unfollow(&community.actor_id(), context).await?;
let unfollow = move |conn: &'_ _| CommunityFollower::unfollow(conn, &community_follower_form);
if blocking(context.pool(), unfollow).await?.is_err() {
- return Err(APIError::err("community_follower_already_exists").into());
+ return Err(ApiError::err("community_follower_already_exists").into());
}
}
.await?
{
Ok(communities) => communities,
- _ => return Err(APIError::err("system_err_login").into()),
+ _ => return Err(ApiError::err("system_err_login").into()),
};
// Return the jwt
if data.ban {
let ban = move |conn: &'_ _| CommunityUserBan::ban(conn, &community_user_ban_form);
if blocking(context.pool(), ban).await?.is_err() {
- return Err(APIError::err("community_user_already_banned").into());
+ return Err(ApiError::err("community_user_already_banned").into());
}
// Also unsubscribe them from the community, if they are subscribed
} else {
let unban = move |conn: &'_ _| CommunityUserBan::unban(conn, &community_user_ban_form);
if blocking(context.pool(), unban).await?.is_err() {
- return Err(APIError::err("community_user_already_banned").into());
+ return Err(ApiError::err("community_user_already_banned").into());
}
}
if data.added {
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
if blocking(context.pool(), join).await?.is_err() {
- return Err(APIError::err("community_moderator_already_exists").into());
+ return Err(ApiError::err("community_moderator_already_exists").into());
}
} else {
let leave = move |conn: &'_ _| CommunityModerator::leave(conn, &community_moderator_form);
if blocking(context.pool(), leave).await?.is_err() {
- return Err(APIError::err("community_moderator_already_exists").into());
+ return Err(ApiError::err("community_moderator_already_exists").into());
}
}
if user.id != read_community.creator_id
&& !admins.iter().map(|a| a.user.id).any(|x| x == user.id)
{
- return Err(APIError::err("not_an_admin").into());
+ return Err(ApiError::err("not_an_admin").into());
}
let community_id = data.community_id;
let new_creator = data.user_id;
let update = move |conn: &'_ _| Community::update_creator(conn, community_id, new_creator);
if blocking(context.pool(), update).await?.is_err() {
- return Err(APIError::err("couldnt_update_community").into());
+ return Err(ApiError::err("couldnt_update_community").into());
};
// You also have to re-do the community_moderator table, reordering it.
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
if blocking(context.pool(), join).await?.is_err() {
- return Err(APIError::err("community_moderator_already_exists").into());
+ return Err(ApiError::err("community_moderator_already_exists").into());
}
}
.await?
{
Ok(community) => community,
- Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_community").into()),
};
let community_id = data.community_id;
.await?
{
Ok(moderators) => moderators,
- Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ Err(_e) => return Err(ApiError::err("couldnt_find_community").into()),
};
// Return the jwt