From a964b4ce21cc19eb42ae4da1a1aef8bfc0a1df5c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 20 Jan 2020 18:39:45 -0500 Subject: [PATCH] Allow comment/post upvoting from other pages. - Fixes #355 - Votes now coming back for posts and comments on search page. --- server/src/api/site.rs | 16 +++ ui/src/components/post-listing.tsx | 6 +- ui/src/components/search.tsx | 212 ++++++++++++++++------------ ui/src/components/user.tsx | 17 ++- ui/src/interfaces.ts | 1 + ui/src/services/WebSocketService.ts | 1 + 6 files changed, 154 insertions(+), 99 deletions(-) diff --git a/server/src/api/site.rs b/server/src/api/site.rs index a189a030..ce07724a 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -19,6 +19,7 @@ pub struct Search { sort: String, page: Option, limit: Option, + auth: Option, } #[derive(Serialize, Deserialize)] @@ -313,6 +314,17 @@ impl Perform for Oper { fn perform(&self, conn: &PgConnection) -> Result { let data: &Search = &self.data; + let user_id: Option = match &data.auth { + Some(auth) => match Claims::decode(&auth) { + Ok(claims) => { + let user_id = claims.claims.id; + Some(user_id) + } + Err(_e) => None, + }, + None => None, + }; + let sort = SortType::from_str(&data.sort)?; let type_ = SearchType::from_str(&data.type_)?; @@ -330,6 +342,7 @@ impl Perform for Oper { .show_nsfw(true) .for_community_id(data.community_id) .search_term(data.q.to_owned()) + .my_user_id(user_id) .page(data.page) .limit(data.limit) .list()?; @@ -338,6 +351,7 @@ impl Perform for Oper { comments = CommentQueryBuilder::create(&conn) .sort(&sort) .search_term(data.q.to_owned()) + .my_user_id(user_id) .page(data.page) .limit(data.limit) .list()?; @@ -364,6 +378,7 @@ impl Perform for Oper { .show_nsfw(true) .for_community_id(data.community_id) .search_term(data.q.to_owned()) + .my_user_id(user_id) .page(data.page) .limit(data.limit) .list()?; @@ -371,6 +386,7 @@ impl Perform for Oper { comments = CommentQueryBuilder::create(&conn) .sort(&sort) .search_term(data.q.to_owned()) + .my_user_id(user_id) .page(data.page) .limit(data.limit) .list()?; diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index b1db2670..aab2cea5 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -52,7 +52,6 @@ interface PostListingProps { post: Post; showCommunity?: boolean; showBody?: boolean; - viewOnly?: boolean; moderators?: Array; admins?: Array; } @@ -118,10 +117,7 @@ export class PostListing extends Component { let post = this.props.post; return (
-
+