diff --git a/server/migrations/2019-04-29-175834_add_delete_columns/down.sql b/server/migrations/2019-04-29-175834_add_delete_columns/down.sql new file mode 100644 index 000000000..5e13295b2 --- /dev/null +++ b/server/migrations/2019-04-29-175834_add_delete_columns/down.sql @@ -0,0 +1,137 @@ +drop view reply_view; +drop view comment_view; +drop view community_view; +drop view post_view; +alter table community drop column deleted; +alter table post drop column deleted; +alter table comment drop column deleted; + +create view community_view as +with all_community as +( + select *, + (select name from user_ u where c.creator_id = u.id) as creator_name, + (select name from category ct where c.category_id = ct.id) as category_name, + (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers, + (select count(*) from post p where p.community_id = c.id) as number_of_posts, + (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments + from community c +) + +select +ac.*, +u.id as user_id, +(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed +from user_ u +cross join all_community ac + +union all + +select +ac.*, +null as user_id, +null as subscribed +from all_community ac +; + +create or replace view post_view as +with all_post as +( + select + p.*, + (select name from user_ where p.creator_id = user_.id) as creator_name, + (select name from community where p.community_id = community.id) as community_name, + (select removed from community c where p.community_id = c.id) as community_removed, + (select count(*) from comment where comment.post_id = p.id) as number_of_comments, + coalesce(sum(pl.score), 0) as score, + count (case when pl.score = 1 then 1 else null end) as upvotes, + count (case when pl.score = -1 then 1 else null end) as downvotes, + hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank + from post p + left join post_like pl on p.id = pl.post_id + group by p.id +) + +select +ap.*, +u.id as user_id, +coalesce(pl.score, 0) as my_vote, +(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed, +(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read, +(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved +from user_ u +cross join all_post ap +left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id + +union all + +select +ap.*, +null as user_id, +null as my_vote, +null as subscribed, +null as read, +null as saved +from all_post ap +; + +create view comment_view as +with all_comment as +( + select + c.*, + (select community_id from post p where p.id = c.post_id), + (select u.banned from user_ u where c.creator_id = u.id) as banned, + (select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community, + (select name from user_ where c.creator_id = user_.id) as creator_name, + coalesce(sum(cl.score), 0) as score, + count (case when cl.score = 1 then 1 else null end) as upvotes, + count (case when cl.score = -1 then 1 else null end) as downvotes + from comment c + left join comment_like cl on c.id = cl.comment_id + group by c.id +) + +select +ac.*, +u.id as user_id, +coalesce(cl.score, 0) as my_vote, +(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved +from user_ u +cross join all_comment ac +left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id + +union all + +select + ac.*, + null as user_id, + null as my_vote, + null as saved +from all_comment ac +; + +create view reply_view as +with closereply as ( + select + c2.id, + c2.creator_id as sender_id, + c.creator_id as recipient_id + from comment c + inner join comment c2 on c.id = c2.parent_id + where c2.creator_id != c.creator_id + -- Do union where post is null + union + select + c.id, + c.creator_id as sender_id, + p.creator_id as recipient_id + from comment c, post p + where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id +) +select cv.*, +closereply.recipient_id +from comment_view cv, closereply +where closereply.id = cv.id +; + diff --git a/server/migrations/2019-04-29-175834_add_delete_columns/up.sql b/server/migrations/2019-04-29-175834_add_delete_columns/up.sql new file mode 100644 index 000000000..88432dda4 --- /dev/null +++ b/server/migrations/2019-04-29-175834_add_delete_columns/up.sql @@ -0,0 +1,141 @@ +alter table community add column deleted boolean default false not null; +alter table post add column deleted boolean default false not null; +alter table comment add column deleted boolean default false not null; + +-- The views +drop view community_view; + +create view community_view as +with all_community as +( + select *, + (select name from user_ u where c.creator_id = u.id) as creator_name, + (select name from category ct where c.category_id = ct.id) as category_name, + (select count(*) from community_follower cf where cf.community_id = c.id) as number_of_subscribers, + (select count(*) from post p where p.community_id = c.id) as number_of_posts, + (select count(*) from comment co, post p where c.id = p.community_id and p.id = co.post_id) as number_of_comments + from community c +) + +select +ac.*, +u.id as user_id, +(select cf.id::boolean from community_follower cf where u.id = cf.user_id and ac.id = cf.community_id) as subscribed +from user_ u +cross join all_community ac + +union all + +select +ac.*, +null as user_id, +null as subscribed +from all_community ac +; + + +drop view post_view; +create view post_view as +with all_post as +( + select + p.*, + (select name from user_ where p.creator_id = user_.id) as creator_name, + (select name from community where p.community_id = community.id) as community_name, + (select removed from community c where p.community_id = c.id) as community_removed, + (select deleted from community c where p.community_id = c.id) as community_deleted, + (select count(*) from comment where comment.post_id = p.id) as number_of_comments, + coalesce(sum(pl.score), 0) as score, + count (case when pl.score = 1 then 1 else null end) as upvotes, + count (case when pl.score = -1 then 1 else null end) as downvotes, + hot_rank(coalesce(sum(pl.score) , 0), p.published) as hot_rank + from post p + left join post_like pl on p.id = pl.post_id + group by p.id +) + +select +ap.*, +u.id as user_id, +coalesce(pl.score, 0) as my_vote, +(select cf.id::bool from community_follower cf where u.id = cf.user_id and cf.community_id = ap.community_id) as subscribed, +(select pr.id::bool from post_read pr where u.id = pr.user_id and pr.post_id = ap.id) as read, +(select ps.id::bool from post_saved ps where u.id = ps.user_id and ps.post_id = ap.id) as saved +from user_ u +cross join all_post ap +left join post_like pl on u.id = pl.user_id and ap.id = pl.post_id + +union all + +select +ap.*, +null as user_id, +null as my_vote, +null as subscribed, +null as read, +null as saved +from all_post ap +; + +drop view reply_view; +drop view comment_view; +create view comment_view as +with all_comment as +( + select + c.*, + (select community_id from post p where p.id = c.post_id), + (select u.banned from user_ u where c.creator_id = u.id) as banned, + (select cb.id::bool from community_user_ban cb, post p where c.creator_id = cb.user_id and p.id = c.post_id and p.community_id = cb.community_id) as banned_from_community, + (select name from user_ where c.creator_id = user_.id) as creator_name, + coalesce(sum(cl.score), 0) as score, + count (case when cl.score = 1 then 1 else null end) as upvotes, + count (case when cl.score = -1 then 1 else null end) as downvotes + from comment c + left join comment_like cl on c.id = cl.comment_id + group by c.id +) + +select +ac.*, +u.id as user_id, +coalesce(cl.score, 0) as my_vote, +(select cs.id::bool from comment_saved cs where u.id = cs.user_id and cs.comment_id = ac.id) as saved +from user_ u +cross join all_comment ac +left join comment_like cl on u.id = cl.user_id and ac.id = cl.comment_id + +union all + +select + ac.*, + null as user_id, + null as my_vote, + null as saved +from all_comment ac +; + +create view reply_view as +with closereply as ( + select + c2.id, + c2.creator_id as sender_id, + c.creator_id as recipient_id + from comment c + inner join comment c2 on c.id = c2.parent_id + where c2.creator_id != c.creator_id + -- Do union where post is null + union + select + c.id, + c.creator_id as sender_id, + p.creator_id as recipient_id + from comment c, post p + where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id +) +select cv.*, +closereply.recipient_id +from comment_view cv, closereply +where closereply.id = cv.id +; + diff --git a/server/src/actions/comment.rs b/server/src/actions/comment.rs index 9bb6d018f..4bbc7c04d 100644 --- a/server/src/actions/comment.rs +++ b/server/src/actions/comment.rs @@ -25,7 +25,8 @@ pub struct Comment { pub removed: bool, pub read: bool, pub published: chrono::NaiveDateTime, - pub updated: Option + pub updated: Option, + pub deleted: bool, } #[derive(Insertable, AsChangeset, Clone)] @@ -37,7 +38,8 @@ pub struct CommentForm { pub content: String, pub removed: Option, pub read: Option, - pub updated: Option + pub updated: Option, + pub deleted: Option, } impl Crud for Comment { @@ -186,6 +188,7 @@ mod tests { category_id: 1, creator_id: inserted_user.id, removed: None, + deleted: None, updated: None }; @@ -198,6 +201,7 @@ mod tests { body: None, community_id: inserted_community.id, removed: None, + deleted: None, locked: None, updated: None }; @@ -209,6 +213,7 @@ mod tests { creator_id: inserted_user.id, post_id: inserted_post.id, removed: None, + deleted: None, read: None, parent_id: None, updated: None @@ -222,6 +227,7 @@ mod tests { creator_id: inserted_user.id, post_id: inserted_post.id, removed: false, + deleted: false, read: false, parent_id: None, published: inserted_comment.published, @@ -234,6 +240,7 @@ mod tests { post_id: inserted_post.id, parent_id: Some(inserted_comment.id), removed: None, + deleted: None, read: None, updated: None }; diff --git a/server/src/actions/comment_view.rs b/server/src/actions/comment_view.rs index 85ddf5871..eb6276cc2 100644 --- a/server/src/actions/comment_view.rs +++ b/server/src/actions/comment_view.rs @@ -17,6 +17,7 @@ table! { read -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, community_id -> Int4, banned -> Bool, banned_from_community -> Bool, @@ -42,6 +43,7 @@ pub struct CommentView { pub read: bool, pub published: chrono::NaiveDateTime, pub updated: Option, + pub deleted: bool, pub community_id: i32, pub banned: bool, pub banned_from_community: bool, @@ -115,6 +117,7 @@ impl CommentView { _ => query.order_by(published.desc()) }; + // Note: deleted and removed comments are done on the front side query .limit(limit) .offset(offset) @@ -153,6 +156,7 @@ table! { read -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, community_id -> Int4, banned -> Bool, banned_from_community -> Bool, @@ -179,6 +183,7 @@ pub struct ReplyView { pub read: bool, pub published: chrono::NaiveDateTime, pub updated: Option, + pub deleted: bool, pub community_id: i32, pub banned: bool, pub banned_from_community: bool, @@ -275,6 +280,7 @@ mod tests { category_id: 1, creator_id: inserted_user.id, removed: None, + deleted: None, updated: None }; @@ -287,6 +293,7 @@ mod tests { body: None, community_id: inserted_community.id, removed: None, + deleted: None, locked: None, updated: None }; @@ -299,6 +306,7 @@ mod tests { post_id: inserted_post.id, parent_id: None, removed: None, + deleted: None, read: None, updated: None }; @@ -322,6 +330,7 @@ mod tests { community_id: inserted_community.id, parent_id: None, removed: false, + deleted: false, read: false, banned: false, banned_from_community: false, @@ -344,6 +353,7 @@ mod tests { community_id: inserted_community.id, parent_id: None, removed: false, + deleted: false, read: false, banned: false, banned_from_community: false, diff --git a/server/src/actions/community.rs b/server/src/actions/community.rs index 42c95c7d7..db53ceb97 100644 --- a/server/src/actions/community.rs +++ b/server/src/actions/community.rs @@ -16,7 +16,8 @@ pub struct Community { pub creator_id: i32, pub removed: bool, pub published: chrono::NaiveDateTime, - pub updated: Option + pub updated: Option, + pub deleted: bool, } #[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)] @@ -28,7 +29,8 @@ pub struct CommunityForm { pub category_id: i32, pub creator_id: i32, pub removed: Option, - pub updated: Option + pub updated: Option, + pub deleted: Option, } impl Crud for Community { @@ -245,6 +247,7 @@ mod tests { description: None, category_id: 1, removed: None, + deleted: None, updated: None, }; @@ -258,6 +261,7 @@ mod tests { description: None, category_id: 1, removed: false, + deleted: false, published: inserted_community.published, updated: None }; diff --git a/server/src/actions/community_view.rs b/server/src/actions/community_view.rs index 8966ee15a..a52897ff6 100644 --- a/server/src/actions/community_view.rs +++ b/server/src/actions/community_view.rs @@ -15,6 +15,7 @@ table! { removed -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, creator_name -> Varchar, category_name -> Varchar, number_of_subscribers -> BigInt, @@ -85,6 +86,7 @@ pub struct CommunityView { pub removed: bool, pub published: chrono::NaiveDateTime, pub updated: Option, + pub deleted: bool, pub creator_name: String, pub category_name: String, pub number_of_subscribers: i64, @@ -139,6 +141,7 @@ impl CommunityView { .limit(limit) .offset(offset) .filter(removed.eq(false)) + .filter(deleted.eq(false)) .load::(conn) } } diff --git a/server/src/actions/moderator.rs b/server/src/actions/moderator.rs index a0d7db6c8..794d91e74 100644 --- a/server/src/actions/moderator.rs +++ b/server/src/actions/moderator.rs @@ -442,6 +442,7 @@ mod tests { category_id: 1, creator_id: inserted_user.id, removed: None, + deleted: None, updated: None }; @@ -454,6 +455,7 @@ mod tests { creator_id: inserted_user.id, community_id: inserted_community.id, removed: None, + deleted: None, locked: None, updated: None }; @@ -465,6 +467,7 @@ mod tests { creator_id: inserted_user.id, post_id: inserted_post.id, removed: None, + deleted: None, read: None, parent_id: None, updated: None diff --git a/server/src/actions/post.rs b/server/src/actions/post.rs index 4dd4561d9..495a8b09e 100644 --- a/server/src/actions/post.rs +++ b/server/src/actions/post.rs @@ -17,7 +17,8 @@ pub struct Post { pub removed: bool, pub locked: bool, pub published: chrono::NaiveDateTime, - pub updated: Option + pub updated: Option, + pub deleted: bool, } #[derive(Insertable, AsChangeset, Clone)] @@ -30,7 +31,8 @@ pub struct PostForm { pub community_id: i32, pub removed: Option, pub locked: Option, - pub updated: Option + pub updated: Option, + pub deleted: Option, } impl Crud for Post { @@ -199,6 +201,7 @@ mod tests { category_id: 1, creator_id: inserted_user.id, removed: None, + deleted: None, updated: None }; @@ -211,6 +214,7 @@ mod tests { creator_id: inserted_user.id, community_id: inserted_community.id, removed: None, + deleted: None, locked: None, updated: None }; @@ -227,6 +231,7 @@ mod tests { published: inserted_post.published, removed: false, locked: false, + deleted: false, updated: None }; diff --git a/server/src/actions/post_view.rs b/server/src/actions/post_view.rs index e24b0ed21..18287651d 100644 --- a/server/src/actions/post_view.rs +++ b/server/src/actions/post_view.rs @@ -23,9 +23,11 @@ table! { locked -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, creator_name -> Varchar, community_name -> Varchar, community_removed -> Bool, + community_deleted -> Bool, number_of_comments -> BigInt, score -> BigInt, upvotes -> BigInt, @@ -53,9 +55,11 @@ pub struct PostView { pub locked: bool, pub published: chrono::NaiveDateTime, pub updated: Option, + pub deleted: bool, pub creator_name: String, pub community_name: String, pub community_removed: bool, + pub community_deleted: bool, pub number_of_comments: i64, pub score: i64, pub upvotes: i64, @@ -144,7 +148,9 @@ impl PostView { .limit(limit) .offset(offset) .filter(removed.eq(false)) - .filter(community_removed.eq(false)); + .filter(deleted.eq(false)) + .filter(community_removed.eq(false)) + .filter(community_deleted.eq(false)); query.load::(conn) } @@ -206,6 +212,7 @@ mod tests { creator_id: inserted_user.id, category_id: 1, removed: None, + deleted: None, updated: None }; @@ -218,6 +225,7 @@ mod tests { creator_id: inserted_user.id, community_id: inserted_community.id, removed: None, + deleted: None, locked: None, updated: None }; @@ -258,9 +266,11 @@ mod tests { creator_name: user_name.to_owned(), community_id: inserted_community.id, removed: false, + deleted: false, locked: false, community_name: community_name.to_owned(), community_removed: false, + community_deleted: false, number_of_comments: 0, score: 1, upvotes: 1, @@ -281,12 +291,14 @@ mod tests { url: None, body: None, removed: false, + deleted: false, locked: false, creator_id: inserted_user.id, creator_name: user_name.to_owned(), community_id: inserted_community.id, community_name: community_name.to_owned(), community_removed: false, + community_deleted: false, number_of_comments: 0, score: 1, upvotes: 1, diff --git a/server/src/schema.rs b/server/src/schema.rs index 65c2ae552..27bc3f941 100644 --- a/server/src/schema.rs +++ b/server/src/schema.rs @@ -16,6 +16,7 @@ table! { read -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, } } @@ -50,6 +51,7 @@ table! { removed -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, } } @@ -182,6 +184,7 @@ table! { locked -> Bool, published -> Timestamp, updated -> Nullable, + deleted -> Bool, } } diff --git a/server/src/websocket_server/server.rs b/server/src/websocket_server/server.rs index 3e361f691..fb551cb31 100644 --- a/server/src/websocket_server/server.rs +++ b/server/src/websocket_server/server.rs @@ -219,6 +219,7 @@ pub struct EditComment { creator_id: i32, post_id: i32, removed: Option, + deleted: Option, reason: Option, read: Option, auth: String @@ -268,6 +269,7 @@ pub struct EditPost { url: Option, body: Option, removed: Option, + deleted: Option, locked: Option, reason: Option, auth: String @@ -288,6 +290,7 @@ pub struct EditCommunity { description: Option, category_id: i32, removed: Option, + deleted: Option, reason: Option, expires: Option, auth: String @@ -912,6 +915,7 @@ impl Perform for CreateCommunity { category_id: self.category_id, creator_id: user_id, removed: None, + deleted: None, updated: None, }; @@ -1060,6 +1064,7 @@ impl Perform for CreatePost { community_id: self.community_id, creator_id: user_id, removed: None, + deleted: None, locked: None, updated: None }; @@ -1264,6 +1269,7 @@ impl Perform for CreateComment { post_id: self.post_id, creator_id: user_id, removed: None, + deleted: None, read: None, updated: None }; @@ -1380,6 +1386,7 @@ impl Perform for EditComment { post_id: self.post_id, creator_id: self.creator_id, removed: self.removed.to_owned(), + deleted: self.deleted.to_owned(), read: self.read.to_owned(), updated: if self.read.is_some() { orig_comment.updated } else {Some(naive_now())} }; @@ -1743,6 +1750,7 @@ impl Perform for EditPost { creator_id: self.creator_id.to_owned(), community_id: self.community_id, removed: self.removed.to_owned(), + deleted: self.deleted.to_owned(), locked: self.locked.to_owned(), updated: Some(naive_now()) }; @@ -1908,6 +1916,7 @@ impl Perform for EditCommunity { category_id: self.category_id.to_owned(), creator_id: user_id, removed: self.removed.to_owned(), + deleted: self.deleted.to_owned(), updated: Some(naive_now()) }; @@ -2747,6 +2756,7 @@ impl Perform for MarkAllAsRead { post_id: reply.to_owned().post_id, creator_id: reply.to_owned().creator_id, removed: None, + deleted: None, read: Some(true), updated: reply.to_owned().updated }; diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index 0c0fd8214..92eda3add 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -92,7 +92,7 @@ export class CommentNode extends Component { {this.state.showEdit && } {!this.state.showEdit &&
-
+
    {UserService.Instance.user && !this.props.viewOnly && <> @@ -108,7 +108,9 @@ export class CommentNode extends Component { edit
  • - delete + + {!this.props.node.comment.deleted ? 'delete' : 'restore'} +
  • } @@ -252,11 +254,12 @@ export class CommentNode extends Component { handleDeleteClick(i: CommentNode) { let deleteForm: CommentFormI = { - content: '*deleted*', + content: i.props.node.comment.content, edit_id: i.props.node.comment.id, creator_id: i.props.node.comment.creator_id, post_id: i.props.node.comment.post_id, parent_id: i.props.node.comment.parent_id, + deleted: !i.props.node.comment.deleted, auth: null }; WebSocketService.Instance.editComment(deleteForm); diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index f4ef2ecdc..48a9d3664 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -178,6 +178,7 @@ export class Inbox extends Component { found.content = res.comment.content; found.updated = res.comment.updated; found.removed = res.comment.removed; + found.deleted = res.comment.deleted; found.upvotes = res.comment.upvotes; found.downvotes = res.comment.downvotes; found.score = res.comment.score; diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index 91d6fd2f5..87dac92c8 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -85,6 +85,9 @@ export class PostListing extends Component { {post.removed && removed } + {post.deleted && + deleted + } {post.locked && locked } @@ -140,7 +143,7 @@ export class PostListing extends Component { {UserService.Instance.user && this.props.editable &&
    • - {this.props.post.saved ? 'unsave' : 'save'} + {post.saved ? 'unsave' : 'save'}
    • {this.myPost && <> @@ -148,7 +151,9 @@ export class PostListing extends Component { edit
    • - delete + + {!post.deleted ? 'delete' : 'restore'} +
    • } @@ -237,12 +242,13 @@ export class PostListing extends Component { handleDeleteClick(i: PostListing) { let deleteForm: PostFormI = { - body: '', + body: i.props.post.body, community_id: i.props.post.community_id, - name: "deleted", - url: '', + name: i.props.post.name, + url: i.props.post.url, edit_id: i.props.post.id, creator_id: i.props.post.creator_id, + deleted: !i.props.post.deleted, auth: null }; WebSocketService.Instance.editPost(deleteForm); diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 5483338c5..5b0a606c3 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -244,6 +244,7 @@ export class Post extends Component { found.content = res.comment.content; found.updated = res.comment.updated; found.removed = res.comment.removed; + found.deleted = res.comment.deleted; found.upvotes = res.comment.upvotes; found.downvotes = res.comment.downvotes; found.score = res.comment.score; diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index a897d3d23..d14ad68cc 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -56,6 +56,9 @@ export class Sidebar extends Component { {community.removed && removed } + {community.deleted && + deleted + } /c/{community.name}
        @@ -66,7 +69,9 @@ export class Sidebar extends Component { {this.amCreator &&
      • - {/* delete */} + + {!community.deleted ? 'delete' : 'restore'} +
      • } @@ -142,9 +147,18 @@ export class Sidebar extends Component { this.setState(this.state); } - // TODO no deleting communities yet - // handleDeleteClick(i: Sidebar, event) { - // } + handleDeleteClick(i: Sidebar) { + event.preventDefault(); + let deleteForm: CommunityFormI = { + name: i.props.community.name, + title: i.props.community.title, + category_id: i.props.community.category_id, + edit_id: i.props.community.id, + deleted: !i.props.community.deleted, + auth: null, + }; + WebSocketService.Instance.editCommunity(deleteForm); + } handleUnsubscribe(communityId: number) { let form: FollowCommunityForm = { @@ -174,9 +188,6 @@ export class Sidebar extends Component { return UserService.Instance.user && this.props.admins.map(a => a.id).includes(UserService.Instance.user.id); } - handleDeleteClick() { - } - handleModRemoveShow(i: Sidebar) { i.state.showRemoveDialog = true; i.setState(i.state); diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index bd883c32d..b55bf41cd 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -350,6 +350,7 @@ export class User extends Component { found.content = res.comment.content; found.updated = res.comment.updated; found.removed = res.comment.removed; + found.deleted = res.comment.deleted; found.upvotes = res.comment.upvotes; found.downvotes = res.comment.downvotes; found.score = res.comment.score; diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 8a16de432..1558f7ae7 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -52,6 +52,7 @@ export interface Community { category_id: number; creator_id: number; removed: boolean; + deleted: boolean; published: string; updated?: string; creator_name: string; @@ -71,6 +72,7 @@ export interface Post { creator_id: number; community_id: number; removed: boolean; + deleted: boolean; locked: boolean; published: string; updated?: string; @@ -96,6 +98,7 @@ export interface Comment { parent_id?: number; content: string; removed: boolean; + deleted: boolean; read: boolean; published: string; updated?: string; @@ -348,6 +351,7 @@ export interface CommunityForm { category_id: number, edit_id?: number; removed?: boolean; + deleted?: boolean; reason?: string; expires?: number; auth?: string; @@ -392,6 +396,7 @@ export interface PostForm { edit_id?: number; creator_id: number; removed?: boolean; + deleted?: boolean; locked?: boolean; reason?: string; auth: string; @@ -424,6 +429,7 @@ export interface CommentForm { edit_id?: number; creator_id: number; removed?: boolean; + deleted?: boolean; reason?: string; read?: boolean; auth: string;