mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
minor updates
This commit is contained in:
parent
2f3ea13613
commit
75a33d205a
@ -2,7 +2,9 @@ import { NoteReply } from "@app/note/components/metadata/reply";
|
||||
import { NoteRepost } from "@app/note/components/metadata/repost";
|
||||
import { NoteZap } from "@app/note/components/metadata/zap";
|
||||
import { RelayContext } from "@shared/relayProvider";
|
||||
import { useActiveAccount } from "@stores/accounts";
|
||||
import { READONLY_RELAYS } from "@stores/constants";
|
||||
import { createReplyNote } from "@utils/storage";
|
||||
import { decode } from "light-bolt11-decoder";
|
||||
import { useContext, useState } from "react";
|
||||
import useSWRSubscription from "swr/subscription";
|
||||
@ -15,6 +17,7 @@ export function NoteMetadata({
|
||||
eventPubkey: string;
|
||||
}) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const account = useActiveAccount((state: any) => state.account);
|
||||
|
||||
const [replies, setReplies] = useState(0);
|
||||
const [reposts, setReposts] = useState(0);
|
||||
@ -25,7 +28,6 @@ export function NoteMetadata({
|
||||
[
|
||||
{
|
||||
"#e": [key],
|
||||
since: 0,
|
||||
kinds: [1, 6, 9735],
|
||||
limit: 20,
|
||||
},
|
||||
@ -35,6 +37,16 @@ export function NoteMetadata({
|
||||
switch (event.kind) {
|
||||
case 1:
|
||||
setReplies((replies) => replies + 1);
|
||||
createReplyNote(
|
||||
event.id,
|
||||
account.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
key,
|
||||
);
|
||||
break;
|
||||
case 6:
|
||||
setReposts((reposts) => reposts + 1);
|
||||
@ -54,6 +66,11 @@ export function NoteMetadata({
|
||||
break;
|
||||
}
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
unsubscribeOnEose: true,
|
||||
},
|
||||
);
|
||||
|
||||
return () => {
|
||||
|
@ -18,13 +18,5 @@ export function NoteWrapper({
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
onClick={(event) => openThread(event, href)}
|
||||
onKeyDown={(event) => openThread(event, href)}
|
||||
className={className}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
return <div className={className}>{children}</div>;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ export function Page() {
|
||||
|
||||
// kind 1 (notes) query
|
||||
query.push({
|
||||
kinds: [1, 6, 1063],
|
||||
kinds: [1, 6],
|
||||
authors: follows,
|
||||
since: queryNoteSince,
|
||||
});
|
||||
@ -87,7 +87,6 @@ export function Page() {
|
||||
switch (event.kind) {
|
||||
// short text note
|
||||
case 1: {
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
// insert event to local database
|
||||
createNote(
|
||||
event.id,
|
||||
@ -97,7 +96,6 @@ export function Page() {
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
parentID,
|
||||
);
|
||||
break;
|
||||
}
|
||||
@ -135,7 +133,6 @@ export function Page() {
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
event.id,
|
||||
);
|
||||
break;
|
||||
// hide message (channel only)
|
||||
@ -150,19 +147,6 @@ export function Page() {
|
||||
addToBlacklist(account.id, event.tags[0][1], 44, 1);
|
||||
}
|
||||
break;
|
||||
// file metadata
|
||||
case 1063:
|
||||
createNote(
|
||||
event.id,
|
||||
account.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
event.id,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -177,6 +161,9 @@ export function Page() {
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
unsubscribeOnEose: true,
|
||||
},
|
||||
);
|
||||
|
||||
return () => {
|
||||
|
@ -33,13 +33,13 @@ export function AddBlock() {
|
||||
leaveFrom="transform opacity-100 scale-100"
|
||||
leaveTo="transform opacity-0 scale-95"
|
||||
>
|
||||
<Menu.Items className="absolute mt-2 right-1/2 transform translate-x-1/2 w-56 origin-top-right rounded-md bg-zinc-900 ring-1 ring-zinc-800 focus:outline-none">
|
||||
<Menu.Items className="absolute mt-2 right-1/2 transform translate-x-1/2 w-56 origin-top-right rounded-md bg-zinc-900/80 backdrop-blur-md focus:outline-none">
|
||||
<div className="px-1 py-1">
|
||||
<Menu.Item>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openAddImageModal()}
|
||||
className="group flex w-full items-center rounded-md hover:bg-zinc-800 text-zinc-300 hover:text-zinc-100 px-2 py-2 text-sm"
|
||||
className="group flex w-full items-center rounded-md hover:bg-zinc-700/50 text-zinc-300 hover:text-zinc-100 px-2 py-2 text-sm"
|
||||
>
|
||||
<ImageIcon width={15} height={15} className="mr-2" />
|
||||
Add image
|
||||
@ -49,7 +49,7 @@ export function AddBlock() {
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openAddFeedModal()}
|
||||
className="group flex w-full items-center rounded-md hover:bg-zinc-800 text-zinc-300 hover:text-zinc-100 px-2 py-2 text-sm"
|
||||
className="group flex w-full items-center rounded-md hover:bg-zinc-700/50 text-zinc-300 hover:text-zinc-100 px-2 py-2 text-sm"
|
||||
>
|
||||
<FeedIcon width={15} height={15} className="mr-2" />
|
||||
Add feed
|
||||
|
@ -4,14 +4,18 @@ import { useActiveAccount } from "@stores/accounts";
|
||||
import { useChannels } from "@stores/channels";
|
||||
import { useChatMessages, useChats } from "@stores/chats";
|
||||
import { DEFAULT_AVATAR, READONLY_RELAYS } from "@stores/constants";
|
||||
import { dateToUnix } from "@utils/date";
|
||||
import { usePageContext } from "@utils/hooks/usePageContext";
|
||||
import { useProfile } from "@utils/hooks/useProfile";
|
||||
import { sendNativeNotification } from "@utils/notification";
|
||||
import { createNote } from "@utils/storage";
|
||||
import { useContext } from "react";
|
||||
import useSWRSubscription from "swr/subscription";
|
||||
|
||||
export function ActiveAccount({ data }: { data: any }) {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const account = useActiveAccount((state: any) => state.account);
|
||||
|
||||
const pageContext = usePageContext();
|
||||
const pathname: any = pageContext.urlParsed.pathname;
|
||||
|
||||
@ -27,11 +31,17 @@ export function ActiveAccount({ data }: { data: any }) {
|
||||
const { user } = useProfile(data.pubkey);
|
||||
|
||||
useSWRSubscription(
|
||||
user && lastLogin > 0 ? ["account", data.pubkey] : null,
|
||||
user && lastLogin > 0 ? ["activeAccount", data.pubkey] : null,
|
||||
() => {
|
||||
const follows = JSON.parse(account.follows);
|
||||
// subscribe to channel
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
kinds: [1, 6],
|
||||
authors: follows,
|
||||
since: dateToUnix(),
|
||||
},
|
||||
{
|
||||
"#p": [data.pubkey],
|
||||
since: lastLogin,
|
||||
@ -41,7 +51,18 @@ export function ActiveAccount({ data }: { data: any }) {
|
||||
(event) => {
|
||||
switch (event.kind) {
|
||||
case 1:
|
||||
case 6: {
|
||||
createNote(
|
||||
event.id,
|
||||
account.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
if (!isChatPage) {
|
||||
// save
|
||||
|
@ -1,72 +0,0 @@
|
||||
import { HeartBeatIcon } from "@shared/icons";
|
||||
import { RelayContext } from "@shared/relayProvider";
|
||||
import { useActiveAccount } from "@stores/accounts";
|
||||
import { READONLY_RELAYS } from "@stores/constants";
|
||||
import { dateToUnix } from "@utils/date";
|
||||
import { createNote } from "@utils/storage";
|
||||
import { getParentID } from "@utils/transform";
|
||||
import { useContext } from "react";
|
||||
import useSWRSubscription from "swr/subscription";
|
||||
|
||||
export function EventCollector() {
|
||||
const pool: any = useContext(RelayContext);
|
||||
const account = useActiveAccount((state: any) => state.account);
|
||||
|
||||
useSWRSubscription(account ? "eventCollector" : null, () => {
|
||||
const follows = JSON.parse(account.follows);
|
||||
const unsubscribe = pool.subscribe(
|
||||
[
|
||||
{
|
||||
kinds: [1, 6],
|
||||
authors: follows,
|
||||
since: dateToUnix(),
|
||||
},
|
||||
],
|
||||
READONLY_RELAYS,
|
||||
(event: any) => {
|
||||
switch (event.kind) {
|
||||
// short text note
|
||||
case 1: {
|
||||
const parentID = getParentID(event.tags, event.id);
|
||||
createNote(
|
||||
event.id,
|
||||
account.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
parentID,
|
||||
);
|
||||
break;
|
||||
}
|
||||
// repost
|
||||
case 6:
|
||||
createNote(
|
||||
event.id,
|
||||
account.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
event.id,
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="inline-flex h-6 w-6 items-center justify-center rounded text-zinc-500 hover:bg-zinc-900 hover:text-green-500">
|
||||
<HeartBeatIcon width={16} height={16} />
|
||||
</div>
|
||||
);
|
||||
}
|
@ -35,7 +35,6 @@ export function useEvent(id: string) {
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
parentID,
|
||||
);
|
||||
// update state
|
||||
next(null, event);
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { getParentID } from "@utils/transform";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import Database from "tauri-plugin-sql-api";
|
||||
|
||||
@ -221,12 +222,41 @@ export async function createNote(
|
||||
tags: string[],
|
||||
content: string,
|
||||
created_at: number,
|
||||
parent_id: string,
|
||||
) {
|
||||
const db = await connect();
|
||||
const parentID = getParentID(tags, event_id);
|
||||
return await db.execute(
|
||||
"INSERT INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
[event_id, account_id, pubkey, kind, tags, content, created_at, parent_id],
|
||||
[event_id, account_id, pubkey, kind, tags, content, created_at, parentID],
|
||||
);
|
||||
}
|
||||
|
||||
// create reply note
|
||||
export async function createReplyNote(
|
||||
event_id: string,
|
||||
account_id: number,
|
||||
pubkey: string,
|
||||
kind: number,
|
||||
tags: string[],
|
||||
content: string,
|
||||
created_at: number,
|
||||
parent_comment_id: string,
|
||||
) {
|
||||
const db = await connect();
|
||||
const parentID = getParentID(tags, event_id);
|
||||
return await db.execute(
|
||||
"INSERT INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id, parent_comment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);",
|
||||
[
|
||||
event_id,
|
||||
account_id,
|
||||
pubkey,
|
||||
kind,
|
||||
tags,
|
||||
content,
|
||||
created_at,
|
||||
parentID,
|
||||
parent_comment_id,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user