mirror of
https://github.com/lumehq/lume.git
synced 2025-10-10 08:23:04 +02:00
wip: native notification
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user