wip: native notification

This commit is contained in:
Ren Amamiya
2023-05-30 15:33:27 +07:00
parent b856c2b8b5
commit 1e5bd7e21f
7 changed files with 59 additions and 18 deletions

View File

@@ -1,10 +1,42 @@
import { Image } from "@shared/image";
import { DEFAULT_AVATAR } from "@stores/constants";
import { RelayContext } from "@shared/relayProvider";
import { useActiveAccount } from "@stores/accounts";
import { DEFAULT_AVATAR, READONLY_RELAYS } from "@stores/constants";
import { useProfile } from "@utils/hooks/useProfile";
import { sendNativeNotification } from "@utils/notification";
import { useContext } from "react";
import useSWRSubscription from "swr/subscription";
export function ActiveAccount({ data }: { data: any }) {
const pool: any = useContext(RelayContext);
const lastLogin = useActiveAccount((state: any) => state.lastLogin);
const { user } = useProfile(data.pubkey);
useSWRSubscription(
user && lastLogin > 0 ? ["account", data.pubkey] : null,
([, key]) => {
// subscribe to channel
const unsubscribe = pool.subscribe(
[
{
"#p": [key],
since: lastLogin,
limit: 20,
},
],
READONLY_RELAYS,
(event) => {
sendNativeNotification(event.content);
},
);
return () => {
unsubscribe();
};
},
);
return (
<button type="button" className="relative h-11 w-11 overflow-hidden">
<Image