Skip to content

Commit

Permalink
comment out code for sent messages
Browse files Browse the repository at this point in the history
  • Loading branch information
daria-github committed Jan 23, 2024
1 parent 53b294a commit a338e39
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions src/controllers/ConversationListController.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -26,9 +26,9 @@ export const ConversationListController = ({
const { isLoaded, isLoading, conversations } = useListConversations();
const { isAllowed, isDenied } = useConsent();

const { db } = useDb();
const [messages, setMessages] = useState<CachedMessage[]>([]);
const messagesDb = db.table("messages");
// const { db } = useDb();
// const [messages, setMessages] = useState<CachedMessage[]>([]);
// const messagesDb = db.table("messages");

useStreamAllMessages();
const { client: walletAddress } = useClient();
Expand All @@ -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(
Expand All @@ -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;
},
Expand All @@ -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,
Expand Down

0 comments on commit a338e39

Please sign in to comment.