From: Dessalines Date: Mon, 20 Jan 2020 23:39:45 +0000 (-0500) Subject: Allow comment/post upvoting from other pages. X-Git-Url: http://these/git/%7B%60https:/%7B%60css/themes/%22https:/nerdica.net/README.ja.md?a=commitdiff_plain;h=a964b4ce21cc19eb42ae4da1a1aef8bfc0a1df5c;p=lemmy.git Allow comment/post upvoting from other pages. - Fixes #355 - Votes now coming back for posts and comments on search page. --- 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 (
-
+