From a338e397c6949062ecc90d31224dca3c20587a65 Mon Sep 17 00:00:00 2001 From: daria-github Date: Tue, 23 Jan 2024 08:29:06 -0800 Subject: [PATCH] comment out code for sent messages --- .../ConversationListController.tsx | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/controllers/ConversationListController.tsx b/src/controllers/ConversationListController.tsx index 52e78459..6a709791 100644 --- a/src/controllers/ConversationListController.tsx +++ b/src/controllers/ConversationListController.tsx @@ -1,6 +1,6 @@ -import { useEffect, useMemo, useState } from "react"; -import { useClient, useConsent, useDb } from "@xmtp/react-sdk"; -import type { CachedConversation, CachedMessage } from "@xmtp/react-sdk"; +import { useEffect, useMemo } from "react"; +import { useClient, useConsent } from "@xmtp/react-sdk"; +import type { CachedConversation } from "@xmtp/react-sdk"; import type { ActiveTab } from "../store/xmtp"; import { useXmtpStore } from "../store/xmtp"; import useListConversations from "../hooks/useListConversations"; @@ -26,9 +26,9 @@ export const ConversationListController = ({ const { isLoaded, isLoading, conversations } = useListConversations(); const { isAllowed, isDenied } = useConsent(); - const { db } = useDb(); - const [messages, setMessages] = useState([]); - const messagesDb = db.table("messages"); + // const { db } = useDb(); + // const [messages, setMessages] = useState([]); + // const messagesDb = db.table("messages"); useStreamAllMessages(); const { client: walletAddress } = useClient(); @@ -48,22 +48,23 @@ export const ConversationListController = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [isLoaded, activeTab, changedConsentCount]); - useEffect(() => { - // This may make more sense to come from the React SDK, but we're pulling from here for now - const fetchMessages = async () => - messagesDb - .where("senderAddress") - .equals(walletAddress?.address as string) - .toArray() - .then((dbMessages: CachedMessage[]) => { - setMessages(dbMessages); - }) - .catch((error: Error) => { - console.error("Error querying messages:", error); - }); + // To-do: remove if not needed after consent goes out + // useEffect(() => { + // // This may make more sense to come from the React SDK, but we're pulling from here for now + // const fetchMessages = async () => + // messagesDb + // .where("senderAddress") + // .equals(walletAddress?.address as string) + // .toArray() + // .then((dbMessages: CachedMessage[]) => { + // setMessages(dbMessages); + // }) + // .catch((error: Error) => { + // console.error("Error querying messages:", error); + // }); - void fetchMessages(); - }, [conversations.length, messagesDb, walletAddress?.address]); + // void fetchMessages(); + // }, [conversations.length, messagesDb, walletAddress?.address]); const messagesToPass = useMemo(() => { const conversationsWithTab = conversations.map( @@ -84,21 +85,21 @@ export const ConversationListController = ({ ); const sortedConvos = conversationsWithTab.filter( (item: NodeWithConsent) => { - const hasSentMessages = messages.find( - (message) => message?.conversationTopic === item.props.convo.topic, - ); + // To-do: remove commented out code in this block if not needed after consent goes out + // const hasSentMessages = messages.find( + // (message) => message?.conversationTopic === item.props.convo.topic, + // ); const isAddressBlocked = isDenied(item.props.convo.peerAddress); const isAddressAllowed = isAllowed(item.props.convo.peerAddress); if (activeTab === "messages") { - // Still want to keep blocked in blocked, even if those still have messages - return isAddressAllowed || (!isAddressBlocked && hasSentMessages); + return isAddressAllowed; } if (activeTab === "blocked") { return isAddressBlocked; } if (activeTab === "requests") { - return !hasSentMessages && !isAddressBlocked && !isAddressAllowed; + return !isAddressBlocked && !isAddressAllowed; } return null; }, @@ -107,10 +108,10 @@ export const ConversationListController = ({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [ conversations, - messages, + // messages, isLoading, walletAddress, - db, + // db, changedConsentCount, isAllowed, isDenied,