wip: new activity sidebar

This commit is contained in:
2024-01-11 21:00:42 +07:00
parent a8cd34d998
commit 2c8571ecc7
21 changed files with 537 additions and 203 deletions

View File

@@ -392,8 +392,12 @@ export class Ark {
const seenIds = new Set<string>();
const dedupQueue = new Set<string>();
const relayUrls = [...this.ndk.pool.relays.values()].map(
(item) => item.url,
);
const events = await this.#fetcher.fetchLatestEvents(
this.#storage.account.relayList,
relayUrls,
filter,
limit,
{

View File

@@ -28,6 +28,8 @@ export function RepostNote({
}
},
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
});
if (isLoading) {
@@ -72,7 +74,6 @@ export function RepostNote({
<Note.Repost />
<Note.Zap />
</div>
N
</div>
</div>
</Note.Provider>

View File

@@ -41,7 +41,7 @@ export function NoteUser({
<Avatar.Image
src={fallbackAvatar}
alt={event.pubkey}
className="h-6 w-6 rounded-md bg-black dark:bg-white"
className="h-6 w-6 shrink-0 object-cover rounded-md bg-black dark:bg-white"
/>
</Avatar.Root>
<div className="flex flex-1 items-baseline gap-2">
@@ -65,7 +65,7 @@ export function NoteUser({
alt={event.pubkey}
loading="eager"
decoding="async"
className="h-6 w-6 rounded-md"
className="h-6 w-6 shrink-0 object-cover rounded-md"
/>
<Avatar.Fallback delayMs={300}>
<img

View File

@@ -1,14 +1,22 @@
import { LoaderIcon } from "@lume/icons";
import { NDKCacheAdapterTauri } from "@lume/ndk-cache-tauri";
import { LumeStorage } from "@lume/storage";
import { QUOTES, delay, sendNativeNotification } from "@lume/utils";
import {
FETCH_LIMIT,
QUOTES,
delay,
sendNativeNotification,
} from "@lume/utils";
import NDK, {
NDKEvent,
NDKKind,
NDKNip46Signer,
NDKPrivateKeySigner,
NDKRelay,
NDKRelayAuthPolicies,
} from "@nostr-dev-kit/ndk";
import { ndkAdapter } from "@nostr-fetch/adapter-ndk";
import { useQueryClient } from "@tanstack/react-query";
import { fetch } from "@tauri-apps/plugin-http";
import { platform } from "@tauri-apps/plugin-os";
import { relaunch } from "@tauri-apps/plugin-process";
@@ -35,6 +43,8 @@ const LumeContext = createContext<Context>({
});
const LumeProvider = ({ children }: PropsWithChildren<object>) => {
const queryClient = useQueryClient();
const [context, setContext] = useState<Context>(undefined);
const [isNewVersion, setIsNewVersion] = useState(false);
@@ -176,14 +186,41 @@ const LumeProvider = ({ children }: PropsWithChildren<object>) => {
const contacts = await user.follows();
storage.account.contacts = [...contacts].map((user) => user.pubkey);
const relays = await user.relayList();
// subscribe for new activity
const sub = ndk.subscribe(
{
kinds: [NDKKind.Text, NDKKind.Repost, NDKKind.Zap],
"#p": [storage.account.pubkey],
since: Math.floor(Date.now() / 1000),
},
{ closeOnEose: false, groupable: false },
);
if (!relays) storage.account.relayList = ndk.explicitRelayUrls;
storage.account.relayList = [
...relays.readRelayUrls,
...relays.bothRelayUrls,
];
sub.addListener("event", async (event: NDKEvent) => {
const profile = await ark.getUserProfile(event.pubkey);
switch (event.kind) {
case NDKKind.Text:
return await sendNativeNotification(
`${
profile.displayName || profile.name || "anon"
} has replied to your note`,
);
case NDKKind.Repost:
return await sendNativeNotification(
`${
profile.displayName || profile.name || "anon"
} has reposted to your note`,
);
case NDKKind.Zap:
return await sendNativeNotification(
`${
profile.displayName || profile.name || "anon"
} has zapped to your note`,
);
default:
break;
}
});
}
// init nostr fetcher