- Changing to_vec function name.
source::post::Post_,
views::{
comment_view::CommentQueryBuilder,
- community::community_moderator_view::CommunityModeratorView,
+ community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
post_report_view::{PostReportQueryBuilder, PostReportView},
post_view::{PostQueryBuilder, PostView},
},
})
.await??;
+ // Necessary for the sidebar
+ let community_view = match blocking(context.pool(), move |conn| {
+ CommunityView::read(conn, community_id, user_id)
+ })
+ .await?
+ {
+ Ok(community) => community,
+ Err(_e) => return Err(APIError::err("couldnt_find_community").into()),
+ };
+
let online = context
.chat_server()
.send(GetPostUsersOnline { post_id: data.id })
// Return the jwt
Ok(GetPostResponse {
post_view,
+ community_view,
comments,
moderators,
online,
.offset(offset)
.load::<CommentReportViewTuple>(self.conn)?;
- Ok(CommentReportView::to_vec(res))
+ Ok(CommentReportView::from_tuple_to_vec(res))
}
}
impl ViewToVec for CommentReportView {
type DbTuple = CommentReportViewTuple;
- fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
- posts
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
comment_report: a.0.to_owned(),
.offset(offset)
.load::<CommentViewTuple>(self.conn)?;
- Ok(CommentView::to_vec(res))
+ Ok(CommentView::from_tuple_to_vec(res))
}
}
impl ViewToVec for CommentView {
type DbTuple = CommentViewTuple;
- fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
- posts
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
comment: a.0.to_owned(),
.order_by(community_follower::published)
.load::<CommunityFollowerViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
pub fn for_user(conn: &PgConnection, user_id: i32) -> Result<Vec<Self>, Error> {
.order_by(community_follower::published)
.load::<CommunityFollowerViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for CommunityFollowerView {
type DbTuple = CommunityFollowerViewTuple;
- fn to_vec(users: Vec<Self::DbTuple>) -> Vec<Self> {
- users
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
community: a.0.to_owned(),
.order_by(community_moderator::published)
.load::<CommunityModeratorViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
pub fn for_user(conn: &PgConnection, user_id: i32) -> Result<Vec<Self>, Error> {
.order_by(community_moderator::published)
.load::<CommunityModeratorViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for CommunityModeratorView {
type DbTuple = CommunityModeratorViewTuple;
- fn to_vec(community_moderators: Vec<Self::DbTuple>) -> Vec<Self> {
- community_moderators
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
community: a.0.to_owned(),
.filter(community::deleted.eq(false))
.load::<CommunityViewTuple>(self.conn)?;
- Ok(CommunityView::to_vec(res))
+ Ok(CommunityView::from_tuple_to_vec(res))
}
}
impl ViewToVec for CommunityView {
type DbTuple = CommunityViewTuple;
- fn to_vec(communities: Vec<Self::DbTuple>) -> Vec<Self> {
- communities
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
community: a.0.to_owned(),
pub(crate) trait ViewToVec {
type DbTuple;
- fn to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
+ fn from_tuple_to_vec(tuple: Vec<Self::DbTuple>) -> Vec<Self>
where
Self: Sized;
}
.order_by(mod_add_community::when_.desc())
.load::<ModAddCommunityViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModAddCommunityView {
type DbTuple = ModAddCommunityViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_add_community: a.0.to_owned(),
.order_by(mod_add::when_.desc())
.load::<ModAddViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModAddView {
type DbTuple = ModAddViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_add: a.0.to_owned(),
.order_by(mod_ban_from_community::when_.desc())
.load::<ModBanFromCommunityViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModBanFromCommunityView {
type DbTuple = ModBanFromCommunityViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_ban_from_community: a.0.to_owned(),
.order_by(mod_ban::when_.desc())
.load::<ModBanViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModBanView {
type DbTuple = ModBanViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_ban: a.0.to_owned(),
.order_by(mod_lock_post::when_.desc())
.load::<ModLockPostViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModLockPostView {
type DbTuple = ModLockPostViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_lock_post: a.0.to_owned(),
.order_by(mod_remove_comment::when_.desc())
.load::<ModRemoveCommentViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModRemoveCommentView {
type DbTuple = ModRemoveCommentViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_remove_comment: a.0.to_owned(),
.order_by(mod_remove_community::when_.desc())
.load::<ModRemoveCommunityTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModRemoveCommunityView {
type DbTuple = ModRemoveCommunityTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_remove_community: a.0.to_owned(),
.order_by(mod_remove_post::when_.desc())
.load::<ModRemovePostViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModRemovePostView {
type DbTuple = ModRemovePostViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_remove_post: a.0.to_owned(),
.order_by(mod_sticky_post::when_.desc())
.load::<ModStickyPostViewTuple>(conn)?;
- Ok(Self::to_vec(res))
+ Ok(Self::from_tuple_to_vec(res))
}
}
impl ViewToVec for ModStickyPostView {
type DbTuple = ModStickyPostViewTuple;
- fn to_vec(mrp: Vec<Self::DbTuple>) -> Vec<Self> {
- mrp
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
mod_sticky_post: a.0.to_owned(),
.offset(offset)
.load::<PostReportViewTuple>(self.conn)?;
- Ok(PostReportView::to_vec(res))
+ Ok(PostReportView::from_tuple_to_vec(res))
}
}
impl ViewToVec for PostReportView {
type DbTuple = PostReportViewTuple;
- fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
- posts
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
post_report: a.0.to_owned(),
.filter(community::deleted.eq(false))
.load::<PostViewTuple>(self.conn)?;
- Ok(PostView::to_vec(res))
+ Ok(PostView::from_tuple_to_vec(res))
}
}
impl ViewToVec for PostView {
type DbTuple = PostViewTuple;
- fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
- posts
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
post: a.0.to_owned(),
.order_by(private_message::published.desc())
.load::<PrivateMessageViewTuple>(self.conn)?;
- Ok(PrivateMessageView::to_vec(res))
+ Ok(PrivateMessageView::from_tuple_to_vec(res))
}
}
impl ViewToVec for PrivateMessageView {
type DbTuple = PrivateMessageViewTuple;
- fn to_vec(pm: Vec<Self::DbTuple>) -> Vec<Self> {
- pm.iter()
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
+ .iter()
.map(|a| Self {
private_message: a.0.to_owned(),
creator: a.1.to_owned(),
.offset(offset)
.load::<UserMentionViewTuple>(self.conn)?;
- Ok(UserMentionView::to_vec(res))
+ Ok(UserMentionView::from_tuple_to_vec(res))
}
}
impl ViewToVec for UserMentionView {
type DbTuple = UserMentionViewTuple;
- fn to_vec(posts: Vec<Self::DbTuple>) -> Vec<Self> {
- posts
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
user_mention: a.0.to_owned(),
.order_by(user_::published)
.load::<UserViewSafeTuple>(conn)?;
- Ok(Self::to_vec(admins))
+ Ok(Self::from_tuple_to_vec(admins))
}
pub fn banned(conn: &PgConnection) -> Result<Vec<Self>, Error> {
.filter(user_::banned.eq(true))
.load::<UserViewSafeTuple>(conn)?;
- Ok(Self::to_vec(banned))
+ Ok(Self::from_tuple_to_vec(banned))
}
}
let res = query.load::<UserViewSafeTuple>(self.conn)?;
- Ok(UserViewSafe::to_vec(res))
+ Ok(UserViewSafe::from_tuple_to_vec(res))
}
}
impl ViewToVec for UserViewSafe {
type DbTuple = UserViewSafeTuple;
- fn to_vec(users: Vec<Self::DbTuple>) -> Vec<Self> {
- users
+ fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
+ items
.iter()
.map(|a| Self {
user: a.0.to_owned(),
use lemmy_db::views::{
comment_view::CommentView,
- community::community_moderator_view::CommunityModeratorView,
+ community::{community_moderator_view::CommunityModeratorView, community_view::CommunityView},
post_report_view::PostReportView,
post_view::PostView,
};
#[derive(Serialize)]
pub struct GetPostResponse {
pub post_view: PostView,
+ pub community_view: CommunityView,
pub comments: Vec<CommentView>,
pub moderators: Vec<CommunityModeratorView>,
pub online: usize,