From 990b1004ff3c975f2aa1a611d453b152d5475126 Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Thu, 23 May 2024 08:16:35 -0500 Subject: [PATCH] update wasm relay fix dm timelines not closing add summary to wiki edit page --- package.json | 2 +- src/helpers/nostr/dms.ts | 8 +++--- src/helpers/nostr/event.ts | 1 + src/hooks/use-timeline-loader.ts | 19 +++++++++++++- ...n-provider.tsx => decryption-provider.tsx} | 0 src/providers/global/index.tsx | 2 +- src/services/dictionary.ts | 2 +- src/views/dms/chat.tsx | 2 +- .../dms/components/decrypt-placeholder.tsx | 2 +- .../dms/components/send-message-form.tsx | 2 +- src/views/dms/components/thread-drawer.tsx | 2 +- src/views/dms/index.tsx | 2 +- src/views/launchpad/components/dms-card.tsx | 2 +- src/views/wiki/create.tsx | 2 +- src/views/wiki/edit.tsx | 25 ++++++++++++++++--- yarn.lock | 18 ++++++------- 16 files changed, 63 insertions(+), 28 deletions(-) rename src/providers/global/{dycryption-provider.tsx => decryption-provider.tsx} (100%) diff --git a/package.json b/package.json index ff62e0934..7fafa95fc 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@noble/hashes": "^1.3.2", "@noble/secp256k1": "^1.7.0", "@scure/base": "^1.1.6", - "@snort/worker-relay": "^1.0.10", + "@snort/worker-relay": "^1.1.0", "@uiw/codemirror-theme-github": "^4.21.21", "@uiw/react-codemirror": "^4.21.21", "@webscopeio/react-textarea-autocomplete": "^4.9.2", diff --git a/src/helpers/nostr/dms.ts b/src/helpers/nostr/dms.ts index 7b444a6d1..590b9e04f 100644 --- a/src/helpers/nostr/dms.ts +++ b/src/helpers/nostr/dms.ts @@ -1,12 +1,12 @@ import dayjs from "dayjs"; -import { NostrEvent, isPTag } from "../../types/nostr-event"; +import { NostrEvent } from "nostr-tools"; import { sortByDate } from "./event"; export function getDMSender(event: NostrEvent) { return event.pubkey; } export function getDMRecipient(event: NostrEvent) { - const pubkey = event.tags.find(isPTag)?.[1]; + const pubkey = event.tags.find((t) => t[0] === "p")?.[1]; if (!pubkey) throw new Error("Missing recipient pubkey"); return pubkey; } @@ -47,8 +47,8 @@ export function hasResponded(conversion: KnownConversation) { const latestReceived = conversion.messages.find((m) => getDMSender(m) === conversion.correspondent); const latestSent = conversion.messages.find((m) => getDMSender(m) === conversion.myself); - if (latestReceived && latestSent && latestSent.created_at > latestReceived.created_at) return false; - return true; + if (latestReceived && latestSent && latestSent.created_at > latestReceived.created_at) return true; + return false; } export function sortConversationsByLastReceived(conversations: KnownConversation[]) { diff --git a/src/helpers/nostr/event.ts b/src/helpers/nostr/event.ts index e387d44a8..a3c163da8 100644 --- a/src/helpers/nostr/event.ts +++ b/src/helpers/nostr/event.ts @@ -299,6 +299,7 @@ export function ensureDTag(draft: DraftNostrEvent, d: string = nanoid()) { } } +/** either replaces the existing tag or adds a new one */ export function replaceOrAddSimpleTag(draft: DraftNostrEvent, tagName: string, value: string) { if (draft.tags.some((t) => t[0] === tagName)) { draft.tags = draft.tags.map((t) => (t[0] === tagName ? [tagName, value] : t)); diff --git a/src/hooks/use-timeline-loader.ts b/src/hooks/use-timeline-loader.ts index 60de0dba7..f5385c3ae 100644 --- a/src/hooks/use-timeline-loader.ts +++ b/src/hooks/use-timeline-loader.ts @@ -1,5 +1,5 @@ import { useEffect, useMemo } from "react"; -import { useUnmount } from "react-use"; +import { usePrevious, useUnmount } from "react-use"; import { Filter, NostrEvent } from "nostr-tools"; import timelineCacheService from "../services/timeline-cache"; @@ -21,11 +21,13 @@ export default function useTimelineLoader( ) { const timeline = useMemo(() => timelineCacheService.createTimeline(key), [key]); + // update relays useEffect(() => { timeline.setRelays(relays); timeline.triggerChunkLoad(); }, [Array.from(relays).join("|")]); + // update filters useEffect(() => { if (filters) { timeline.setFilters(Array.isArray(filters) ? filters : [filters]); @@ -34,18 +36,33 @@ export default function useTimelineLoader( } else timeline.close(); }, [timeline, JSON.stringify(filters)]); + // update event filter useEffect(() => { timeline.setEventFilter(opts?.eventFilter); }, [timeline, opts?.eventFilter]); + + // update cursor + // NOTE: I don't think this is used anywhere and should be removed useEffect(() => { if (opts?.cursor !== undefined) { timeline.setCursor(opts.cursor); } }, [timeline, opts?.cursor]); + + // update custom sort useEffect(() => { timeline.events.customSort = opts?.customSort; }, [timeline, opts?.customSort]); + // close the old timeline when the key changes + const oldTimeline = usePrevious(timeline); + useEffect(() => { + if (oldTimeline && oldTimeline !== timeline) { + oldTimeline.close(); + } + }, [timeline, oldTimeline]); + + // stop the loader when unmount useUnmount(() => { timeline.close(); }); diff --git a/src/providers/global/dycryption-provider.tsx b/src/providers/global/decryption-provider.tsx similarity index 100% rename from src/providers/global/dycryption-provider.tsx rename to src/providers/global/decryption-provider.tsx diff --git a/src/providers/global/index.tsx b/src/providers/global/index.tsx index 682b87e1a..6d3aff29d 100644 --- a/src/providers/global/index.tsx +++ b/src/providers/global/index.tsx @@ -8,7 +8,7 @@ import NotificationsProvider from "./notifications-provider"; import { DefaultEmojiProvider, UserEmojiProvider } from "./emoji-provider"; import { AllUserSearchDirectoryProvider } from "./user-directory-provider"; import BreakpointProvider from "./breakpoint-provider"; -import DecryptionProvider from "./dycryption-provider"; +import DecryptionProvider from "./decryption-provider"; import DMTimelineProvider from "./dms-provider"; import PublishProvider from "./publish-provider"; import WebOfTrustProvider from "./web-of-trust-provider"; diff --git a/src/services/dictionary.ts b/src/services/dictionary.ts index 6e5d0ceb9..4b892fcec 100644 --- a/src/services/dictionary.ts +++ b/src/services/dictionary.ts @@ -27,7 +27,7 @@ class DictionaryService { }); constructor() { - this.process = new Process("EventReactionsService", this); + this.process = new Process("DictionaryService", this); this.process.icon = BookOpen01; this.process.active = true; diff --git a/src/views/dms/chat.tsx b/src/views/dms/chat.tsx index 7d6423a6e..64d9ad314 100644 --- a/src/views/dms/chat.tsx +++ b/src/views/dms/chat.tsx @@ -14,7 +14,7 @@ import IntersectionObserverProvider from "../../providers/local/intersection-obs import { useTimelineCurserIntersectionCallback } from "../../hooks/use-timeline-cursor-intersection-callback"; import TimelineActionAndStatus from "../../components/timeline-page/timeline-action-and-status"; import UserDnsIdentity from "../../components/user/user-dns-identity"; -import { useDecryptionContext } from "../../providers/global/dycryption-provider"; +import { useDecryptionContext } from "../../providers/global/decryption-provider"; import SendMessageForm from "./components/send-message-form"; import { groupMessages } from "../../helpers/nostr/dms"; import ThreadDrawer from "./components/thread-drawer"; diff --git a/src/views/dms/components/decrypt-placeholder.tsx b/src/views/dms/components/decrypt-placeholder.tsx index cc1721ddc..8df66f558 100644 --- a/src/views/dms/components/decrypt-placeholder.tsx +++ b/src/views/dms/components/decrypt-placeholder.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from "react"; import { Alert, AlertDescription, AlertIcon, Button, ButtonProps } from "@chakra-ui/react"; import { UnlockIcon } from "../../../components/icons"; -import { useDecryptionContainer } from "../../../providers/global/dycryption-provider"; +import { useDecryptionContainer } from "../../../providers/global/decryption-provider"; import useCurrentAccount from "../../../hooks/use-current-account"; import { getDMRecipient, getDMSender } from "../../../helpers/nostr/dms"; import { NostrEvent } from "../../../types/nostr-event"; diff --git a/src/views/dms/components/send-message-form.tsx b/src/views/dms/components/send-message-form.tsx index 787b7b0e1..a89514044 100644 --- a/src/views/dms/components/send-message-form.tsx +++ b/src/views/dms/components/send-message-form.tsx @@ -8,7 +8,7 @@ import { useSigningContext } from "../../../providers/global/signing-provider"; import MagicTextArea, { RefType } from "../../../components/magic-textarea"; import { useTextAreaUploadFileWithForm } from "../../../hooks/use-textarea-upload-file"; import { DraftNostrEvent } from "../../../types/nostr-event"; -import { useDecryptionContext } from "../../../providers/global/dycryption-provider"; +import { useDecryptionContext } from "../../../providers/global/decryption-provider"; import useUserMailboxes from "../../../hooks/use-user-mailboxes"; import { usePublishEvent } from "../../../providers/global/publish-provider"; diff --git a/src/views/dms/components/thread-drawer.tsx b/src/views/dms/components/thread-drawer.tsx index 991e63fb6..8b161fd8b 100644 --- a/src/views/dms/components/thread-drawer.tsx +++ b/src/views/dms/components/thread-drawer.tsx @@ -27,7 +27,7 @@ import { Thread, useThreadsContext } from "../../../providers/local/thread-provi import ThreadButton from "./thread-button"; import SendMessageForm from "./send-message-form"; import { groupMessages } from "../../../helpers/nostr/dms"; -import { useDecryptionContext } from "../../../providers/global/dycryption-provider"; +import { useDecryptionContext } from "../../../providers/global/decryption-provider"; import DirectMessageBlock from "./direct-message-block"; function MessagePreview({ message, ...props }: { message: NostrEvent } & Omit) { diff --git a/src/views/dms/index.tsx b/src/views/dms/index.tsx index 1c707a632..2289f12e5 100644 --- a/src/views/dms/index.tsx +++ b/src/views/dms/index.tsx @@ -18,7 +18,7 @@ import { useTimelineCurserIntersectionCallback } from "../../hooks/use-timeline- import TimelineActionAndStatus from "../../components/timeline-page/timeline-action-and-status"; import { useDMTimeline } from "../../providers/global/dms-provider"; import UserName from "../../components/user/user-name"; -import { useDecryptionContainer } from "../../providers/global/dycryption-provider"; +import { useDecryptionContainer } from "../../providers/global/decryption-provider"; import { NostrEvent } from "../../types/nostr-event"; import { CheckIcon } from "../../components/icons"; import UserDnsIdentity from "../../components/user/user-dns-identity"; diff --git a/src/views/launchpad/components/dms-card.tsx b/src/views/launchpad/components/dms-card.tsx index a3c20589c..03d1af671 100644 --- a/src/views/launchpad/components/dms-card.tsx +++ b/src/views/launchpad/components/dms-card.tsx @@ -19,7 +19,7 @@ import HoverLinkOverlay from "../../../components/hover-link-overlay"; import UserName from "../../../components/user/user-name"; import UserDnsIdentity from "../../../components/user/user-dns-identity"; import { nip19 } from "nostr-tools"; -import { useDecryptionContainer, useDecryptionContext } from "../../../providers/global/dycryption-provider"; +import { useDecryptionContainer, useDecryptionContext } from "../../../providers/global/decryption-provider"; import Timestamp from "../../../components/timestamp"; function MessagePreview({ message, pubkey }: { message: NostrEvent; pubkey: string }) { diff --git a/src/views/wiki/create.tsx b/src/views/wiki/create.tsx index 40b7b7aeb..2d8d17dcc 100644 --- a/src/views/wiki/create.tsx +++ b/src/views/wiki/create.tsx @@ -99,7 +99,7 @@ export default function CreateWikiPageView() { Summary