Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d989d6ffad | ||
| 5229458746 | |||
| 2bfa1db816 | |||
| 8439428ce1 | |||
| 34dceef4a3 |
@@ -2,7 +2,7 @@
|
|||||||
"name": "lume",
|
"name": "lume",
|
||||||
"description": "the communication app",
|
"description": "the communication app",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "2.1.4",
|
"version": "2.1.6",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
|||||||
2
src-tauri/Cargo.lock
generated
2
src-tauri/Cargo.lock
generated
@@ -2680,7 +2680,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lume"
|
name = "lume"
|
||||||
version = "2.1.4"
|
version = "2.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"keyring",
|
"keyring",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "lume"
|
name = "lume"
|
||||||
version = "2.1.4"
|
version = "2.1.6"
|
||||||
description = "the communication app"
|
description = "the communication app"
|
||||||
authors = ["Ren Amamiya"]
|
authors = ["Ren Amamiya"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"package": {
|
"package": {
|
||||||
"productName": "Lume",
|
"productName": "Lume",
|
||||||
"version": "2.1.4"
|
"version": "2.1.6"
|
||||||
},
|
},
|
||||||
"plugins": {
|
"plugins": {
|
||||||
"fs": {
|
"fs": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { message } from '@tauri-apps/plugin-dialog';
|
|
||||||
import { normalizeRelayUrl } from 'nostr-fetch';
|
import { normalizeRelayUrl } from 'nostr-fetch';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { toast } from 'sonner';
|
||||||
import { VList } from 'virtua';
|
import { VList } from 'virtua';
|
||||||
|
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
@@ -37,10 +37,14 @@ export function RelayList() {
|
|||||||
const url = normalizeRelayUrl(relayUrl);
|
const url = normalizeRelayUrl(relayUrl);
|
||||||
const res = await db.createRelay(url);
|
const res = await db.createRelay(url);
|
||||||
|
|
||||||
if (!res) await message("You're aldready connected to this relay");
|
if (res) {
|
||||||
queryClient.invalidateQueries({
|
toast.info('Connected. You need to restart app to take effect');
|
||||||
queryKey: ['user-relay'],
|
queryClient.invalidateQueries({
|
||||||
});
|
queryKey: ['user-relay'],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast.warning("You're aldready connected to this relay");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ export function ProfileCard() {
|
|||||||
{user?.display_name || user?.name}
|
{user?.display_name || user?.name}
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-lg text-neutral-700 dark:text-neutral-300">
|
<p className="text-lg text-neutral-700 dark:text-neutral-300">
|
||||||
{user.nip05 || displayNpub(db.account.pubkey, 16)}
|
{user?.nip05 || displayNpub(db.account.pubkey, 16)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -184,10 +184,7 @@ export function EditProfileScreen() {
|
|||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type={'text'}
|
type={'text'}
|
||||||
{...register('display_name', {
|
{...register('display_name')}
|
||||||
required: true,
|
|
||||||
minLength: 4,
|
|
||||||
})}
|
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none backdrop-blur-xl placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100"
|
className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none backdrop-blur-xl placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100"
|
||||||
/>
|
/>
|
||||||
@@ -201,10 +198,7 @@ export function EditProfileScreen() {
|
|||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type={'text'}
|
type={'text'}
|
||||||
{...register('name', {
|
{...register('name')}
|
||||||
required: true,
|
|
||||||
minLength: 4,
|
|
||||||
})}
|
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none backdrop-blur-xl placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100"
|
className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none backdrop-blur-xl placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100"
|
||||||
/>
|
/>
|
||||||
@@ -218,10 +212,7 @@ export function EditProfileScreen() {
|
|||||||
</label>
|
</label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<input
|
<input
|
||||||
{...register('nip05', {
|
{...register('nip05')}
|
||||||
required: true,
|
|
||||||
minLength: 4,
|
|
||||||
})}
|
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none backdrop-blur-xl placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100"
|
className="relative h-11 w-full rounded-lg bg-neutral-100 px-3 py-1 text-neutral-900 !outline-none backdrop-blur-xl placeholder:text-neutral-500 dark:bg-neutral-900 dark:text-neutral-100"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -26,44 +26,48 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
|
|||||||
const svgURI =
|
const svgURI =
|
||||||
'data:image/svg+xml;utf8,' + encodeURIComponent(minidenticon(pubkey, 90, 50));
|
'data:image/svg+xml;utf8,' + encodeURIComponent(minidenticon(pubkey, 90, 50));
|
||||||
|
|
||||||
const follow = async (pubkey: string) => {
|
const follow = async () => {
|
||||||
try {
|
try {
|
||||||
|
if (!ndk.signer) return navigate('/new/privkey');
|
||||||
|
setFollowed(true);
|
||||||
|
|
||||||
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
||||||
const contacts = await user.follows();
|
const contacts = await user.follows();
|
||||||
const add = await user.follow(new NDKUser({ pubkey: pubkey }), contacts);
|
const add = await user.follow(new NDKUser({ pubkey: pubkey }), contacts);
|
||||||
|
|
||||||
if (add) {
|
if (!add) {
|
||||||
setFollowed(true);
|
toast.success('You already follow this user');
|
||||||
} else {
|
setFollowed(false);
|
||||||
toast('You already follow this user');
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
console.log(error);
|
toast.error(e);
|
||||||
|
setFollowed(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const unfollow = async (pubkey: string) => {
|
const unfollow = async () => {
|
||||||
try {
|
try {
|
||||||
if (!ndk.signer) return navigate('/new/privkey');
|
if (!ndk.signer) return navigate('/new/privkey');
|
||||||
|
setFollowed(false);
|
||||||
|
|
||||||
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
||||||
const contacts = await user.follows();
|
const contacts = await user.follows();
|
||||||
contacts.delete(new NDKUser({ pubkey: pubkey }));
|
contacts.delete(new NDKUser({ pubkey: pubkey }));
|
||||||
|
|
||||||
let list: string[][];
|
const list = [...contacts].map((item) => [
|
||||||
contacts.forEach((el) => list.push(['p', el.pubkey, el.relayUrls?.[0] || '', '']));
|
'p',
|
||||||
|
item.pubkey,
|
||||||
|
item.relayUrls?.[0] || '',
|
||||||
|
'',
|
||||||
|
]);
|
||||||
const event = new NDKEvent(ndk);
|
const event = new NDKEvent(ndk);
|
||||||
event.content = '';
|
event.content = '';
|
||||||
event.kind = NDKKind.Contacts;
|
event.kind = NDKKind.Contacts;
|
||||||
event.tags = list;
|
event.tags = list;
|
||||||
|
|
||||||
const publishedRelays = await event.publish();
|
await event.publish();
|
||||||
if (publishedRelays) {
|
} catch (e) {
|
||||||
setFollowed(false);
|
toast.error(e);
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,23 +143,23 @@ export function UserProfile({ pubkey }: { pubkey: string }) {
|
|||||||
{followed ? (
|
{followed ? (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => unfollow(pubkey)}
|
onClick={unfollow}
|
||||||
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-neutral-200 text-sm font-medium text-neutral-900 backdrop-blur-xl hover:bg-blue-600 hover:text-neutral-100 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-blue-600 dark:hover:text-neutral-100"
|
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-neutral-200 text-sm font-medium text-neutral-900 backdrop-blur-xl hover:bg-blue-500 hover:text-neutral-100 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-blue-600 dark:hover:text-neutral-100"
|
||||||
>
|
>
|
||||||
Unfollow
|
Unfollow
|
||||||
</button>
|
</button>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => follow(pubkey)}
|
onClick={follow}
|
||||||
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-neutral-200 text-sm font-medium text-neutral-900 backdrop-blur-xl hover:bg-blue-600 hover:text-neutral-100 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-blue-600 dark:hover:text-neutral-100"
|
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-neutral-200 text-sm font-medium text-neutral-900 backdrop-blur-xl hover:bg-blue-500 hover:text-neutral-100 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-blue-600 dark:hover:text-neutral-100"
|
||||||
>
|
>
|
||||||
Follow
|
Follow
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
<Link
|
<Link
|
||||||
to={`/chats/${pubkey}`}
|
to={`/chats/${pubkey}`}
|
||||||
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-neutral-200 text-sm font-medium text-neutral-900 backdrop-blur-xl hover:bg-blue-600 hover:text-neutral-100 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-blue-600 dark:hover:text-neutral-100"
|
className="inline-flex h-10 w-36 items-center justify-center rounded-md bg-neutral-200 text-sm font-medium text-neutral-900 backdrop-blur-xl hover:bg-blue-500 hover:text-neutral-100 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-blue-600 dark:hover:text-neutral-100"
|
||||||
>
|
>
|
||||||
Message
|
Message
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import NDK, { NDKNip46Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
|
import NDK, { NDKNip46Signer, NDKPrivateKeySigner } from '@nostr-dev-kit/ndk';
|
||||||
import { ndkAdapter } from '@nostr-fetch/adapter-ndk';
|
import { ndkAdapter } from '@nostr-fetch/adapter-ndk';
|
||||||
import { message } from '@tauri-apps/plugin-dialog';
|
import { ask } from '@tauri-apps/plugin-dialog';
|
||||||
import { fetch } from '@tauri-apps/plugin-http';
|
import { fetch } from '@tauri-apps/plugin-http';
|
||||||
|
import { relaunch } from '@tauri-apps/plugin-process';
|
||||||
import { NostrFetcher } from 'nostr-fetch';
|
import { NostrFetcher } from 'nostr-fetch';
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
@@ -78,50 +79,57 @@ export const NDKInstance = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function initNDK() {
|
async function initNDK() {
|
||||||
const outboxSetting = await db.getSettingValue('outbox');
|
|
||||||
const bunkerSetting = await db.getSettingValue('nsecbunker');
|
|
||||||
const signer = await getSigner(!!parseInt(bunkerSetting));
|
|
||||||
const explicitRelayUrls = await getExplicitRelays();
|
|
||||||
|
|
||||||
const tauriAdapter = new NDKCacheAdapterTauri(db);
|
|
||||||
const instance = new NDK({
|
|
||||||
explicitRelayUrls,
|
|
||||||
cacheAdapter: tauriAdapter,
|
|
||||||
outboxRelayUrls: ['wss://purplepag.es'],
|
|
||||||
blacklistRelayUrls: [],
|
|
||||||
enableOutboxModel: !!parseInt(outboxSetting),
|
|
||||||
});
|
|
||||||
instance.signer = signer;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const outboxSetting = await db.getSettingValue('outbox');
|
||||||
|
const bunkerSetting = await db.getSettingValue('nsecbunker');
|
||||||
|
const signer = await getSigner(!!parseInt(bunkerSetting));
|
||||||
|
const explicitRelayUrls = await getExplicitRelays();
|
||||||
|
|
||||||
|
const tauriAdapter = new NDKCacheAdapterTauri(db);
|
||||||
|
const instance = new NDK({
|
||||||
|
explicitRelayUrls,
|
||||||
|
cacheAdapter: tauriAdapter,
|
||||||
|
outboxRelayUrls: ['wss://purplepag.es'],
|
||||||
|
blacklistRelayUrls: [],
|
||||||
|
enableOutboxModel: !!parseInt(outboxSetting),
|
||||||
|
});
|
||||||
|
instance.signer = signer;
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
await instance.connect(2000);
|
await instance.connect();
|
||||||
|
|
||||||
// update account's metadata
|
// update account's metadata
|
||||||
if (db.account) {
|
if (db.account) {
|
||||||
const user = instance.getUser({ pubkey: db.account.pubkey });
|
const user = instance.getUser({ pubkey: db.account.pubkey });
|
||||||
const follows = [...(await user.follows())].map((user) => user.pubkey);
|
if (user) {
|
||||||
const relayList = await user.relayList();
|
const follows = [...(await user.follows())].map((user) => user.pubkey);
|
||||||
|
const relayList = await user.relayList();
|
||||||
|
|
||||||
// update user's follows
|
// update user's follows
|
||||||
await db.updateAccount('follows', JSON.stringify(follows));
|
await db.updateAccount('follows', JSON.stringify(follows));
|
||||||
|
|
||||||
// update user's relay list
|
if (relayList)
|
||||||
if (relayList) {
|
// update user's relays
|
||||||
for (const relay of relayList.relays) {
|
for (const relay of relayList.relays) {
|
||||||
await db.createRelay(relay);
|
await db.createRelay(relay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
|
||||||
await message(`NDK instance init failed: ${error}`, {
|
|
||||||
title: 'Lume',
|
|
||||||
type: 'error',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setNDK(instance);
|
setNDK(instance);
|
||||||
setRelayUrls(explicitRelayUrls);
|
setRelayUrls(explicitRelayUrls);
|
||||||
|
} catch (e) {
|
||||||
|
const yes = await ask(
|
||||||
|
`Something wrong, Lume is not working as expected, do you want to relaunch app?`,
|
||||||
|
{
|
||||||
|
title: 'Lume',
|
||||||
|
type: 'error',
|
||||||
|
okLabel: 'Yes',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (yes) relaunch();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ export class LumeStorage {
|
|||||||
[relay, this.account.id]
|
[relay, this.account.id]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!existRelays.length) return;
|
if (existRelays.length) return;
|
||||||
|
|
||||||
return await this.db.execute(
|
return await this.db.execute(
|
||||||
'INSERT OR IGNORE INTO relays (account_id, relay, purpose) VALUES ($1, $2, $3);',
|
'INSERT OR IGNORE INTO relays (account_id, relay, purpose) VALUES ($1, $2, $3);',
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link, NavLink, Outlet, ScrollRestoration } from 'react-router-dom';
|
import { NavLink, Outlet, ScrollRestoration, useNavigate } from 'react-router-dom';
|
||||||
import { twMerge } from 'tailwind-merge';
|
import { twMerge } from 'tailwind-merge';
|
||||||
import { WindowTitlebar } from 'tauri-controls';
|
import { WindowTitlebar } from 'tauri-controls';
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
|
|
||||||
export function SettingsLayout() {
|
export function SettingsLayout() {
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen w-screen flex-col bg-neutral-50 dark:bg-neutral-950">
|
<div className="flex h-screen w-screen flex-col bg-neutral-50 dark:bg-neutral-950">
|
||||||
@@ -26,16 +27,17 @@ export function SettingsLayout() {
|
|||||||
<div className="flex h-full min-h-0 w-full flex-col gap-8 overflow-y-auto pb-10">
|
<div className="flex h-full min-h-0 w-full flex-col gap-8 overflow-y-auto pb-10">
|
||||||
<div className="flex h-20 w-full items-center justify-between border-b border-neutral-200 px-2 pb-2 dark:border-neutral-900">
|
<div className="flex h-20 w-full items-center justify-between border-b border-neutral-200 px-2 pb-2 dark:border-neutral-900">
|
||||||
<div>
|
<div>
|
||||||
<Link
|
<button
|
||||||
to="/"
|
type="button"
|
||||||
|
onClick={() => navigate(-1)}
|
||||||
className="inline-flex h-12 w-12 items-center justify-center rounded-xl bg-neutral-100 dark:bg-neutral-900"
|
className="inline-flex h-12 w-12 items-center justify-center rounded-xl bg-neutral-100 dark:bg-neutral-900"
|
||||||
>
|
>
|
||||||
<ArrowLeftIcon className="h-5 w-5" />
|
<ArrowLeftIcon className="h-5 w-5" />
|
||||||
</Link>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-0.5">
|
<div className="flex items-center gap-0.5">
|
||||||
<NavLink
|
<NavLink
|
||||||
to="/settings"
|
to="/settings/"
|
||||||
end
|
end
|
||||||
className={({ isActive }) =>
|
className={({ isActive }) =>
|
||||||
twMerge(
|
twMerge(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { NDKEvent, NDKKind, NDKUser } from '@nostr-dev-kit/ndk';
|
import { NDKUser } from '@nostr-dev-kit/ndk';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
@@ -6,7 +6,7 @@ import { toast } from 'sonner';
|
|||||||
import { useNDK } from '@libs/ndk/provider';
|
import { useNDK } from '@libs/ndk/provider';
|
||||||
import { useStorage } from '@libs/storage/provider';
|
import { useStorage } from '@libs/storage/provider';
|
||||||
|
|
||||||
import { FollowIcon, UnfollowIcon } from '@shared/icons';
|
import { FollowIcon } from '@shared/icons';
|
||||||
|
|
||||||
import { shortenKey } from '@utils/shortenKey';
|
import { shortenKey } from '@utils/shortenKey';
|
||||||
|
|
||||||
@@ -16,53 +16,30 @@ export interface Profile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function NostrBandUserProfile({ data }: { data: Profile }) {
|
export function NostrBandUserProfile({ data }: { data: Profile }) {
|
||||||
const embedProfile = data.profile ? JSON.parse(data.profile.content) : null;
|
|
||||||
const profile = embedProfile;
|
|
||||||
|
|
||||||
const { db } = useStorage();
|
const { db } = useStorage();
|
||||||
const { ndk } = useNDK();
|
const { ndk } = useNDK();
|
||||||
|
|
||||||
const [followed, setFollowed] = useState(false);
|
const [followed, setFollowed] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const profile = data.profile ? JSON.parse(data.profile.content) : null;
|
||||||
|
|
||||||
const follow = async (pubkey: string) => {
|
const follow = async (pubkey: string) => {
|
||||||
try {
|
try {
|
||||||
|
if (!ndk.signer) return navigate('/new/privkey');
|
||||||
|
setFollowed(true);
|
||||||
|
|
||||||
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
||||||
const contacts = await user.follows();
|
const contacts = await user.follows();
|
||||||
const add = await user.follow(new NDKUser({ pubkey: pubkey }), contacts);
|
const add = await user.follow(new NDKUser({ pubkey: pubkey }), contacts);
|
||||||
|
|
||||||
if (add) {
|
if (!add) {
|
||||||
setFollowed(true);
|
toast.success('You already follow this user');
|
||||||
} else {
|
|
||||||
toast('You already follow this user');
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const unfollow = async (pubkey: string) => {
|
|
||||||
try {
|
|
||||||
if (!ndk.signer) return navigate('/new/privkey');
|
|
||||||
|
|
||||||
const user = ndk.getUser({ pubkey: db.account.pubkey });
|
|
||||||
const contacts = await user.follows();
|
|
||||||
contacts.delete(new NDKUser({ pubkey: pubkey }));
|
|
||||||
|
|
||||||
let list: string[][];
|
|
||||||
contacts.forEach((el) => list.push(['p', el.pubkey, el.relayUrls?.[0] || '', '']));
|
|
||||||
|
|
||||||
const event = new NDKEvent(ndk);
|
|
||||||
event.content = '';
|
|
||||||
event.kind = NDKKind.Contacts;
|
|
||||||
event.tags = list;
|
|
||||||
|
|
||||||
const publishedRelays = await event.publish();
|
|
||||||
if (publishedRelays) {
|
|
||||||
setFollowed(false);
|
setFollowed(false);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
console.log(error);
|
toast.error(e);
|
||||||
|
setFollowed(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,15 +77,7 @@ export function NostrBandUserProfile({ data }: { data: Profile }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="inline-flex items-center gap-2">
|
<div className="inline-flex items-center gap-2">
|
||||||
{followed ? (
|
{!followed ? (
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => unfollow(data.pubkey)}
|
|
||||||
className="inline-flex h-8 w-8 items-center justify-center rounded-md bg-neutral-200 text-neutral-900 backdrop-blur-xl hover:bg-blue-600 hover:text-white dark:bg-neutral-800 dark:text-neutral-100 dark:hover:text-white"
|
|
||||||
>
|
|
||||||
<UnfollowIcon className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
) : (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => follow(data.pubkey)}
|
onClick={() => follow(data.pubkey)}
|
||||||
@@ -116,7 +85,7 @@ export function NostrBandUserProfile({ data }: { data: Profile }) {
|
|||||||
>
|
>
|
||||||
<FollowIcon className="h-4 w-4" />
|
<FollowIcon className="h-4 w-4" />
|
||||||
</button>
|
</button>
|
||||||
)}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-2 line-clamp-5 whitespace-pre-line break-all text-neutral-900 dark:text-neutral-100">
|
<div className="mt-2 line-clamp-5 whitespace-pre-line break-all text-neutral-900 dark:text-neutral-100">
|
||||||
|
|||||||
@@ -13,7 +13,10 @@ export function useSuggestion() {
|
|||||||
items: async ({ query }) => {
|
items: async ({ query }) => {
|
||||||
const users = await db.getAllCacheUsers();
|
const users = await db.getAllCacheUsers();
|
||||||
return users
|
return users
|
||||||
.filter((item) => item.name.toLowerCase().startsWith(query.toLowerCase()))
|
.filter((item) => {
|
||||||
|
if (item.name) return item.name.toLowerCase().startsWith(query.toLowerCase());
|
||||||
|
return item.displayName.toLowerCase().startsWith(query.toLowerCase());
|
||||||
|
})
|
||||||
.slice(0, 5);
|
.slice(0, 5);
|
||||||
},
|
},
|
||||||
render: () => {
|
render: () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user