Skip to content

Commit

Permalink
fix(xmtp-plugin): conversations bug
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony23991 committed Jan 16, 2025
1 parent 6d83277 commit 08bfb8c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PrimaryNameRecord } from '@justaname.id/react';
import { Flex } from '@justweb3/ui';
import {
CachedConversation,
CachedMessage,
ContentTypeMetadata,
ContentTypeMetadata
} from '@xmtp/react-sdk';
import React from 'react';
import { MessageItem } from './MessageItem';
import { PrimaryNameRecord } from '@justaname.id/react';

export interface ChatListProps {
conversations: CachedConversation<ContentTypeMetadata>[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMountedAccount, usePrimaryNameBatch } from '@justaname.id/react';
import {
AddIcon,
Flex,
Expand All @@ -20,12 +21,11 @@ import {
useConversations,
useStreamAllMessages,
useStreamConsentList,
useStreamConversations,
useStreamConversations
} from '@xmtp/react-sdk';
import { isEqual } from 'lodash';
import React, { useEffect, useMemo } from 'react';
import { ChatList } from './ChatList';
import { useMountedAccount, usePrimaryNameBatch } from '@justaname.id/react';
import { isEqual } from 'lodash';

export interface InboxSheetProps {
open?: boolean;
Expand Down Expand Up @@ -68,16 +68,28 @@ export const InboxSheet: React.FC<InboxSheetProps> = ({
const [tab, setTab] = React.useState('Chats');
const { conversations: cachedConversations, isLoading } = useConversations();
const { address } = useMountedAccount();
const [initialConversations, setInitialConversations] = React.useState<
Conversation[] | null
>(null);
const conversations = useMemo(() => {
return cachedConversations.filter((convo) => convo.peerAddress !== address);
}, [cachedConversations, address]);
if (!cachedConversations || initialConversations === null) return [];
const filtered = cachedConversations.filter(
(convo) => convo.peerAddress !== address
);
const result = filtered.filter((conv) => {
return initialConversations.some(
(initConv) =>
initConv.peerAddress === conv.peerAddress &&
initConv.topic === conv.topic
);
});
return result;
}, [cachedConversations, address, initialConversations]);

const [isConsentListLoading, setIsConsentListLoading] = React.useState(true);
const { entries, loadConsentList } = useConsent();
const { client } = useClient();

const [initialConversations, setInitialConversations] = React.useState<
Conversation[] | null
>(null);
useEffect(() => {
if (!client || initialConversations !== null) return;

Expand Down

0 comments on commit 08bfb8c

Please sign in to comment.