mirror of
https://github.com/lumehq/lume.git
synced 2025-03-18 22:01:43 +01:00
add kind 30023 to initial data
This commit is contained in:
parent
f46f4530a6
commit
730f3be016
src
@ -4,6 +4,7 @@ import { READONLY_RELAYS } from '@lume/stores/constants';
|
||||
import { dateToUnix, hoursAgo } from '@lume/utils/getDate';
|
||||
import {
|
||||
addToBlacklist,
|
||||
countTotalLongNotes,
|
||||
countTotalNotes,
|
||||
createChat,
|
||||
createNote,
|
||||
@ -28,19 +29,31 @@ export function Page() {
|
||||
const account = await getActiveAccount();
|
||||
const lastLogin = await getLastLogin();
|
||||
const notes = await countTotalNotes();
|
||||
const longNotes = await countTotalLongNotes();
|
||||
|
||||
const follows = nip02ToArray(JSON.parse(account.follows));
|
||||
const query = [];
|
||||
|
||||
let since: number;
|
||||
let sinceNotes: number;
|
||||
let sinceLongNotes: number;
|
||||
|
||||
if (notes === 0) {
|
||||
since = dateToUnix(hoursAgo(24, now.current));
|
||||
sinceNotes = dateToUnix(hoursAgo(48, now.current));
|
||||
} else {
|
||||
if (parseInt(lastLogin) > 0) {
|
||||
since = parseInt(lastLogin);
|
||||
sinceNotes = parseInt(lastLogin);
|
||||
} else {
|
||||
since = dateToUnix(hoursAgo(24, now.current));
|
||||
sinceNotes = dateToUnix(hoursAgo(48, now.current));
|
||||
}
|
||||
}
|
||||
|
||||
if (longNotes === 0) {
|
||||
sinceLongNotes = 0;
|
||||
} else {
|
||||
if (parseInt(lastLogin) > 0) {
|
||||
sinceLongNotes = parseInt(lastLogin);
|
||||
} else {
|
||||
sinceLongNotes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +61,7 @@ export function Page() {
|
||||
query.push({
|
||||
kinds: [1, 6],
|
||||
authors: follows,
|
||||
since: since,
|
||||
since: sinceNotes,
|
||||
until: dateToUnix(now.current),
|
||||
});
|
||||
|
||||
@ -68,6 +81,13 @@ export function Page() {
|
||||
until: dateToUnix(now.current),
|
||||
});
|
||||
|
||||
// kind 30023 (long post) query
|
||||
query.push({
|
||||
kinds: [30023],
|
||||
since: sinceLongNotes,
|
||||
until: dateToUnix(now.current),
|
||||
});
|
||||
|
||||
// subscribe relays
|
||||
unsubscribe = pool.subscribe(
|
||||
query,
|
||||
@ -113,11 +133,27 @@ export function Page() {
|
||||
if (event.tags[0][0] === 'e') {
|
||||
addToBlacklist(account.id, event.tags[0][1], 43, 1);
|
||||
}
|
||||
break;
|
||||
// mute user (channel only)
|
||||
case 44:
|
||||
if (event.tags[0][0] === 'p') {
|
||||
addToBlacklist(account.id, event.tags[0][1], 44, 1);
|
||||
}
|
||||
break;
|
||||
// long post
|
||||
case 30023:
|
||||
// insert event to local database
|
||||
createNote(
|
||||
event.id,
|
||||
account.id,
|
||||
event.pubkey,
|
||||
event.kind,
|
||||
event.tags,
|
||||
event.content,
|
||||
event.created_at,
|
||||
''
|
||||
);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import { shortenKey } from '@lume/utils/shortenKey';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
import Skeleton from 'react-loading-skeleton';
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
@ -24,7 +25,7 @@ export const NoteDefaultUser = ({ pubkey, time }: { pubkey: string; time: number
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex items-baseline gap-2">
|
||||
<h5 className="text-sm font-semibold leading-none group-hover:underline">
|
||||
{user?.display_name || shortenKey(pubkey)}
|
||||
{user?.display_name || user?.name || <Skeleton />}
|
||||
</h5>
|
||||
</div>
|
||||
<div className="flex items-baseline gap-1.5 text-sm leading-none text-zinc-500">
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Image } from '@lume/shared/image';
|
||||
import { DEFAULT_AVATAR, IMGPROXY_URL } from '@lume/stores/constants';
|
||||
import { useProfile } from '@lume/utils/hooks/useProfile';
|
||||
import { shortenKey } from '@lume/utils/shortenKey';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
import relativeTime from 'dayjs/plugin/relativeTime';
|
||||
import Skeleton from 'react-loading-skeleton';
|
||||
|
||||
dayjs.extend(relativeTime);
|
||||
|
||||
@ -22,8 +22,9 @@ export const NoteRepostUser = ({ pubkey, time }: { pubkey: string; time: number
|
||||
</div>
|
||||
<div className="flex items-baseline gap-2 text-sm">
|
||||
<h5 className="font-semibold leading-tight group-hover:underline">
|
||||
{user?.display_name || user?.name || shortenKey(pubkey)}{' '}
|
||||
{user?.display_name || user?.name || <Skeleton />}
|
||||
<span className="bg-gradient-to-r from-fuchsia-300 via-orange-100 to-amber-300 bg-clip-text text-transparent">
|
||||
{' '}
|
||||
reposted
|
||||
</span>
|
||||
</h5>
|
||||
|
@ -76,7 +76,14 @@ export async function countTotalChannels() {
|
||||
// count total notes
|
||||
export async function countTotalNotes() {
|
||||
const db = await connect();
|
||||
const result = await db.select('SELECT COUNT(*) AS "total" FROM notes;');
|
||||
const result = await db.select('SELECT COUNT(*) AS "total" FROM notes WHERE kind IN (1, 6);');
|
||||
return result[0].total;
|
||||
}
|
||||
|
||||
// count total notes
|
||||
export async function countTotalLongNotes() {
|
||||
const db = await connect();
|
||||
const result = await db.select('SELECT COUNT(*) AS "total" FROM notes WHERE kind = 30023;');
|
||||
return result[0].total;
|
||||
}
|
||||
|
||||
@ -86,7 +93,22 @@ export async function getNotes(time: number, limit: number, offset: number) {
|
||||
|
||||
const notes: any = { data: null, nextCursor: 0 };
|
||||
const query: any = await db.select(
|
||||
`SELECT * FROM notes WHERE created_at <= "${time}" GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
|
||||
`SELECT * FROM notes WHERE created_at <= "${time}" AND kind IN (1, 6) GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
|
||||
);
|
||||
|
||||
notes['data'] = query;
|
||||
notes['nextCursor'] = offset + limit;
|
||||
|
||||
return notes;
|
||||
}
|
||||
|
||||
// get all long notes
|
||||
export async function getLongNotes(time: number, limit: number, offset: number) {
|
||||
const db = await connect();
|
||||
|
||||
const notes: any = { data: null, nextCursor: 0 };
|
||||
const query: any = await db.select(
|
||||
`SELECT * FROM notes WHERE created_at <= "${time}" AND kind = 30023 GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
|
||||
);
|
||||
|
||||
notes['data'] = query;
|
||||
|
Loading…
x
Reference in New Issue
Block a user