mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 14:45:20 +00:00
Using fully qualified actor_ids for name and community tributes. Fixes #93
This commit is contained in:
parent
2be380ef76
commit
b8c3c2bcd4
|
@ -42,6 +42,8 @@ import {
|
||||||
PostView,
|
PostView,
|
||||||
PrivateMessageView,
|
PrivateMessageView,
|
||||||
LemmyWebsocket,
|
LemmyWebsocket,
|
||||||
|
UserViewSafe,
|
||||||
|
CommunityView,
|
||||||
} from 'lemmy-js-client';
|
} from 'lemmy-js-client';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -671,13 +673,11 @@ export function setupTribute() {
|
||||||
{
|
{
|
||||||
trigger: '@',
|
trigger: '@',
|
||||||
selectTemplate: (item: any) => {
|
selectTemplate: (item: any) => {
|
||||||
let link = item.original.local
|
let it: UserTribute = item.original;
|
||||||
? `[${item.original.key}](/u/${item.original.name})`
|
return `[${it.key}](${it.view.user.actor_id})`;
|
||||||
: `[${item.original.key}](/user/${item.original.id})`;
|
|
||||||
return link;
|
|
||||||
},
|
},
|
||||||
values: (text: string, cb: any) => {
|
values: (text: string, cb: (users: UserTribute[]) => any) => {
|
||||||
userSearch(text, (users: any) => cb(users));
|
userSearch(text, (users: UserTribute[]) => cb(users));
|
||||||
},
|
},
|
||||||
allowSpaces: false,
|
allowSpaces: false,
|
||||||
autocompleteMode: true,
|
autocompleteMode: true,
|
||||||
|
@ -690,13 +690,13 @@ export function setupTribute() {
|
||||||
{
|
{
|
||||||
trigger: '!',
|
trigger: '!',
|
||||||
selectTemplate: (item: any) => {
|
selectTemplate: (item: any) => {
|
||||||
let link = item.original.local
|
let it: CommunityTribute = item.original;
|
||||||
? `[${item.original.key}](/c/${item.original.name})`
|
return `[${it.key}](${it.view.community.actor_id})`;
|
||||||
: `[${item.original.key}](/community/${item.original.id})`;
|
|
||||||
return link;
|
|
||||||
},
|
},
|
||||||
values: (text: string, cb: any) => {
|
values: (text: string, cb: any) => {
|
||||||
communitySearch(text, (communities: any) => cb(communities));
|
communitySearch(text, (communities: CommunityTribute[]) =>
|
||||||
|
cb(communities)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
allowSpaces: false,
|
allowSpaces: false,
|
||||||
autocompleteMode: true,
|
autocompleteMode: true,
|
||||||
|
@ -724,7 +724,12 @@ export function setupTippy() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function userSearch(text: string, cb: any) {
|
interface UserTribute {
|
||||||
|
key: string;
|
||||||
|
view: UserViewSafe;
|
||||||
|
}
|
||||||
|
|
||||||
|
function userSearch(text: string, cb: (users: UserTribute[]) => any) {
|
||||||
if (text) {
|
if (text) {
|
||||||
let form: Search = {
|
let form: Search = {
|
||||||
q: text,
|
q: text,
|
||||||
|
@ -742,13 +747,12 @@ function userSearch(text: string, cb: any) {
|
||||||
let res = wsJsonToRes(msg);
|
let res = wsJsonToRes(msg);
|
||||||
if (res.op == UserOperation.Search) {
|
if (res.op == UserOperation.Search) {
|
||||||
let data = res.data as SearchResponse;
|
let data = res.data as SearchResponse;
|
||||||
let users = data.users.map(uv => {
|
let users: UserTribute[] = data.users.map(uv => {
|
||||||
return {
|
let tribute: UserTribute = {
|
||||||
key: `@${uv.user.name}@${hostname(uv.user.actor_id)}`,
|
key: `@${uv.user.name}@${hostname(uv.user.actor_id)}`,
|
||||||
name: uv.user.name,
|
view: uv,
|
||||||
local: uv.user.local,
|
|
||||||
id: uv.user.id,
|
|
||||||
};
|
};
|
||||||
|
return tribute;
|
||||||
});
|
});
|
||||||
cb(users);
|
cb(users);
|
||||||
userSub.unsubscribe();
|
userSub.unsubscribe();
|
||||||
|
@ -762,7 +766,15 @@ function userSearch(text: string, cb: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function communitySearch(text: string, cb: any) {
|
interface CommunityTribute {
|
||||||
|
key: string;
|
||||||
|
view: CommunityView;
|
||||||
|
}
|
||||||
|
|
||||||
|
function communitySearch(
|
||||||
|
text: string,
|
||||||
|
cb: (communities: CommunityTribute[]) => any
|
||||||
|
) {
|
||||||
if (text) {
|
if (text) {
|
||||||
let form: Search = {
|
let form: Search = {
|
||||||
q: text,
|
q: text,
|
||||||
|
@ -780,13 +792,12 @@ function communitySearch(text: string, cb: any) {
|
||||||
let res = wsJsonToRes(msg);
|
let res = wsJsonToRes(msg);
|
||||||
if (res.op == UserOperation.Search) {
|
if (res.op == UserOperation.Search) {
|
||||||
let data = res.data as SearchResponse;
|
let data = res.data as SearchResponse;
|
||||||
let communities = data.communities.map(cv => {
|
let communities: CommunityTribute[] = data.communities.map(cv => {
|
||||||
return {
|
let tribute: CommunityTribute = {
|
||||||
key: `!${cv.community.name}@${hostname(cv.community.actor_id)}`,
|
key: `!${cv.community.name}@${hostname(cv.community.actor_id)}`,
|
||||||
name: cv.community.name,
|
view: cv,
|
||||||
local: cv.community.local,
|
|
||||||
id: cv.community.id,
|
|
||||||
};
|
};
|
||||||
|
return tribute;
|
||||||
});
|
});
|
||||||
cb(communities);
|
cb(communities);
|
||||||
communitySub.unsubscribe();
|
communitySub.unsubscribe();
|
||||||
|
|
Loading…
Reference in a new issue