From: Dessalines Date: Thu, 25 Apr 2019 21:52:18 +0000 (-0700) Subject: Adding /f/ and /u/ in links now. X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%7B%7D/static/%7Bthis.props.icon%7D?a=commitdiff_plain;h=e4532aa1cb19decb5f57fca13ca20aae3e1e0a1e;p=lemmy.git Adding /f/ and /u/ in links now. - Fixes #102 --- diff --git a/server/src/actions/community.rs b/server/src/actions/community.rs index 7a69c807..42c95c7d 100644 --- a/server/src/actions/community.rs +++ b/server/src/actions/community.rs @@ -59,6 +59,14 @@ impl Crud for Community { } } +impl Community { + pub fn read_from_name(conn: &PgConnection, community_name: String) -> Result { + use schema::community::dsl::*; + community.filter(name.eq(community_name)) + .first::(conn) + } +} + #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)] #[belongs_to(Community)] #[table_name = "community_moderator"] diff --git a/server/src/actions/user.rs b/server/src/actions/user.rs index ea6f36e6..58cfd89d 100644 --- a/server/src/actions/user.rs +++ b/server/src/actions/user.rs @@ -67,6 +67,10 @@ impl User_ { Self::create(&conn, &edited_user) } + pub fn read_from_name(conn: &PgConnection, from_user_name: String) -> Result { + user_.filter(name.eq(from_user_name)) + .first::(conn) + } } #[derive(Debug, Serialize, Deserialize)] diff --git a/server/src/websocket_server/server.rs b/server/src/websocket_server/server.rs index dee42726..dbd1be8d 100644 --- a/server/src/websocket_server/server.rs +++ b/server/src/websocket_server/server.rs @@ -188,7 +188,8 @@ pub struct GetPostsResponse { #[derive(Serialize, Deserialize)] pub struct GetCommunity { - id: i32, + id: Option, + name: Option, auth: Option } @@ -311,7 +312,8 @@ pub struct GetFollowedCommunitiesResponse { #[derive(Serialize, Deserialize)] pub struct GetUserDetails { - user_id: i32, + user_id: Option, + username: Option, sort: String, page: Option, limit: Option, @@ -1176,14 +1178,19 @@ impl Perform for GetCommunity { None => None }; - let community_view = match CommunityView::read(&conn, self.id, user_id) { + let community_id = match self.id { + Some(id) => id, + None => Community::read_from_name(&conn, self.name.to_owned().unwrap_or("main".to_string()))?.id + }; + + let community_view = match CommunityView::read(&conn, community_id, user_id) { Ok(community) => community, Err(_e) => { return Err(self.error("Couldn't find Community"))? } }; - let moderators = match CommunityModeratorView::for_community(&conn, self.id) { + let moderators = match CommunityModeratorView::for_community(&conn, community_id) { Ok(moderators) => moderators, Err(_e) => { return Err(self.error("Couldn't find Community"))? @@ -2042,7 +2049,13 @@ impl Perform for GetUserDetails { //TODO add save let sort = SortType::from_str(&self.sort)?; - let user_view = UserView::read(&conn, self.user_id)?; + let user_details_id = match self.user_id { + Some(id) => id, + None => User_::read_from_name(&conn, self.username.to_owned().unwrap_or("admin".to_string()))?.id + }; + + let user_view = UserView::read(&conn, user_details_id)?; + // If its saved only, you don't care what creator it was let posts = if self.saved_only { PostView::list(&conn, @@ -2051,7 +2064,7 @@ impl Perform for GetUserDetails { self.community_id, None, None, - Some(self.user_id), + Some(user_details_id), self.saved_only, false, self.page, @@ -2061,7 +2074,7 @@ impl Perform for GetUserDetails { PostListingType::All, &sort, self.community_id, - Some(self.user_id), + Some(user_details_id), None, None, self.saved_only, @@ -2075,7 +2088,7 @@ impl Perform for GetUserDetails { None, None, None, - Some(self.user_id), + Some(user_details_id), self.saved_only, self.page, self.limit)? @@ -2083,7 +2096,7 @@ impl Perform for GetUserDetails { CommentView::list(&conn, &sort, None, - Some(self.user_id), + Some(user_details_id), None, None, self.saved_only, @@ -2091,8 +2104,8 @@ impl Perform for GetUserDetails { self.limit)? }; - let follows = CommunityFollowerView::for_user(&conn, self.user_id)?; - let moderates = CommunityModeratorView::for_user(&conn, self.user_id)?; + let follows = CommunityFollowerView::for_user(&conn, user_details_id)?; + let moderates = CommunityModeratorView::for_user(&conn, user_details_id)?; // Return the jwt Ok( diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index fabacb28..0c0fd821 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -69,7 +69,7 @@ export class CommentNode extends Component {
  • - {node.comment.creator_name} + {node.comment.creator_name}
  • {this.isMod &&
  • mod
  • diff --git a/ui/src/components/communities.tsx b/ui/src/components/communities.tsx index 23206807..38344007 100644 --- a/ui/src/components/communities.tsx +++ b/ui/src/components/communities.tsx @@ -73,7 +73,7 @@ export class Communities extends Component { {this.state.communities.map(community => - {community.name} + {community.name} {community.title} {community.category_name} {community.number_of_subscribers} diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx index 2d5aa3e7..66071a3f 100644 --- a/ui/src/components/community-form.tsx +++ b/ui/src/components/community-form.tsx @@ -11,7 +11,7 @@ import { Community } from '../interfaces'; interface CommunityFormProps { community?: Community; // If a community is given, that means this is an edit onCancel?(): any; - onCreate?(id: number): any; + onCreate?(community: Community): any; onEdit?(community: Community): any; } @@ -167,7 +167,7 @@ export class CommunityForm extends Component; admins: Array; loading: boolean; @@ -36,6 +37,7 @@ export class Community extends Component { moderators: [], admins: [], communityId: Number(this.props.match.params.id), + communityName: this.props.match.params.name, loading: true } @@ -52,7 +54,12 @@ export class Community extends Component { () => console.log('complete') ); - WebSocketService.Instance.getCommunity(this.state.communityId); + if (this.state.communityId) { + WebSocketService.Instance.getCommunity(this.state.communityId); + } else if (this.state.communityName) { + WebSocketService.Instance.getCommunityByName(this.state.communityName); + } + } componentWillUnmount() { @@ -71,7 +78,7 @@ export class Community extends Component { removed } - + {this.state.community && }
{ @@ -25,8 +26,8 @@ export class CreateCommunity extends Component { ) } - handleCommunityCreate(id: number) { - this.props.history.push(`/community/${id}`); + handleCommunityCreate(community: Community) { + this.props.history.push(`/f/${community.name}`); } } diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index 50fd47c2..02d813f3 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -58,7 +58,7 @@ export class Inbox extends Component {
-
Inbox for {user.username}
+
Inbox for {user.username}
{this.selects()} {this.replies()} {this.paginator()} diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 0687ffbc..6911ca40 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -96,7 +96,7 @@ export class Main extends Component {
Subscribed forums
    {this.state.subscribedCommunities.map(community => -
  • {community.community_name}
  • +
  • {community.community_name}
  • )}
@@ -116,7 +116,7 @@ export class Main extends Component {
Trending forums
    {this.state.trendingCommunities.map(community => -
  • {community.name}
  • +
  • {community.name}
  • )}
@@ -158,7 +158,7 @@ export class Main extends Component {
  • admins:
  • {this.state.site.admins.map(admin => -
  • {admin.name}
  • +
  • {admin.name}
  • )}
{this.state.site.site.description && diff --git a/ui/src/components/modlog.tsx b/ui/src/components/modlog.tsx index 55df617a..f644b163 100644 --- a/ui/src/components/modlog.tsx +++ b/ui/src/components/modlog.tsx @@ -84,7 +84,7 @@ export class Modlog extends Component { {this.state.combined.map(i => - {i.data.mod_user_name} + {i.data.mod_user_name} {i.type_ == 'removed_posts' && <> @@ -103,14 +103,14 @@ export class Modlog extends Component { <> {(i.data as ModRemoveComment).removed? 'Removed' : 'Restored'} Comment {(i.data as ModRemoveComment).comment_content} - by {(i.data as ModRemoveComment).comment_user_name} + by {(i.data as ModRemoveComment).comment_user_name}
{(i.data as ModRemoveComment).reason && ` reason: ${(i.data as ModRemoveComment).reason}`}
} {i.type_ == 'removed_communities' && <> {(i.data as ModRemoveCommunity).removed ? 'Removed' : 'Restored'} - Community {(i.data as ModRemoveCommunity).community_name} + Community {(i.data as ModRemoveCommunity).community_name}
{(i.data as ModRemoveCommunity).reason && ` reason: ${(i.data as ModRemoveCommunity).reason}`}
{(i.data as ModRemoveCommunity).expires && ` expires: ${moment.utc((i.data as ModRemoveCommunity).expires).fromNow()}`}
@@ -118,9 +118,9 @@ export class Modlog extends Component { {i.type_ == 'banned_from_community' && <> {(i.data as ModBanFromCommunity).banned ? 'Banned ' : 'Unbanned '} - {(i.data as ModBanFromCommunity).other_user_name} + {(i.data as ModBanFromCommunity).other_user_name} from the community - {(i.data as ModBanFromCommunity).community_name} + {(i.data as ModBanFromCommunity).community_name}
{(i.data as ModBanFromCommunity).reason && ` reason: ${(i.data as ModBanFromCommunity).reason}`}
{(i.data as ModBanFromCommunity).expires && ` expires: ${moment.utc((i.data as ModBanFromCommunity).expires).fromNow()}`}
@@ -128,15 +128,15 @@ export class Modlog extends Component { {i.type_ == 'added_to_community' && <> {(i.data as ModAddCommunity).removed ? 'Removed ' : 'Appointed '} - {(i.data as ModAddCommunity).other_user_name} + {(i.data as ModAddCommunity).other_user_name} as a mod to the community - {(i.data as ModAddCommunity).community_name} + {(i.data as ModAddCommunity).community_name} } {i.type_ == 'banned' && <> {(i.data as ModBan).banned ? 'Banned ' : 'Unbanned '} - {(i.data as ModBan).other_user_name} + {(i.data as ModBan).other_user_name}
{(i.data as ModBan).reason && ` reason: ${(i.data as ModBan).reason}`}
{(i.data as ModBan).expires && ` expires: ${moment.utc((i.data as ModBan).expires).fromNow()}`}
@@ -144,7 +144,7 @@ export class Modlog extends Component { {i.type_ == 'added' && <> {(i.data as ModAdd).removed ? 'Removed ' : 'Appointed '} - {(i.data as ModAdd).other_user_name} + {(i.data as ModAdd).other_user_name} as an admin } @@ -165,7 +165,7 @@ export class Modlog extends Component {
:
- {this.state.communityName && /f/{this.state.communityName} } + {this.state.communityName && /f/{this.state.communityName} } Modlog
diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx index fb8f5755..88d270e1 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -129,7 +129,7 @@ export class Navbar extends Component { handleOverviewClick(i: Navbar) { i.state.expandUserDropdown = false; i.setState(i.state); - let userPage = `/user/${UserService.Instance.user.id}`; + let userPage = `/u/${UserService.Instance.user.username}`; i.context.router.history.push(userPage); } diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index 40462eb6..198c8e8e 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -103,7 +103,7 @@ export class PostListing extends Component {
  • by - {post.creator_name} + {post.creator_name} {this.isMod && mod } @@ -113,7 +113,7 @@ export class PostListing extends Component { {this.props.showCommunity && to - {post.community_name} + {post.community_name} }
  • diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index 0d9715c4..7bea5f90 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -57,7 +57,7 @@ export class Sidebar extends Component { removed } - /f/{community.name} + /f/{community.name}
      {this.canMod && <> @@ -107,7 +107,7 @@ export class Sidebar extends Component {
      • mods:
      • {this.props.moderators.map(mod => -
      • {mod.user_name}
      • +
      • {mod.user_name}
      • )}
      diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index 1131428b..1d1f8e63 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -16,6 +16,7 @@ enum View { interface UserState { user: UserView; user_id: number; + username: string; follows: Array; moderates: Array; comments: Array; @@ -41,6 +42,7 @@ export class User extends Component { comment_score: null, }, user_id: null, + username: null, follows: [], moderates: [], comments: [], @@ -56,6 +58,7 @@ export class User extends Component { this.state = this.emptyState; this.state.user_id = Number(this.props.match.params.id); + this.state.username = this.props.match.params.username; this.subscription = WebSocketService.Instance.subject .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) @@ -206,7 +209,7 @@ export class User extends Component {
      Moderates
        {this.state.moderates.map(community => -
      • {community.community_name}
      • +
      • {community.community_name}
      • )}
      @@ -224,7 +227,7 @@ export class User extends Component {
      Subscribed
        {this.state.follows.map(community => -
      • {community.community_name}
      • +
      • {community.community_name}
      • )}
@@ -259,6 +262,7 @@ export class User extends Component { refetch() { let form: GetUserDetailsForm = { user_id: this.state.user_id, + username: this.state.username, sort: SortType[this.state.sort], saved_only: this.state.view == View.Saved, page: this.state.page, diff --git a/ui/src/index.tsx b/ui/src/index.tsx index 4b3cd611..446705f1 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -48,8 +48,9 @@ class Index extends Component { - + + diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 05987fe3..68d1b412 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -141,8 +141,9 @@ export interface GetFollowedCommunitiesResponse { } export interface GetUserDetailsForm { - user_id: number; - sort: string; // TODO figure this one out + user_id?: number; + username?: string; + sort: string; page?: number; limit?: number; community_id?: number; diff --git a/ui/src/services/WebSocketService.ts b/ui/src/services/WebSocketService.ts index dc06df28..2389ab84 100644 --- a/ui/src/services/WebSocketService.ts +++ b/ui/src/services/WebSocketService.ts @@ -81,6 +81,11 @@ export class WebSocketService { this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, data)); } + public getCommunityByName(name: string) { + let data = {name: name, auth: UserService.Instance.auth }; + this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, data)); + } + public createComment(commentForm: CommentForm) { this.setAuth(commentForm); this.subject.next(this.wsSendWrapper(UserOperation.CreateComment, commentForm));