diff --git a/packages/web/components/MainTabsOrPages/ViewConvo.tsx b/packages/web/components/MainTabsOrPages/ViewConvo.tsx index 57cc98b..dbbac30 100644 --- a/packages/web/components/MainTabsOrPages/ViewConvo.tsx +++ b/packages/web/components/MainTabsOrPages/ViewConvo.tsx @@ -17,6 +17,12 @@ import { } from "react-icons/fa"; import LinkIcon from "../Drawer/LinkIcon"; import UserAvatar, { UserAvatarSizes } from "../UserDetails/UserAvatar"; +import { useRecoilValue } from "recoil"; +import { allRelevantConversationsAtom } from "../../recoil/main"; +import { useRouter } from "next/router"; +import Conversation from "@nirvana/common/models/conversation"; +import { useAuth } from "../../contexts/authContext"; +import { QueryRoutes, Routes } from "@nirvana/common/helpers/routes"; const testDrawerItems: { linkType: LinkType; @@ -102,17 +108,37 @@ const testAudioClips: { ]; export default function ViewConvo(props: { conversationId: string }) { - // auth if do not have this conversation in react cache, then we are not authorized + const { currUser } = useAuth(); - // if somehow it's still cached but we were removed, - // then authenticate by checking if we are in the array of users for the conversation + const allConvosMap = useRecoilValue(allRelevantConversationsAtom); const endOfTimeline = useRef(); + const router = useRouter(); + useEffect(() => { endOfTimeline.current?.scrollIntoView({ behavior: "smooth" }); }, []); + // auth if do not have this conversation in react cache, then we are not authorized + // if somehow it's still cached but we were removed, + // then authenticate by checking if we are in the array of users for the conversation + + const convo: Conversation | undefined = allConvosMap.get( + props.conversationId + ); + + useEffect(() => { + if (!convo || !convo.activeMembers.includes(currUser!.uid)) { + toast.error("Not authorized for this conversation"); + + router.push({ + pathname: Routes.home, + query: { page: QueryRoutes.convos }, + }); + } + }, []); + return ( <>
@@ -120,21 +146,21 @@ export default function ViewConvo(props: { conversationId: string }) {
{/* header */} - - + + - Engineering + {convo?.name} - - 25 members + + {convo?.activeMembers.length} members diff --git a/packages/web/pages/s/index.tsx b/packages/web/pages/s/index.tsx index 47fa407..862fd75 100644 --- a/packages/web/pages/s/index.tsx +++ b/packages/web/pages/s/index.tsx @@ -45,7 +45,7 @@ export default function Me() { } else if (currPage === QueryRoutes.createConvo) { fullCleanPageContent = ; } else if (currConvo) { - fullCleanPageContent = ; + fullCleanPageContent = ; } if (fullCleanPageContent) { diff --git a/packages/web/services/firebaseService.js b/packages/web/services/firebaseService.js index 1f12522..39b2362 100644 --- a/packages/web/services/firebaseService.js +++ b/packages/web/services/firebaseService.js @@ -42,17 +42,17 @@ console.log("initialized firebase"); // Initialize firestore persistence for data caching export const firestoreDb = getFirestore(app); -enableIndexedDbPersistence(firestoreDb).catch((err) => { - if (err.code == "failed-precondition") { - // Multiple tabs open, persistence can only be enabled - // in one tab at a a time. - // ... - } else if (err.code == "unimplemented") { - // The current browser does not support all of the - // features required to enable persistence - // ... - } -}); +// enableIndexedDbPersistence(firestoreDb).catch((err) => { +// if (err.code == "failed-precondition") { +// // Multiple tabs open, persistence can only be enabled +// // in one tab at a a time. +// // ... +// } else if (err.code == "unimplemented") { +// // The current browser does not support all of the +// // features required to enable persistence +// // ... +// } +// }); setPersistence(getAuth(), browserSessionPersistence);