create view community_moderator_view as
select *,
-(select name from user_ u where cm.user_id = u.id) as user_name
+(select name from user_ u where cm.user_id = u.id) as user_name,
+(select name from community c where cm.community_id = c.id) as community_name
from community_moderator cm;
create view community_follower_view as
select *,
-(select name from user_ u where cf.user_id = u.id) as user_name
+(select name from user_ u where cf.user_id = u.id) as user_name,
+(select name from community c where cf.community_id = c.id) as community_name
from community_follower cf;
}
}
+table! {
+ community_moderator_view (id) {
+ id -> Int4,
+ community_id -> Int4,
+ user_id -> Int4,
+ published -> Timestamp,
+ user_name -> Varchar,
+ community_name -> Varchar,
+ }
+}
+
+table! {
+ community_follower_view (id) {
+ id -> Int4,
+ community_id -> Int4,
+ user_id -> Int4,
+ published -> Timestamp,
+ user_name -> Varchar,
+ community_name -> Varchar,
+ }
+}
+
#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
#[table_name="community_view"]
pub struct CommunityView {
}
}
+
+#[derive(Queryable, Identifiable, PartialEq, Debug, Serialize, Deserialize,QueryableByName,Clone)]
+#[table_name="community_moderator_view"]
+pub struct CommunityModeratorView {
+ pub id: i32,
+ pub community_id: i32,
+ pub user_id: i32,
+ pub published: chrono::NaiveDateTime,
+ pub user_name : String,
+ pub community_name: String,
+}
+
+impl CommunityModeratorView {
+ pub fn for_community(conn: &PgConnection, from_community_id: i32) -> Result<Vec<Self>, Error> {
+ use actions::community_view::community_moderator_view::dsl::*;
+ community_moderator_view.filter(community_id.eq(from_community_id)).load::<Self>(conn)
+ }
+
+ pub fn for_user(conn: &PgConnection, from_user_id: i32) -> Result<Vec<Self>, Error> {
+ use actions::community_view::community_moderator_view::dsl::*;
+ community_moderator_view.filter(user_id.eq(from_user_id)).load::<Self>(conn)
+ }
+}
+
op: String,
post: PostView,
comments: Vec<CommentView>,
- community: CommunityView
+ community: CommunityView,
+ moderators: Vec<CommunityModeratorView>
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize)]
pub struct GetCommunityResponse {
op: String,
- community: CommunityView
+ community: CommunityView,
+ moderators: Vec<CommunityModeratorView>
}
#[derive(Serialize, Deserialize)]
let community = CommunityView::read(&conn, post_view.community_id).unwrap();
+ let moderators = CommunityModeratorView::for_community(&conn, post_view.community_id).unwrap();
+
// Return the jwt
serde_json::to_string(
&GetPostResponse {
op: self.op_type().to_string(),
post: post_view,
comments: comments,
- community: community
+ community: community,
+ moderators: moderators
}
)
.unwrap()
}
};
+
+ let moderators = match CommunityModeratorView::for_community(&conn, self.id) {
+ Ok(moderators) => moderators,
+ Err(_e) => {
+ return self.error("Couldn't find Community");
+ }
+ };
+
// Return the jwt
serde_json::to_string(
&GetCommunityResponse {
op: self.op_type().to_string(),
- community: community_view
+ community: community_view,
+ moderators: moderators
}
)
.unwrap()
render() {
return (
<div class="container-fluid">
+ <h4>Communities</h4>
<div class="table-responsive">
<table class="table table-sm table-hover" data-sortable>
<thead>
import { Link } from 'inferno-router';
import { Subscription } from "rxjs";
import { retryWhen, delay, take } from 'rxjs/operators';
-import { UserOperation, Community as CommunityI, CommunityResponse, Post, GetPostsForm, ListingSortType, ListingType, GetPostsResponse, CreatePostLikeForm, CreatePostLikeResponse} from '../interfaces';
+import { UserOperation, Community as CommunityI, CommunityResponse, Post, GetPostsForm, ListingSortType, ListingType, GetPostsResponse, CreatePostLikeForm, CreatePostLikeResponse, CommunityUser} from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { MomentTime } from './moment-time';
import { PostListing } from './post-listing';
interface State {
community: CommunityI;
+ moderators: Array<CommunityUser>;
posts: Array<Post>;
sortType: ListingSortType;
}
creator_name: null,
number_of_subscribers: null,
number_of_posts: null,
+ number_of_comments: null,
published: null
},
+ moderators: [],
posts: [],
sortType: ListingSortType.Hot,
}
}
</div>
<div class="col-12 col-sm-2 col-lg-3">
- <Sidebar community={this.state.community} />
+ <Sidebar community={this.state.community} moderators={this.state.moderators} />
</div>
</div>
</div>
} else if (op == UserOperation.GetCommunity) {
let res: CommunityResponse = msg;
this.state.community = res.community;
+ this.state.moderators = res.moderators;
this.setState(this.state);
} else if (op == UserOperation.GetPosts) {
let res: GetPostsResponse = msg;
import { Link } from 'inferno-router';
import { Subscription } from "rxjs";
import { retryWhen, delay, take } from 'rxjs/operators';
-import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentLikeForm, CommentSortType, CreatePostLikeResponse } from '../interfaces';
+import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentLikeForm, CommentSortType, CreatePostLikeResponse, CommunityUser } from '../interfaces';
import { WebSocketService, UserService } from '../services';
import { msgOp, hotRank,mdToHtml } from '../utils';
import { MomentTime } from './moment-time';
comments: Array<Comment>;
commentSort: CommentSortType;
community: Community;
+ moderators: Array<CommunityUser>;
}
export class Post extends Component<any, PostState> {
comments: [],
commentSort: CommentSortType.Hot,
community: null,
+ moderators: []
}
constructor(props, context) {
sidebar() {
return (
<div class="sticky-top">
- <Sidebar community={this.state.community} />
+ <Sidebar community={this.state.community} moderators={this.state.moderators} />
</div>
);
}
this.state.post = res.post;
this.state.comments = res.comments;
this.state.community = res.community;
+ this.state.moderators = res.moderators;
this.setState(this.state);
} else if (op == UserOperation.CreateComment) {
let res: CommentResponse = msg;
import { Component, linkEvent } from 'inferno';
-import { Community } from '../interfaces';
+import { Link } from 'inferno-router';
+import { Community, CommunityUser } from '../interfaces';
import { mdToHtml } from '../utils';
interface SidebarProps {
community: Community;
+ moderators: Array<CommunityUser>;
}
interface SidebarState {
<div>
<h4>{community.title}</h4>
<ul class="list-inline">
- <li className="list-inline-item badge badge-light">{community.category_name}</li>
+ <li className="list-inline-item"><Link className="badge badge-light" to="/communities">{community.category_name}</Link></li>
<li className="list-inline-item badge badge-light">{community.number_of_subscribers} Subscribers</li>
<li className="list-inline-item badge badge-light">{community.number_of_posts} Posts</li>
<li className="list-inline-item badge badge-light">{community.number_of_comments} Comments</li>
</ul>
<div><button type="button" class="btn btn-secondary mb-2">Subscribe</button></div>
+ {community.description &&
+ <div>
+ <hr />
+ <div className="md-div" dangerouslySetInnerHTML={mdToHtml(community.description)} />
+ </div>
+ }
<hr />
- {community.description && <div className="md-div" dangerouslySetInnerHTML={mdToHtml(community.description)} />}
+ <h5>Moderators</h5>
+ {this.props.moderators.map(mod =>
+ <Link to={`/user/${mod.user_id}`}>{mod.user_name}</Link>
+ )}
</div>
);
}
username: string;
}
+export interface CommunityUser {
+ id: number;
+ user_id: number;
+ user_name: string;
+ community_id: number;
+ community_name: string;
+ published: string;
+}
+
export interface Community {
id: number;
name: string;
export interface CommunityResponse {
op: string;
community: Community;
+ moderators: Array<CommunityUser>;
}
export interface ListCommunitiesResponse {
post: Post;
comments: Array<Comment>;
community: Community;
+ moderators: Array<CommunityUser>;
}
export interface PostResponse {