diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 35363a17..c5985f46 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -254,6 +254,7 @@ impl Perform for Oper { data.community_id, None, None, + None, user_id, show_nsfw, false, diff --git a/server/src/api/site.rs b/server/src/api/site.rs index 8f094aac..c98539be 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -23,6 +23,7 @@ pub struct Search { #[derive(Serialize, Deserialize)] pub struct SearchResponse { op: String, + type_: String, comments: Vec, posts: Vec, communities: Vec, @@ -288,6 +289,7 @@ impl Perform for Oper { data.community_id, None, Some(data.q.to_owned()), + None, None, true, false, @@ -333,6 +335,7 @@ impl Perform for Oper { data.community_id, None, Some(data.q.to_owned()), + None, None, true, false, @@ -363,6 +366,22 @@ impl Perform for Oper { Some(data.q.to_owned()), data.page, data.limit)?; + }, + SearchType::Url => { + posts = PostView::list( + &conn, + PostListingType::All, + &sort, + data.community_id, + None, + None, + Some(data.q.to_owned()), + None, + true, + false, + false, + data.page, + data.limit)?; } }; @@ -371,6 +390,7 @@ impl Perform for Oper { Ok( SearchResponse { op: self.op.to_string(), + type_: data.type_.to_owned(), comments: comments, posts: posts, communities: communities, diff --git a/server/src/api/user.rs b/server/src/api/user.rs index 672eca56..425cc1cb 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -318,6 +318,7 @@ impl Perform for Oper { data.community_id, None, None, + None, Some(user_details_id), show_nsfw, data.saved_only, @@ -332,6 +333,7 @@ impl Perform for Oper { data.community_id, Some(user_details_id), None, + None, user_id, show_nsfw, data.saved_only, diff --git a/server/src/db/mod.rs b/server/src/db/mod.rs index 9f0c79b8..3de0abb4 100644 --- a/server/src/db/mod.rs +++ b/server/src/db/mod.rs @@ -67,7 +67,7 @@ pub enum SortType { #[derive(EnumString,ToString,Debug, Serialize, Deserialize)] pub enum SearchType { - All, Comments, Posts, Communities, Users + All, Comments, Posts, Communities, Users, Url } pub fn fuzzy_search(q: &str) -> String { diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs index c7e6eea3..c9d8cff7 100644 --- a/server/src/db/post_view.rs +++ b/server/src/db/post_view.rs @@ -79,6 +79,7 @@ impl PostView { for_community_id: Option, for_creator_id: Option, search_term: Option, + url_search: Option, my_user_id: Option, show_nsfw: bool, saved_only: bool, @@ -104,6 +105,10 @@ impl PostView { query = query.filter(name.ilike(fuzzy_search(&search_term))); }; + if let Some(url_search) = url_search { + query = query.filter(url.eq(url_search)); + }; + // TODO these are wrong, bc they'll only show saved for your logged in user, not theirs if saved_only { query = query.filter(saved.eq(true)); @@ -326,29 +331,34 @@ mod tests { }; - let read_post_listings_with_user = PostView::list(&conn, - PostListingType::Community, - &SortType::New, Some(inserted_community.id), - None, - None, - Some(inserted_user.id), - false, - false, - false, - None, - None).unwrap(); - let read_post_listings_no_user = PostView::list(&conn, - PostListingType::Community, - &SortType::New, - Some(inserted_community.id), - None, - None, - None, - false, - false, - false, - None, - None).unwrap(); + let read_post_listings_with_user = PostView::list( + &conn, + PostListingType::Community, + &SortType::New, + Some(inserted_community.id), + None, + None, + None, + Some(inserted_user.id), + false, + false, + false, + None, + None).unwrap(); + let read_post_listings_no_user = PostView::list( + &conn, + PostListingType::Community, + &SortType::New, + Some(inserted_community.id), + None, + None, + None, + None, + false, + false, + false, + None, + None).unwrap(); let read_post_listing_no_user = PostView::read(&conn, inserted_post.id, None).unwrap(); let read_post_listing_with_user = PostView::read(&conn, inserted_post.id, Some(inserted_user.id)).unwrap(); diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs index 64f94f4c..c0dee267 100644 --- a/server/src/websocket/server.rs +++ b/server/src/websocket/server.rs @@ -142,6 +142,7 @@ impl ChatServer { None, None, None, + None, false, false, false, diff --git a/ui/src/components/create-post.tsx b/ui/src/components/create-post.tsx index dd93a3c5..3e00bd80 100644 --- a/ui/src/components/create-post.tsx +++ b/ui/src/components/create-post.tsx @@ -1,6 +1,7 @@ import { Component } from 'inferno'; import { PostForm } from './post-form'; import { WebSocketService } from '../services'; +import { PostFormParams } from '../interfaces'; import { i18n } from '../i18next'; import { T } from 'inferno-i18next'; @@ -21,13 +22,25 @@ export class CreatePost extends Component {
#
- +
) } + get params(): PostFormParams { + let urlParams = new URLSearchParams(this.props.location.search); + let params: PostFormParams = { + name: urlParams.get("name"), + community: urlParams.get("community") || this.prevCommunityName, + body: urlParams.get("body"), + url: urlParams.get("url"), + }; + + return params; + } + get prevCommunityName(): string { if (this.props.match.params.name) { return this.props.match.params.name; diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index 42620c9f..f502e7f3 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno'; import { PostListings } from './post-listings'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; -import { PostForm as PostFormI, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces'; +import { PostForm as PostFormI, PostFormParams, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter } from '../utils'; import * as autosize from 'autosize'; @@ -11,7 +11,7 @@ import { T } from 'inferno-i18next'; interface PostFormProps { post?: Post; // If a post is given, that means this is an edit - prevCommunityName?: string; + params?: PostFormParams; onCancel?(): any; onCreate?(id: number): any; onEdit?(post: Post): any; @@ -23,6 +23,7 @@ interface PostFormState { loading: boolean; suggestedTitle: string; suggestedPosts: Array; + crossPosts: Array; } export class PostForm extends Component { @@ -40,6 +41,7 @@ export class PostForm extends Component { loading: false, suggestedTitle: undefined, suggestedPosts: [], + crossPosts: [], } constructor(props: any, context: any) { @@ -60,20 +62,30 @@ export class PostForm extends Component { } } + if (this.props.params) { + this.state.postForm.name = this.props.params.name; + if (this.props.params.url) { + this.state.postForm.url = this.props.params.url; + } + if (this.props.params.body) { + this.state.postForm.body = this.props.params.body; + } + } + this.subscription = WebSocketService.Instance.subject - .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) - .subscribe( - (msg) => this.parseMessage(msg), + .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) + .subscribe( + (msg) => this.parseMessage(msg), (err) => console.error(err), () => console.log('complete') - ); + ); - let listCommunitiesForm: ListCommunitiesForm = { - sort: SortType[SortType.TopAll], - limit: 9999, - } + let listCommunitiesForm: ListCommunitiesForm = { + sort: SortType[SortType.TopAll], + limit: 9999, + } - WebSocketService.Instance.listCommunities(listCommunitiesForm); + WebSocketService.Instance.listCommunities(listCommunitiesForm); } componentDidMount() { @@ -95,6 +107,12 @@ export class PostForm extends Component { {this.state.suggestedTitle &&
#
} + {this.state.crossPosts.length > 0 && + <> +
#
+ + + }
@@ -115,7 +133,6 @@ export class PostForm extends Component {