mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 19:46:34 +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 { NoteRepost } from "@app/note/components/metadata/repost";
|
||||||
import { NoteZap } from "@app/note/components/metadata/zap";
|
import { NoteZap } from "@app/note/components/metadata/zap";
|
||||||
import { RelayContext } from "@shared/relayProvider";
|
import { RelayContext } from "@shared/relayProvider";
|
||||||
|
import { useActiveAccount } from "@stores/accounts";
|
||||||
import { READONLY_RELAYS } from "@stores/constants";
|
import { READONLY_RELAYS } from "@stores/constants";
|
||||||
|
import { createReplyNote } from "@utils/storage";
|
||||||
import { decode } from "light-bolt11-decoder";
|
import { decode } from "light-bolt11-decoder";
|
||||||
import { useContext, useState } from "react";
|
import { useContext, useState } from "react";
|
||||||
import useSWRSubscription from "swr/subscription";
|
import useSWRSubscription from "swr/subscription";
|
||||||
@ -15,6 +17,7 @@ export function NoteMetadata({
|
|||||||
eventPubkey: string;
|
eventPubkey: string;
|
||||||
}) {
|
}) {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
|
const account = useActiveAccount((state: any) => state.account);
|
||||||
|
|
||||||
const [replies, setReplies] = useState(0);
|
const [replies, setReplies] = useState(0);
|
||||||
const [reposts, setReposts] = useState(0);
|
const [reposts, setReposts] = useState(0);
|
||||||
@ -25,7 +28,6 @@ export function NoteMetadata({
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"#e": [key],
|
"#e": [key],
|
||||||
since: 0,
|
|
||||||
kinds: [1, 6, 9735],
|
kinds: [1, 6, 9735],
|
||||||
limit: 20,
|
limit: 20,
|
||||||
},
|
},
|
||||||
@ -35,6 +37,16 @@ export function NoteMetadata({
|
|||||||
switch (event.kind) {
|
switch (event.kind) {
|
||||||
case 1:
|
case 1:
|
||||||
setReplies((replies) => replies + 1);
|
setReplies((replies) => replies + 1);
|
||||||
|
createReplyNote(
|
||||||
|
event.id,
|
||||||
|
account.id,
|
||||||
|
event.pubkey,
|
||||||
|
event.kind,
|
||||||
|
event.tags,
|
||||||
|
event.content,
|
||||||
|
event.created_at,
|
||||||
|
key,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
setReposts((reposts) => reposts + 1);
|
setReposts((reposts) => reposts + 1);
|
||||||
@ -54,6 +66,11 @@ export function NoteMetadata({
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
|
unsubscribeOnEose: true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -18,13 +18,5 @@ export function NoteWrapper({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <div className={className}>{children}</div>;
|
||||||
<div
|
|
||||||
onClick={(event) => openThread(event, href)}
|
|
||||||
onKeyDown={(event) => openThread(event, href)}
|
|
||||||
className={className}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ export function Page() {
|
|||||||
|
|
||||||
// kind 1 (notes) query
|
// kind 1 (notes) query
|
||||||
query.push({
|
query.push({
|
||||||
kinds: [1, 6, 1063],
|
kinds: [1, 6],
|
||||||
authors: follows,
|
authors: follows,
|
||||||
since: queryNoteSince,
|
since: queryNoteSince,
|
||||||
});
|
});
|
||||||
@ -87,7 +87,6 @@ export function Page() {
|
|||||||
switch (event.kind) {
|
switch (event.kind) {
|
||||||
// short text note
|
// short text note
|
||||||
case 1: {
|
case 1: {
|
||||||
const parentID = getParentID(event.tags, event.id);
|
|
||||||
// insert event to local database
|
// insert event to local database
|
||||||
createNote(
|
createNote(
|
||||||
event.id,
|
event.id,
|
||||||
@ -97,7 +96,6 @@ export function Page() {
|
|||||||
event.tags,
|
event.tags,
|
||||||
event.content,
|
event.content,
|
||||||
event.created_at,
|
event.created_at,
|
||||||
parentID,
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -135,7 +133,6 @@ export function Page() {
|
|||||||
event.tags,
|
event.tags,
|
||||||
event.content,
|
event.content,
|
||||||
event.created_at,
|
event.created_at,
|
||||||
event.id,
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
// hide message (channel only)
|
// hide message (channel only)
|
||||||
@ -150,19 +147,6 @@ export function Page() {
|
|||||||
addToBlacklist(account.id, event.tags[0][1], 44, 1);
|
addToBlacklist(account.id, event.tags[0][1], 44, 1);
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -177,6 +161,9 @@ export function Page() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
unsubscribeOnEose: true,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -33,13 +33,13 @@ export function AddBlock() {
|
|||||||
leaveFrom="transform opacity-100 scale-100"
|
leaveFrom="transform opacity-100 scale-100"
|
||||||
leaveTo="transform opacity-0 scale-95"
|
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">
|
<div className="px-1 py-1">
|
||||||
<Menu.Item>
|
<Menu.Item>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => openAddImageModal()}
|
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" />
|
<ImageIcon width={15} height={15} className="mr-2" />
|
||||||
Add image
|
Add image
|
||||||
@ -49,7 +49,7 @@ export function AddBlock() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => openAddFeedModal()}
|
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" />
|
<FeedIcon width={15} height={15} className="mr-2" />
|
||||||
Add feed
|
Add feed
|
||||||
|
@ -4,14 +4,18 @@ import { useActiveAccount } from "@stores/accounts";
|
|||||||
import { useChannels } from "@stores/channels";
|
import { useChannels } from "@stores/channels";
|
||||||
import { useChatMessages, useChats } from "@stores/chats";
|
import { useChatMessages, useChats } from "@stores/chats";
|
||||||
import { DEFAULT_AVATAR, READONLY_RELAYS } from "@stores/constants";
|
import { DEFAULT_AVATAR, READONLY_RELAYS } from "@stores/constants";
|
||||||
|
import { dateToUnix } from "@utils/date";
|
||||||
import { usePageContext } from "@utils/hooks/usePageContext";
|
import { usePageContext } from "@utils/hooks/usePageContext";
|
||||||
import { useProfile } from "@utils/hooks/useProfile";
|
import { useProfile } from "@utils/hooks/useProfile";
|
||||||
import { sendNativeNotification } from "@utils/notification";
|
import { sendNativeNotification } from "@utils/notification";
|
||||||
|
import { createNote } from "@utils/storage";
|
||||||
import { useContext } from "react";
|
import { useContext } from "react";
|
||||||
import useSWRSubscription from "swr/subscription";
|
import useSWRSubscription from "swr/subscription";
|
||||||
|
|
||||||
export function ActiveAccount({ data }: { data: any }) {
|
export function ActiveAccount({ data }: { data: any }) {
|
||||||
const pool: any = useContext(RelayContext);
|
const pool: any = useContext(RelayContext);
|
||||||
|
const account = useActiveAccount((state: any) => state.account);
|
||||||
|
|
||||||
const pageContext = usePageContext();
|
const pageContext = usePageContext();
|
||||||
const pathname: any = pageContext.urlParsed.pathname;
|
const pathname: any = pageContext.urlParsed.pathname;
|
||||||
|
|
||||||
@ -27,11 +31,17 @@ export function ActiveAccount({ data }: { data: any }) {
|
|||||||
const { user } = useProfile(data.pubkey);
|
const { user } = useProfile(data.pubkey);
|
||||||
|
|
||||||
useSWRSubscription(
|
useSWRSubscription(
|
||||||
user && lastLogin > 0 ? ["account", data.pubkey] : null,
|
user && lastLogin > 0 ? ["activeAccount", data.pubkey] : null,
|
||||||
() => {
|
() => {
|
||||||
|
const follows = JSON.parse(account.follows);
|
||||||
// subscribe to channel
|
// subscribe to channel
|
||||||
const unsubscribe = pool.subscribe(
|
const unsubscribe = pool.subscribe(
|
||||||
[
|
[
|
||||||
|
{
|
||||||
|
kinds: [1, 6],
|
||||||
|
authors: follows,
|
||||||
|
since: dateToUnix(),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"#p": [data.pubkey],
|
"#p": [data.pubkey],
|
||||||
since: lastLogin,
|
since: lastLogin,
|
||||||
@ -41,7 +51,18 @@ export function ActiveAccount({ data }: { data: any }) {
|
|||||||
(event) => {
|
(event) => {
|
||||||
switch (event.kind) {
|
switch (event.kind) {
|
||||||
case 1:
|
case 1:
|
||||||
|
case 6: {
|
||||||
|
createNote(
|
||||||
|
event.id,
|
||||||
|
account.id,
|
||||||
|
event.pubkey,
|
||||||
|
event.kind,
|
||||||
|
event.tags,
|
||||||
|
event.content,
|
||||||
|
event.created_at,
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 4:
|
case 4:
|
||||||
if (!isChatPage) {
|
if (!isChatPage) {
|
||||||
// save
|
// 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.tags,
|
||||||
event.content,
|
event.content,
|
||||||
event.created_at,
|
event.created_at,
|
||||||
parentID,
|
|
||||||
);
|
);
|
||||||
// update state
|
// update state
|
||||||
next(null, event);
|
next(null, event);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { getParentID } from "@utils/transform";
|
||||||
import { nip19 } from "nostr-tools";
|
import { nip19 } from "nostr-tools";
|
||||||
import Database from "tauri-plugin-sql-api";
|
import Database from "tauri-plugin-sql-api";
|
||||||
|
|
||||||
@ -221,12 +222,41 @@ export async function createNote(
|
|||||||
tags: string[],
|
tags: string[],
|
||||||
content: string,
|
content: string,
|
||||||
created_at: number,
|
created_at: number,
|
||||||
parent_id: string,
|
|
||||||
) {
|
) {
|
||||||
const db = await connect();
|
const db = await connect();
|
||||||
|
const parentID = getParentID(tags, event_id);
|
||||||
return await db.execute(
|
return await db.execute(
|
||||||
"INSERT INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
|
"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