forked from Kieran/snort
Prettier
This commit is contained in:
parent
04239123bb
commit
4b2161369d
@ -3,16 +3,7 @@ import React, { useMemo, useState, ReactNode } from "react";
|
||||
import { useNavigate, Link } from "react-router-dom";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
import { useIntl, FormattedMessage } from "react-intl";
|
||||
import {
|
||||
TaggedNostrEvent,
|
||||
HexKey,
|
||||
EventKind,
|
||||
NostrPrefix,
|
||||
Lists,
|
||||
EventExt,
|
||||
parseZap,
|
||||
NostrLink
|
||||
} from "@snort/system";
|
||||
import { TaggedNostrEvent, HexKey, EventKind, NostrPrefix, Lists, EventExt, parseZap, NostrLink } from "@snort/system";
|
||||
|
||||
import { System } from "index";
|
||||
import useEventPublisher from "Feed/EventPublisher";
|
||||
|
@ -12,19 +12,16 @@ export function useReactions(subId: string, ids: Array<NostrLink>, others?: (rb:
|
||||
const aTags = ids.filter(a => a.type === NostrPrefix.Address);
|
||||
|
||||
if (aTags.length > 0 || eTags.length > 0) {
|
||||
const f = rb.withFilter()
|
||||
const f = rb
|
||||
.withFilter()
|
||||
.kinds(
|
||||
pref.enableReactions
|
||||
? [EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt]
|
||||
: [EventKind.ZapReceipt, EventKind.Repost],
|
||||
);
|
||||
|
||||
if(aTags.length > 0) {
|
||||
f.tag("a", aTags.map(v => `${v.kind}:${v.author}:${v.id}`));
|
||||
}
|
||||
if(eTags.length > 0) {
|
||||
f.tag("e", eTags.map(v => v.id));
|
||||
}
|
||||
aTags.forEach(v => f.replyToLink(v));
|
||||
eTags.forEach(v => f.replyToLink(v));
|
||||
}
|
||||
others?.(rb);
|
||||
return rb.numFilters > 0 ? rb : null;
|
||||
|
@ -14,13 +14,9 @@ export default function useThreadFeed(link: NostrLink) {
|
||||
sub.withOptions({
|
||||
leaveOpen: true,
|
||||
});
|
||||
sub.withFilter()
|
||||
.kinds([EventKind.TextNote])
|
||||
.link(link);
|
||||
sub.withFilter().kinds([EventKind.TextNote]).link(link);
|
||||
if (allEvents.length > 0) {
|
||||
const f = sub
|
||||
.withFilter()
|
||||
.kinds([EventKind.TextNote]);
|
||||
const f = sub.withFilter().kinds([EventKind.TextNote]);
|
||||
allEvents.forEach(x => f.replyToLink(x));
|
||||
}
|
||||
return sub;
|
||||
@ -31,10 +27,12 @@ export default function useThreadFeed(link: NostrLink) {
|
||||
useEffect(() => {
|
||||
if (store.data) {
|
||||
const mainNotes = store.data?.filter(a => a.kind === EventKind.TextNote || a.kind === EventKind.Polls) ?? [];
|
||||
const links = mainNotes.map(a => [
|
||||
NostrLink.fromEvent(a),
|
||||
...a.tags.filter(a => a[0] === "e" || a[0] === "a").map(v => NostrLink.fromTag(v))
|
||||
]).flat();
|
||||
const links = mainNotes
|
||||
.map(a => [
|
||||
NostrLink.fromEvent(a),
|
||||
...a.tags.filter(a => a[0] === "e" || a[0] === "a").map(v => NostrLink.fromTag(v)),
|
||||
])
|
||||
.flat();
|
||||
setAllEvents(links);
|
||||
}
|
||||
}, [store.data?.length]);
|
||||
|
@ -1,12 +1,5 @@
|
||||
import { unwrap } from "@snort/shared";
|
||||
import {
|
||||
EventExt,
|
||||
NostrLink,
|
||||
NostrPrefix,
|
||||
TaggedNostrEvent,
|
||||
u256,
|
||||
Thread as ThreadInfo,
|
||||
} from "@snort/system";
|
||||
import { EventExt, NostrLink, NostrPrefix, TaggedNostrEvent, u256, Thread as ThreadInfo } from "@snort/system";
|
||||
import useThreadFeed from "Feed/ThreadFeed";
|
||||
import { findTag } from "SnortUtils";
|
||||
import { ReactNode, createContext, useMemo, useState } from "react";
|
||||
@ -56,7 +49,7 @@ export function ThreadContextWrapper({ link, children }: { link: NostrLink; chil
|
||||
// Root is the parent of the current note or the current note if its a root note or the root of the thread
|
||||
const root = useMemo(() => {
|
||||
const currentNote =
|
||||
feed.thread?.find(
|
||||
feed.thread?.find(
|
||||
ne =>
|
||||
ne.id === currentId ||
|
||||
(link.type === NostrPrefix.Address && findTag(ne, "d") === currentId && ne.pubkey === link.author),
|
||||
|
@ -25,8 +25,8 @@ import useLogin from "Hooks/useLogin";
|
||||
type Cols = "notes" | "articles" | "media" | "streams" | "notifications";
|
||||
|
||||
interface DeckScope {
|
||||
thread?: NostrLink,
|
||||
setThread: (e?: NostrLink) => void
|
||||
thread?: NostrLink;
|
||||
setThread: (e?: NostrLink) => void;
|
||||
}
|
||||
|
||||
export const DeckContext = createContext<DeckScope | undefined>(undefined);
|
||||
@ -35,7 +35,7 @@ export function SnortDeckLayout() {
|
||||
const login = useLogin();
|
||||
const navigate = useNavigate();
|
||||
const [deckScope, setDeckScope] = useState<DeckScope>({
|
||||
setThread: (e?: NostrLink) => setDeckScope(s => ({ ...s, thread: e }))
|
||||
setThread: (e?: NostrLink) => setDeckScope(s => ({ ...s, thread: e })),
|
||||
});
|
||||
|
||||
useLoginFeed();
|
||||
|
@ -1,14 +1,6 @@
|
||||
import "./Notifications.css";
|
||||
import { useEffect, useMemo, useSyncExternalStore } from "react";
|
||||
import {
|
||||
EventExt,
|
||||
EventKind,
|
||||
NostrEvent,
|
||||
NostrLink,
|
||||
NostrPrefix,
|
||||
TaggedNostrEvent,
|
||||
parseZap,
|
||||
} from "@snort/system";
|
||||
import { EventExt, EventKind, NostrEvent, NostrLink, NostrPrefix, TaggedNostrEvent, parseZap } from "@snort/system";
|
||||
import { unwrap } from "@snort/shared";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import { useInView } from "react-intersection-observer";
|
||||
|
@ -142,9 +142,16 @@ export const NotesTab = () => {
|
||||
<>
|
||||
<FollowsHint />
|
||||
<TaskList />
|
||||
<TimelineFollows postsOnly={true} noteOnClick={deckContext ? (ev) => {
|
||||
deckContext.setThread(NostrLink.fromEvent(ev));
|
||||
} : undefined} />
|
||||
<TimelineFollows
|
||||
postsOnly={true}
|
||||
noteOnClick={
|
||||
deckContext
|
||||
? ev => {
|
||||
deckContext.setThread(NostrLink.fromEvent(ev));
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
@ -1,10 +1,5 @@
|
||||
import { LNURL } from "@snort/shared";
|
||||
import {
|
||||
EventPublisher,
|
||||
NostrEvent,
|
||||
NostrLink,
|
||||
SystemInterface
|
||||
} from "@snort/system";
|
||||
import { EventPublisher, NostrEvent, NostrLink, SystemInterface } from "@snort/system";
|
||||
import { generateRandomKey } from "Login";
|
||||
import { isHex } from "SnortUtils";
|
||||
import { LNWallet, WalletInvoiceState } from "Wallet";
|
||||
@ -203,7 +198,7 @@ export class Zapper {
|
||||
return svc;
|
||||
}
|
||||
}
|
||||
}catch {
|
||||
} catch {
|
||||
// nothing
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,9 @@
|
||||
"+aZY2h": {
|
||||
"defaultMessage": "Zap Type"
|
||||
},
|
||||
"+tShPg": {
|
||||
"defaultMessage": "following"
|
||||
},
|
||||
"+vA//S": {
|
||||
"defaultMessage": "Logins"
|
||||
},
|
||||
|
@ -3,6 +3,7 @@
|
||||
"+PzQ9Y": "Payout Now",
|
||||
"+Vxixo": "Secret Group Chat",
|
||||
"+aZY2h": "Zap Type",
|
||||
"+tShPg": "following",
|
||||
"+vA//S": "Logins",
|
||||
"+vIQlC": "Please make sure to save the following password in order to manage your handle in the future",
|
||||
"+vVZ/G": "Connect",
|
||||
|
@ -8,11 +8,11 @@ export class NostrLink {
|
||||
readonly id: string,
|
||||
readonly kind?: number,
|
||||
readonly author?: string,
|
||||
readonly relays?: Array<string>
|
||||
) { }
|
||||
readonly relays?: Array<string>,
|
||||
) {}
|
||||
|
||||
encode(): string {
|
||||
if(this.type === NostrPrefix.Note || this.type === NostrPrefix.PrivateKey || this.type === NostrPrefix.PublicKey) {
|
||||
if (this.type === NostrPrefix.Note || this.type === NostrPrefix.PrivateKey || this.type === NostrPrefix.PublicKey) {
|
||||
return hexToBech32(this.type, this.id);
|
||||
} else {
|
||||
return encodeTLV(this.type, this.id, this.relays, this.kind, this.author);
|
||||
@ -39,12 +39,12 @@ export class NostrLink {
|
||||
} else if (this.type === NostrPrefix.Event || this.type === NostrPrefix.Note) {
|
||||
return this.id === ev.id;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static fromTag(tag: Array<string>) {
|
||||
const relays = tag.length > 2 ? [tag[2]]: undefined;
|
||||
const relays = tag.length > 2 ? [tag[2]] : undefined;
|
||||
switch (tag[0]) {
|
||||
case "e": {
|
||||
return new NostrLink(NostrPrefix.Event, tag[1], undefined, undefined, relays);
|
||||
|
@ -233,7 +233,7 @@ export class RequestFilterBuilder {
|
||||
* Get event from link
|
||||
*/
|
||||
link(link: NostrLink) {
|
||||
if(link.type === NostrPrefix.Address) {
|
||||
if (link.type === NostrPrefix.Address) {
|
||||
return this.tag("d", [link.id])
|
||||
.kinds([unwrap(link.kind)])
|
||||
.authors([unwrap(link.author)]);
|
||||
@ -246,7 +246,7 @@ export class RequestFilterBuilder {
|
||||
* Get replies to link with e/a tags
|
||||
*/
|
||||
replyToLink(link: NostrLink) {
|
||||
if(link.type === NostrPrefix.Address) {
|
||||
if (link.type === NostrPrefix.Address) {
|
||||
return this.tag("a", [`${link.kind}:${link.author}:${link.id}`]);
|
||||
} else {
|
||||
return this.tag("e", [link.id]);
|
||||
|
Loading…
Reference in New Issue
Block a user