mirror of
https://github.com/luminous-devs/lume.git
synced 2024-09-19 11:43:30 +00:00
removed tauri event listener from event collector
This commit is contained in:
parent
5c01b91771
commit
fbd9627dc0
@ -0,0 +1,5 @@
|
|||||||
|
-- Add migration script here
|
||||||
|
INSERT INTO
|
||||||
|
settings (key, value)
|
||||||
|
VALUES
|
||||||
|
("last_login", "0");
|
@ -63,6 +63,12 @@ fn main() {
|
|||||||
sql: include_str!("../migrations/20230418080146_create_chats.sql"),
|
sql: include_str!("../migrations/20230418080146_create_chats.sql"),
|
||||||
kind: MigrationKind::Up,
|
kind: MigrationKind::Up,
|
||||||
},
|
},
|
||||||
|
Migration {
|
||||||
|
version: 20230420040005,
|
||||||
|
description: "insert last login to settings",
|
||||||
|
sql: include_str!("../migrations/20230420040005_insert_last_login_to_settings.sql"),
|
||||||
|
kind: MigrationKind::Up,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.build(),
|
.build(),
|
||||||
|
@ -10,21 +10,21 @@ import {
|
|||||||
createChat,
|
createChat,
|
||||||
createNote,
|
createNote,
|
||||||
getActiveAccount,
|
getActiveAccount,
|
||||||
|
getLastLogin,
|
||||||
getPlebs,
|
getPlebs,
|
||||||
|
updateLastLogin,
|
||||||
} from '@utils/storage';
|
} from '@utils/storage';
|
||||||
import { getParentID } from '@utils/transform';
|
import { getParentID } from '@utils/transform';
|
||||||
|
|
||||||
import LumeSymbol from '@assets/icons/Lume';
|
import LumeSymbol from '@assets/icons/Lume';
|
||||||
|
|
||||||
import useLocalStorage, { writeStorage } from '@rehooks/local-storage';
|
import { writeStorage } from '@rehooks/local-storage';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useCallback, useContext, useEffect, useRef } from 'react';
|
import { useCallback, useContext, useEffect, useRef } from 'react';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [pool, relays]: any = useContext(RelayContext);
|
const [pool, relays]: any = useContext(RelayContext);
|
||||||
const [lastLogin] = useLocalStorage('lastLogin', new Date());
|
|
||||||
|
|
||||||
const now = useRef(new Date());
|
const now = useRef(new Date());
|
||||||
const timeout = useRef(null);
|
const timeout = useRef(null);
|
||||||
@ -32,6 +32,7 @@ export default function Page() {
|
|||||||
|
|
||||||
const fetchData = useCallback(
|
const fetchData = useCallback(
|
||||||
async (account: { id: number; pubkey: string; chats: string[] }, tags: any) => {
|
async (account: { id: number; pubkey: string; chats: string[] }, tags: any) => {
|
||||||
|
const lastLogin = await getLastLogin();
|
||||||
const notes = await countTotalNotes();
|
const notes = await countTotalNotes();
|
||||||
const channels = await countTotalChannels();
|
const channels = await countTotalChannels();
|
||||||
const chats = account.chats?.length || 0;
|
const chats = account.chats?.length || 0;
|
||||||
@ -44,7 +45,11 @@ export default function Page() {
|
|||||||
if (notes.total === 0) {
|
if (notes.total === 0) {
|
||||||
since = dateToUnix(hoursAgo(24, now.current));
|
since = dateToUnix(hoursAgo(24, now.current));
|
||||||
} else {
|
} else {
|
||||||
since = dateToUnix(new Date(lastLogin));
|
if (parseInt(lastLogin) > 0) {
|
||||||
|
since = parseInt(lastLogin);
|
||||||
|
} else {
|
||||||
|
since = dateToUnix(hoursAgo(24, now.current));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
query.push({
|
query.push({
|
||||||
kinds: [1, 6],
|
kinds: [1, 6],
|
||||||
@ -119,7 +124,8 @@ export default function Page() {
|
|||||||
},
|
},
|
||||||
undefined,
|
undefined,
|
||||||
() => {
|
() => {
|
||||||
timeout.current = setTimeout(() => router.replace('/nostr/newsfeed/following'), 5000);
|
updateLastLogin(dateToUnix(now.current));
|
||||||
|
//timeout.current = setTimeout(() => router.replace('/nostr/newsfeed/following'), 5000);
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
unsubscribeOnEose: true,
|
unsubscribeOnEose: true,
|
||||||
@ -127,7 +133,7 @@ export default function Page() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[router, pool, relays, lastLogin]
|
[router, pool, relays]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -9,9 +9,7 @@ import { dateToUnix } from '@utils/getDate';
|
|||||||
import { createChannel, createChat, createNote, updateAccount } from '@utils/storage';
|
import { createChannel, createChat, createNote, updateAccount } from '@utils/storage';
|
||||||
import { getParentID, nip02ToArray } from '@utils/transform';
|
import { getParentID, nip02ToArray } from '@utils/transform';
|
||||||
|
|
||||||
import useLocalStorage, { writeStorage } from '@rehooks/local-storage';
|
import useLocalStorage from '@rehooks/local-storage';
|
||||||
import { window } from '@tauri-apps/api';
|
|
||||||
import { TauriEvent } from '@tauri-apps/api/event';
|
|
||||||
import { useSetAtom } from 'jotai';
|
import { useSetAtom } from 'jotai';
|
||||||
import { useCallback, useContext, useEffect, useRef } from 'react';
|
import { useCallback, useContext, useEffect, useRef } from 'react';
|
||||||
|
|
||||||
@ -23,10 +21,9 @@ export default function EventCollector() {
|
|||||||
const follows = JSON.parse(activeAccount.follows);
|
const follows = JSON.parse(activeAccount.follows);
|
||||||
|
|
||||||
const now = useRef(new Date());
|
const now = useRef(new Date());
|
||||||
const unsubscribe = useRef(null);
|
|
||||||
|
|
||||||
const subscribe = useCallback(async () => {
|
const subscribe = useCallback(async () => {
|
||||||
unsubscribe.current = pool.subscribe(
|
pool.subscribe(
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
kinds: [1, 6],
|
kinds: [1, 6],
|
||||||
@ -106,27 +103,9 @@ export default function EventCollector() {
|
|||||||
);
|
);
|
||||||
}, [activeAccount.follows, activeAccount.pubkey, activeAccount.id, pool, relays, setHasNewerNote]);
|
}, [activeAccount.follows, activeAccount.pubkey, activeAccount.id, pool, relays, setHasNewerNote]);
|
||||||
|
|
||||||
const listenWindowClose = useCallback(async () => {
|
|
||||||
window.getCurrent().listen(TauriEvent.WINDOW_CLOSE_REQUESTED, () => {
|
|
||||||
writeStorage('lastLogin', now.current);
|
|
||||||
window.getCurrent().close();
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
subscribe();
|
subscribe();
|
||||||
listenWindowClose();
|
}, [setHasNewerNote, subscribe]);
|
||||||
|
|
||||||
return () => {
|
return <NetworkStatusIndicator />;
|
||||||
if (unsubscribe.current) {
|
|
||||||
unsubscribe.current();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [setHasNewerNote, subscribe, listenWindowClose]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<NetworkStatusIndicator />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -144,3 +144,16 @@ export async function createChat(account_id: number, pubkey: string, created_at:
|
|||||||
created_at,
|
created_at,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get last login
|
||||||
|
export async function getLastLogin() {
|
||||||
|
const db = await connect();
|
||||||
|
const result = await db.select(`SELECT value FROM settings WHERE key = "last_login";`);
|
||||||
|
return result[0]?.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// update last login
|
||||||
|
export async function updateLastLogin(value: number) {
|
||||||
|
const db = await connect();
|
||||||
|
return await db.execute(`UPDATE settings SET value = ${value} WHERE key = "last_login";`);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user