minor updates

This commit is contained in:
Ren Amamiya
2023-06-03 19:40:36 +07:00
parent 93711e1d36
commit be6de2344e
14 changed files with 185 additions and 176 deletions

View File

@@ -2,7 +2,7 @@ import { Image } from "@shared/image";
import { RelayContext } from "@shared/relayProvider";
import { useActiveAccount } from "@stores/accounts";
import { useChannels } from "@stores/channels";
import { useChats } from "@stores/chats";
import { useChatMessages, useChats } from "@stores/chats";
import { DEFAULT_AVATAR, READONLY_RELAYS } from "@stores/constants";
import { usePageContext } from "@utils/hooks/usePageContext";
import { useProfile } from "@utils/hooks/useProfile";
@@ -13,26 +13,27 @@ import useSWRSubscription from "swr/subscription";
export function ActiveAccount({ data }: { data: any }) {
const pool: any = useContext(RelayContext);
const pageContext = usePageContext();
const pathnames: any = pageContext.urlParsed.pathname;
const pathname: any = pageContext.urlParsed.pathname;
const notChatPage = pathnames.includes("/chat") ? false : true;
const notChannelPage = pathnames.includes("/channel") ? false : true;
const isChatPage = pathname.includes("/chat");
const isChannelPage = pathname.includes("/channel");
// const notSpacePage = pathnames.includes("/space") ? false : true;
const lastLogin = useActiveAccount((state: any) => state.lastLogin);
const notifyChat = useChats((state: any) => state.add);
const saveChat = useChatMessages((state: any) => state.add);
const notifyChannel = useChannels((state: any) => state.add);
const { user } = useProfile(data.pubkey);
useSWRSubscription(
user && lastLogin > 0 ? ["account", data.pubkey] : null,
([, key]) => {
() => {
// subscribe to channel
const unsubscribe = pool.subscribe(
[
{
"#p": [key],
"#p": [data.pubkey],
since: lastLogin,
},
],
@@ -42,7 +43,9 @@ export function ActiveAccount({ data }: { data: any }) {
case 1:
break;
case 4:
if (notChatPage) {
if (!isChatPage) {
// save
saveChat(data.pubkey, event);
// update state
notifyChat(event.pubkey);
// send native notifiation
@@ -50,7 +53,7 @@ export function ActiveAccount({ data }: { data: any }) {
}
break;
case 42:
if (notChannelPage) {
if (!isChannelPage) {
// update state
notifyChannel(event);
// send native notifiation