From 38cdfdf7e0ee1db1e315c150a1b375f9245a95db Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 30 Apr 2020 11:45:12 -0400 Subject: Changing federated community and user links and searching. - Search: !community@instance, @user@instance - Representation: community@instance, user@instance --- ui/src/api_tests/api.spec.ts | 2 +- ui/src/components/community-link.tsx | 7 +++++-- ui/src/components/sidebar.tsx | 13 +++---------- ui/src/components/user-listing.tsx | 5 +++-- ui/src/components/user.tsx | 2 +- ui/src/utils.ts | 28 ++++++++++++++++++++++------ 6 files changed, 35 insertions(+), 22 deletions(-) (limited to 'ui/src') diff --git a/ui/src/api_tests/api.spec.ts b/ui/src/api_tests/api.spec.ts index 7a810d9a..7121d038 100644 --- a/ui/src/api_tests/api.spec.ts +++ b/ui/src/api_tests/api.spec.ts @@ -96,7 +96,7 @@ describe('main', () => { test('/u/lemmy_alpha follows and accepts lemmy_beta/c/main', async () => { // Make sure lemmy_beta/c/main is cached on lemmy_alpha // Use short-hand search url - let searchUrl = `${lemmyAlphaApiUrl}/search?q=/c/main@lemmy_beta:8550&type_=All&sort=TopAll`; + let searchUrl = `${lemmyAlphaApiUrl}/search?q=!main@lemmy_beta:8550&type_=All&sort=TopAll`; let searchResponse: SearchResponse = await fetch(searchUrl, { method: 'GET', diff --git a/ui/src/components/community-link.tsx b/ui/src/components/community-link.tsx index bcfa0534..eb55400e 100644 --- a/ui/src/components/community-link.tsx +++ b/ui/src/components/community-link.tsx @@ -12,6 +12,7 @@ interface CommunityOther { interface CommunityLinkProps { community: Community | CommunityOther; + realLink?: boolean; } export class CommunityLink extends Component { @@ -27,8 +28,10 @@ export class CommunityLink extends Component { name_ = community.name; link = `/c/${community.name}`; } else { - name_ = `${hostname(community.actor_id)}/${community.name}`; - link = `/community/${community.id}`; + name_ = `${community.name}@${hostname(community.actor_id)}`; + link = !this.props.realLink + ? `/community/${community.id}` + : community.actor_id; } return {name_}; } diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index 51766923..dc2376d7 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -11,6 +11,7 @@ import { WebSocketService, UserService } from '../services'; import { mdToHtml, getUnixTime, hostname } from '../utils'; import { CommunityForm } from './community-form'; import { UserListing } from './user-listing'; +import { CommunityLink } from './community-link'; import { i18n } from '../i18next'; interface SidebarProps { @@ -66,7 +67,7 @@ export class Sidebar extends Component { name_ = community.name; link = `/c/${community.name}`; } else { - name_ = `${hostname(community.actor_id)}/${community.name}`; + name_ = `${community.name}@${hostname(community.actor_id)}`; link = community.actor_id; } return ( @@ -86,15 +87,7 @@ export class Sidebar extends Component { )} - {community.local ? ( - - {name_} - - ) : ( - - {name_} - - )} +
    {this.canMod && ( <> diff --git a/ui/src/components/user-listing.tsx b/ui/src/components/user-listing.tsx index 356c4d48..903aa1a7 100644 --- a/ui/src/components/user-listing.tsx +++ b/ui/src/components/user-listing.tsx @@ -13,6 +13,7 @@ interface UserOther { interface UserListingProps { user: UserView | UserOther; + realLink?: boolean; } export class UserListing extends Component { @@ -29,8 +30,8 @@ export class UserListing extends Component { name_ = user.name; link = `/u/${user.name}`; } else { - name_ = `${hostname(user.actor_id)}/${user.name}`; - link = `/user/${user.id}`; + name_ = `${user.name}@${hostname(user.actor_id)}`; + link = !this.props.realLink ? `/user/${user.id}` : user.actor_id; } return ( diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index b3e4542f..51b9582f 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -402,7 +402,7 @@ export class User extends Component {
    • - +
    • {user.banned && (
    • diff --git a/ui/src/utils.ts b/ui/src/utils.ts index 480b41c7..277da987 100644 --- a/ui/src/utils.ts +++ b/ui/src/utils.ts @@ -501,7 +501,10 @@ export function setupTribute(): Tribute { { trigger: '@', selectTemplate: (item: any) => { - return `[/u/${item.original.key}](/u/${item.original.key})`; + let link = item.original.local + ? `[@${item.original.key}](/u/${item.original.key})` + : `[@${item.original.key}](/user/${item.original.id})`; + return link; }, values: (text: string, cb: any) => { userSearch(text, (users: any) => cb(users)); @@ -514,9 +517,12 @@ export function setupTribute(): Tribute { // Communities { - trigger: '#', + trigger: '!', selectTemplate: (item: any) => { - return `[/c/${item.original.key}](/c/${item.original.key})`; + let link = item.original.local + ? `[!${item.original.key}](/c/${item.original.key})` + : `[!${item.original.key}](/community/${item.original.id})`; + return link; }, values: (text: string, cb: any) => { communitySearch(text, (communities: any) => cb(communities)); @@ -559,7 +565,12 @@ function userSearch(text: string, cb: any) { if (res.op == UserOperation.Search) { let data = res.data as SearchResponse; let users = data.users.map(u => { - return { key: u.name }; + let name_ = u.local ? u.name : `${u.name}@${hostname(u.actor_id)}`; + return { + key: name_, + local: u.local, + id: u.id, + }; }); cb(users); this.userSub.unsubscribe(); @@ -590,8 +601,13 @@ function communitySearch(text: string, cb: any) { let res = wsJsonToRes(msg); if (res.op == UserOperation.Search) { let data = res.data as SearchResponse; - let communities = data.communities.map(u => { - return { key: u.name }; + let communities = data.communities.map(c => { + let name_ = c.local ? c.name : `${c.name}@${hostname(c.actor_id)}`; + return { + key: name_, + local: c.local, + id: c.id, + }; }); cb(communities); this.communitySub.unsubscribe(); -- cgit v1.2.3