comment::Comment,
comment_view::CommentQueryBuilder,
community::*,
- community_view::*,
diesel_option_overwrite,
moderator::*,
naive_now,
post::Post,
site::*,
- user_view::*,
+ views::{
+ community_follower_view::CommunityFollowerView,
+ community_moderator_view::CommunityModeratorView,
+ community_view::{CommunityQueryBuilder, CommunityView},
+ user_view::UserViewSafe,
+ },
ApubObject,
Bannable,
Crud,
.unwrap_or(1);
let res = GetCommunityResponse {
- community: community_view,
+ community_view,
moderators,
online,
};
})
.await??;
- Ok(CommunityResponse {
- community: community_view,
- })
+ Ok(CommunityResponse { community_view })
}
}
let edit_id = data.edit_id;
let mods: Vec<i32> = blocking(context.pool(), move |conn| {
CommunityModeratorView::for_community(conn, edit_id)
- .map(|v| v.into_iter().map(|m| m.user_id).collect())
+ .map(|v| v.into_iter().map(|m| m.moderator.id).collect())
})
.await??;
if !mods.contains(&user.id) {
})
.await??;
- let res = CommunityResponse {
- community: community_view,
- };
+ let res = CommunityResponse { community_view };
send_community_websocket(&res, context, websocket_id, UserOperation::EditCommunity);
})
.await??;
- let res = CommunityResponse {
- community: community_view,
- };
+ let res = CommunityResponse { community_view };
send_community_websocket(&res, context, websocket_id, UserOperation::DeleteCommunity);
})
.await??;
- let res = CommunityResponse {
- community: community_view,
- };
+ let res = CommunityResponse { community_view };
send_community_websocket(&res, context, websocket_id, UserOperation::RemoveCommunity);
let page = data.page;
let limit = data.limit;
let communities = blocking(context.pool(), move |conn| {
- CommunityQueryBuilder::create(conn)
+ CommunityQueryBuilder::create(conn, user_id)
.sort(&sort)
- .for_user(user_id)
.show_nsfw(show_nsfw)
.page(page)
.limit(limit)
// For now, just assume that remote follows are accepted.
// Otherwise, the subscribed will be null
if !community.local {
- community_view.subscribed = Some(data.follow);
+ community_view.subscribed = data.follow;
}
- Ok(CommunityResponse {
- community: community_view,
- })
+ Ok(CommunityResponse { community_view })
}
}
let user_id = data.user_id;
let user_view = blocking(context.pool(), move |conn| {
- UserView::get_user_secure(conn, user_id)
+ UserViewSafe::read(conn, user_id)
})
.await??;
let res = BanFromCommunityResponse {
- user: user_view,
+ user_view,
banned: data.ban,
};
})
.await??;
- let mut admins = blocking(context.pool(), move |conn| UserView::admins(conn)).await??;
+ let mut admins = blocking(context.pool(), move |conn| UserViewSafe::admins(conn)).await??;
let creator_index = admins
.iter()
- .position(|r| r.id == site_creator_id)
+ .position(|r| r.user.id == site_creator_id)
.context(location_info!())?;
let creator_user = admins.remove(creator_index);
admins.insert(0, creator_user);
// Make sure user is the creator, or an admin
- if user.id != read_community.creator_id && !admins.iter().map(|a| a.id).any(|x| x == user.id) {
+ 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());
}
.await??;
let creator_index = community_mods
.iter()
- .position(|r| r.user_id == data.user_id)
+ .position(|r| r.moderator.id == data.user_id)
.context(location_info!())?;
let creator_user = community_mods.remove(creator_index);
community_mods.insert(0, creator_user);
// TODO: this should probably be a bulk operation
for cmod in &community_mods {
let community_moderator_form = CommunityModeratorForm {
- community_id: cmod.community_id,
- user_id: cmod.user_id,
+ community_id: cmod.community.id,
+ user_id: cmod.moderator.id,
};
let join = move |conn: &'_ _| CommunityModerator::join(conn, &community_moderator_form);
// Return the jwt
Ok(GetCommunityResponse {
- community: community_view,
+ community_view,
moderators,
online: 0,
})
websocket_id: Option<ConnectionId>,
op: UserOperation,
) {
+ // TODO is there any way around this?
// Strip out the user id and subscribed when sending to others
- let mut res_sent = res.clone();
- res_sent.community.user_id = None;
- res_sent.community.subscribed = None;
+ // let mut res_sent = res.clone();
+ // res_sent.community_view.user_id = None;
+ // res_sent.community.subscribed = None;
context.chat_server().do_send(SendCommunityRoomMessage {
op,
- response: res_sent,
- community_id: res.community.id,
+ response: res.to_owned(),
+ community_id: res.community_view.community.id,
websocket_id,
});
}