mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-18 03:03:31 +00:00
clean up
This commit is contained in:
parent
fc8dc8fd0d
commit
beb622f05e
@ -27,7 +27,6 @@
|
||||
"emoji-mart": "^5.5.2",
|
||||
"framer-motion": "^9.1.7",
|
||||
"jotai": "^2.0.3",
|
||||
"jotai-cache": "^0.3.0",
|
||||
"next": "^13.2.4",
|
||||
"nostr-relaypool": "^0.5.18",
|
||||
"nostr-tools": "^1.8.1",
|
||||
@ -37,7 +36,6 @@
|
||||
"react-player": "^2.12.0",
|
||||
"react-string-replace": "^1.1.0",
|
||||
"react-virtuoso": "^4.1.1",
|
||||
"tauri-plugin-sql-api": "github:tauri-apps/tauri-plugin-sql",
|
||||
"unique-names-generator": "^4.7.1",
|
||||
"ws": "^8.13.0"
|
||||
},
|
||||
|
@ -32,7 +32,6 @@ specifiers:
|
||||
framer-motion: ^9.1.7
|
||||
husky: ^8.0.3
|
||||
jotai: ^2.0.3
|
||||
jotai-cache: ^0.3.0
|
||||
lint-staged: ^13.2.0
|
||||
next: ^13.2.4
|
||||
nostr-relaypool: ^0.5.18
|
||||
@ -48,7 +47,6 @@ specifiers:
|
||||
react-string-replace: ^1.1.0
|
||||
react-virtuoso: ^4.1.1
|
||||
tailwindcss: ^3.3.1
|
||||
tauri-plugin-sql-api: github:tauri-apps/tauri-plugin-sql
|
||||
typescript: ^4.9.5
|
||||
unique-names-generator: ^4.7.1
|
||||
ws: ^8.13.0
|
||||
@ -69,7 +67,6 @@ dependencies:
|
||||
emoji-mart: 5.5.2
|
||||
framer-motion: 9.1.7_biqbaboplfbrettd7655fr4n2y
|
||||
jotai: 2.0.3_react@18.2.0
|
||||
jotai-cache: 0.3.0_jotai@2.0.3
|
||||
next: 13.2.4_biqbaboplfbrettd7655fr4n2y
|
||||
nostr-relaypool: 0.5.18_ws@8.13.0
|
||||
nostr-tools: 1.8.1
|
||||
@ -79,7 +76,6 @@ dependencies:
|
||||
react-player: 2.12.0_react@18.2.0
|
||||
react-string-replace: 1.1.0
|
||||
react-virtuoso: 4.1.1_biqbaboplfbrettd7655fr4n2y
|
||||
tauri-plugin-sql-api: github.com/tauri-apps/tauri-plugin-sql/3a8b9a6b244df7512bc5ef8692cebdedbab3ccce
|
||||
unique-names-generator: 4.7.1
|
||||
ws: 8.13.0
|
||||
|
||||
@ -3231,15 +3227,6 @@ packages:
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
||||
/jotai-cache/0.3.0_jotai@2.0.3:
|
||||
resolution:
|
||||
{ integrity: sha512-hV6DUD1frRpW0EN8Ss7n4KNaMZRBokQw6KPT3seA4P35QRXctMNUn4pHRlg3hzO+KBPpEZw+fyKlWAqagmuIwQ== }
|
||||
peerDependencies:
|
||||
jotai: '>=1.11.0'
|
||||
dependencies:
|
||||
jotai: 2.0.3_react@18.2.0
|
||||
dev: false
|
||||
|
||||
/jotai/2.0.3_react@18.2.0:
|
||||
resolution:
|
||||
{ integrity: sha512-MMjhSPAL3RoeZD9WbObufRT2quThEAEknHHridf2ma8Ml7ZVQmUiHk0ssdbR3F0h3kcwhYqSGJ59OjhPge7RRg== }
|
||||
@ -4995,14 +4982,3 @@ packages:
|
||||
{ integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== }
|
||||
engines: { node: '>=10' }
|
||||
dev: true
|
||||
|
||||
github.com/tauri-apps/tauri-plugin-sql/3a8b9a6b244df7512bc5ef8692cebdedbab3ccce:
|
||||
resolution:
|
||||
{
|
||||
tarball: https://codeload.github.com/tauri-apps/tauri-plugin-sql/tar.gz/3a8b9a6b244df7512bc5ef8692cebdedbab3ccce,
|
||||
}
|
||||
name: tauri-plugin-sql-api
|
||||
version: 0.0.0
|
||||
dependencies:
|
||||
'@tauri-apps/api': 1.2.0
|
||||
dev: false
|
||||
|
@ -2,12 +2,11 @@ import EmojiPicker from '@components/form/emojiPicker';
|
||||
import ImagePicker from '@components/form/imagePicker';
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
|
||||
import { activeAccountAtom } from '@stores/account';
|
||||
import { noteContentAtom } from '@stores/note';
|
||||
|
||||
import { dateToUnix } from '@utils/getDate';
|
||||
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useAtom } from 'jotai';
|
||||
import { useResetAtom } from 'jotai/utils';
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
import { useContext } from 'react';
|
||||
@ -15,23 +14,21 @@ import { useContext } from 'react';
|
||||
export default function FormBase() {
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const activeAccount: any = useAtomValue(activeAccountAtom);
|
||||
const [value, setValue] = useAtom(noteContentAtom);
|
||||
const resetValue = useResetAtom(noteContentAtom);
|
||||
|
||||
const pubkey = activeAccount.id;
|
||||
const privkey = activeAccount.privkey;
|
||||
|
||||
const submitEvent = () => {
|
||||
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
||||
|
||||
const event: any = {
|
||||
content: value,
|
||||
created_at: dateToUnix(),
|
||||
kind: 1,
|
||||
pubkey: pubkey,
|
||||
pubkey: activeAccount.pubkey,
|
||||
tags: [],
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, privkey);
|
||||
event.sig = signEvent(event, activeAccount.privkey);
|
||||
|
||||
// publish note
|
||||
pool.publish(event, relays);
|
||||
|
@ -23,7 +23,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
|
||||
content: value,
|
||||
created_at: dateToUnix(),
|
||||
kind: 1,
|
||||
pubkey: activeAccount.id,
|
||||
pubkey: activeAccount.pubkey,
|
||||
tags: [['e', eventID]],
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
@ -42,7 +42,7 @@ export default function FormComment({ eventID }: { eventID: any }) {
|
||||
<div className="relative h-11 w-11 shrink-0 overflow-hidden rounded-md border border-white/10">
|
||||
<ImageWithFallback
|
||||
src={profile?.picture}
|
||||
alt={activeAccount.id}
|
||||
alt={activeAccount.pubkey}
|
||||
fill={true}
|
||||
className="rounded-md object-cover"
|
||||
/>
|
||||
|
@ -19,11 +19,11 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
||||
const userData = JSON.parse(user.metadata);
|
||||
|
||||
const openProfilePage = () => {
|
||||
router.push(`/users/${user.id}`);
|
||||
router.push(`/users/${user.pubkey}`);
|
||||
};
|
||||
|
||||
const copyPublicKey = async () => {
|
||||
await writeText(nip19.npubEncode(user.id));
|
||||
await writeText(nip19.npubEncode(user.pubkey));
|
||||
};
|
||||
|
||||
const insertFollowsToStorage = useCallback(
|
||||
@ -46,7 +46,7 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
||||
[
|
||||
{
|
||||
kinds: [3],
|
||||
authors: [user.id],
|
||||
authors: [user.pubkey],
|
||||
},
|
||||
],
|
||||
relays,
|
||||
@ -65,7 +65,7 @@ export const ActiveAccount = memo(function ActiveAccount({ user }: { user: any }
|
||||
return () => {
|
||||
unsubscribe;
|
||||
};
|
||||
}, [insertFollowsToStorage, pool, relays, user.id]);
|
||||
}, [insertFollowsToStorage, pool, relays, user.pubkey]);
|
||||
|
||||
return (
|
||||
<DropdownMenu.Root>
|
||||
|
@ -12,13 +12,13 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
export default function MultiAccounts() {
|
||||
const [users, setUsers] = useState([]);
|
||||
|
||||
const renderAccount = useCallback((user: { id: string }) => {
|
||||
const renderAccount = useCallback((user: { pubkey: string }) => {
|
||||
const activeAccount = JSON.parse(localStorage.getItem('activeAccount'));
|
||||
|
||||
if (user.id === activeAccount.id) {
|
||||
return <ActiveAccount key={user.id} user={user} />;
|
||||
if (user.pubkey === activeAccount.pubkey) {
|
||||
return <ActiveAccount key={user.pubkey} user={user} />;
|
||||
} else {
|
||||
return <InactiveAccount key={user.id} user={user} />;
|
||||
return <InactiveAccount key={user.pubkey} user={user} />;
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
@ -3,7 +3,6 @@ import { RelayContext } from '@components/relaysProvider';
|
||||
import { UserExtend } from '@components/user/extend';
|
||||
|
||||
import { activeAccountAtom } from '@stores/account';
|
||||
import { relaysAtom } from '@stores/relays';
|
||||
|
||||
import { dateToUnix } from '@utils/getDate';
|
||||
|
||||
@ -33,11 +32,10 @@ export const NoteComment = memo(function NoteComment({
|
||||
const router = useRouter();
|
||||
const [pool, relays]: any = useContext(RelayContext);
|
||||
|
||||
const activeAccount: any = useAtomValue(activeAccountAtom);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [value, setValue] = useState('');
|
||||
|
||||
const activeAccount: any = useAtomValue(activeAccountAtom);
|
||||
const profile = destr(activeAccount.metadata);
|
||||
|
||||
const openThread = () => {
|
||||
@ -49,7 +47,7 @@ export const NoteComment = memo(function NoteComment({
|
||||
content: value,
|
||||
created_at: dateToUnix(),
|
||||
kind: 1,
|
||||
pubkey: activeAccount.id,
|
||||
pubkey: activeAccount.pubkey,
|
||||
tags: [['e', eventID]],
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
|
@ -38,7 +38,7 @@ export const NoteReaction = memo(function NoteReaction({
|
||||
['p', eventPubkey],
|
||||
],
|
||||
created_at: dateToUnix(),
|
||||
pubkey: activeAccount.id,
|
||||
pubkey: activeAccount.pubkey,
|
||||
};
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, activeAccount.privkey);
|
||||
|
@ -2,8 +2,6 @@ import { NoteComment } from '@components/note/meta/comment';
|
||||
import { NoteReaction } from '@components/note/meta/reaction';
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
|
||||
import { createCacheCommentNote } from '@utils/storage';
|
||||
|
||||
import { useContext, useEffect, useState } from 'react';
|
||||
|
||||
export default function NoteMetadata({
|
||||
@ -39,7 +37,7 @@ export default function NoteMetadata({
|
||||
// update state
|
||||
setComments((comments) => (comments += 1));
|
||||
// save comment to database
|
||||
createCacheCommentNote(event, eventID);
|
||||
// createCacheCommentNote(event, eventID);
|
||||
break;
|
||||
case 7:
|
||||
if (event.content === '🤙' || event.content === '+') {
|
||||
|
@ -45,7 +45,7 @@ export const NoteParent = memo(function NoteParent({ id }: { id: string }) {
|
||||
parent_id: parentID,
|
||||
parent_comment_id: '',
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
account_id: activeAccount.pubkey,
|
||||
}).catch(console.error);
|
||||
},
|
||||
undefined,
|
||||
|
@ -41,7 +41,7 @@ export const NoteRepost = memo(function NoteRepost({ id }: { id: string }) {
|
||||
parent_id: parentID,
|
||||
parent_comment_id: '',
|
||||
created_at: event.created_at,
|
||||
account_id: activeAccount.id,
|
||||
account_id: activeAccount.pubkey,
|
||||
}).catch(console.error);
|
||||
},
|
||||
undefined,
|
||||
|
@ -6,8 +6,6 @@ import { NoteComment } from '@components/note/comment';
|
||||
import { NoteExtend } from '@components/note/extend';
|
||||
import { RelayContext } from '@components/relaysProvider';
|
||||
|
||||
import { getAllCommentNotes, getNoteByID } from '@utils/storage';
|
||||
|
||||
import { useRouter } from 'next/router';
|
||||
import {
|
||||
JSXElementConstructor,
|
||||
@ -29,12 +27,12 @@ export default function Page() {
|
||||
const [comments, setComments] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
getNoteByID(id)
|
||||
/*getNoteByID(id)
|
||||
.then((res) => {
|
||||
setRootEvent(res);
|
||||
getAllCommentNotes(id).then((res: any) => setComments(res));
|
||||
})
|
||||
.catch(console.error);
|
||||
.catch(console.error);*/
|
||||
}, [id, pool, relays]);
|
||||
|
||||
return (
|
||||
|
@ -1,175 +0,0 @@
|
||||
import { getParentID } from '@utils/transform';
|
||||
|
||||
import Database from 'tauri-plugin-sql-api';
|
||||
|
||||
let db: null | Database = null;
|
||||
|
||||
// connect database (sqlite)
|
||||
// path: tauri::api::path::BaseDirectory::App
|
||||
export async function connect(): Promise<Database> {
|
||||
if (db) {
|
||||
return db;
|
||||
}
|
||||
db = await Database.load('sqlite:lume.db');
|
||||
return db;
|
||||
}
|
||||
|
||||
// get all relays
|
||||
export async function getAllRelays() {
|
||||
const db = await connect();
|
||||
const result: any = await db.select('SELECT relay_url FROM relays WHERE relay_status = "1";');
|
||||
return result.reduce((relays, { relay_url }) => {
|
||||
relays.push(relay_url);
|
||||
return relays;
|
||||
}, []);
|
||||
}
|
||||
|
||||
// get active account
|
||||
export async function getActiveAccount() {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT * FROM accounts LIMIT 1;`);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// get all accounts
|
||||
export async function getAccounts() {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT * FROM accounts`);
|
||||
}
|
||||
|
||||
// get all follows by account id
|
||||
export async function getAllFollowsByID(id) {
|
||||
const db = await connect();
|
||||
return await db.select(`SELECT pubkey FROM follows WHERE account = "${id}";`);
|
||||
}
|
||||
|
||||
// create account
|
||||
export async function createAccount(data) {
|
||||
const db = await connect();
|
||||
return await db.execute(
|
||||
'INSERT OR IGNORE INTO accounts (id, privkey, npub, nsec, metadata) VALUES (?, ?, ?, ?, ?);',
|
||||
[data.pubkey, data.privkey, data.npub, data.nsec, data.metadata]
|
||||
);
|
||||
}
|
||||
|
||||
// create follow
|
||||
export async function createFollow(pubkey, account, kind) {
|
||||
const db = await connect();
|
||||
return await db.execute('INSERT OR IGNORE INTO follows (pubkey, account, kind) VALUES (?, ?, ?);', [
|
||||
pubkey,
|
||||
account,
|
||||
kind || 0,
|
||||
]);
|
||||
}
|
||||
|
||||
// create follow
|
||||
export async function createFollows(data, account, kind) {
|
||||
const db = await connect();
|
||||
data.forEach(async (item) => {
|
||||
await db.execute('INSERT OR IGNORE INTO follows (pubkey, account, kind) VALUES (?, ?, ?);', [
|
||||
item,
|
||||
account,
|
||||
kind || 0,
|
||||
]);
|
||||
});
|
||||
return 'ok';
|
||||
}
|
||||
|
||||
// create cache profile
|
||||
export async function createCacheProfile(id, metadata) {
|
||||
const db = await connect();
|
||||
return await db.execute('INSERT OR IGNORE INTO cache_profiles (id, metadata) VALUES (?, ?);', [id, metadata]);
|
||||
}
|
||||
|
||||
// get cache profile
|
||||
export async function getCacheProfile(id) {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT metadata FROM cache_profiles WHERE id = "${id}"`);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// get all notes
|
||||
export async function getNotes(time, limit, offset) {
|
||||
const db = await connect();
|
||||
return await db.select(
|
||||
`SELECT * FROM cache_notes WHERE created_at <= "${time}" GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}"`
|
||||
);
|
||||
}
|
||||
|
||||
// get all latest notes
|
||||
export async function getLatestNotes(time) {
|
||||
const db = await connect();
|
||||
return await db.select(
|
||||
`SELECT * FROM cache_notes WHERE created_at > "${time}" GROUP BY parent_id ORDER BY created_at DESC`
|
||||
);
|
||||
}
|
||||
|
||||
// get note by id
|
||||
export async function getNoteByID(id) {
|
||||
const db = await connect();
|
||||
const result = await db.select(`SELECT * FROM cache_notes WHERE id = "${id}"`);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// create cache note
|
||||
export async function createCacheNote(data) {
|
||||
const db = await connect();
|
||||
return await db.execute(
|
||||
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?);',
|
||||
[
|
||||
data.id,
|
||||
data.pubkey,
|
||||
data.created_at,
|
||||
data.kind,
|
||||
data.content,
|
||||
JSON.stringify(data.tags),
|
||||
getParentID(data.tags, data.id),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// get all comment notes
|
||||
export async function getAllCommentNotes(eid) {
|
||||
const db = await connect();
|
||||
return await db.select(
|
||||
`SELECT * FROM cache_notes WHERE parent_comment_id = "${eid}" ORDER BY created_at DESC LIMIT 500`
|
||||
);
|
||||
}
|
||||
|
||||
// create cache comment note
|
||||
export async function createCacheCommentNote(data, eid) {
|
||||
const db = await connect();
|
||||
return await db.execute(
|
||||
'INSERT OR IGNORE INTO cache_notes (id, pubkey, created_at, kind, content, tags, parent_id, parent_comment_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);',
|
||||
[
|
||||
data.id,
|
||||
data.pubkey,
|
||||
data.created_at,
|
||||
data.kind,
|
||||
data.content,
|
||||
JSON.stringify(data.tags),
|
||||
getParentID(data.tags, data.id),
|
||||
eid,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// create cache comment note
|
||||
export async function countTotalNotes() {
|
||||
const db = await connect();
|
||||
const result = await db.select('SELECT COUNT(*) AS "total" FROM cache_notes;');
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// get last login time
|
||||
export async function getLastLoginTime() {
|
||||
const db = await connect();
|
||||
const result = await db.select('SELECT setting_value FROM settings WHERE setting_key = "last_login"');
|
||||
return result[0];
|
||||
}
|
||||
|
||||
// update last login time
|
||||
export async function updateLastLoginTime(time) {
|
||||
const db = await connect();
|
||||
return await db.execute(`UPDATE settings SET setting_value = "${time}" WHERE setting_key = "last_login"`);
|
||||
}
|
Loading…
Reference in New Issue
Block a user