diff --git a/features/conversation-requests-list/useV3RequestItems.tsx b/features/conversation-requests-list/useV3RequestItems.tsx index af992e41e..c7e062b4b 100644 --- a/features/conversation-requests-list/useV3RequestItems.tsx +++ b/features/conversation-requests-list/useV3RequestItems.tsx @@ -1,3 +1,4 @@ +import logger from "@/utils/logger"; import { getMessageContentType } from "@/utils/xmtpRN/contentTypes"; import { getV3SpamScore } from "@data/helpers/conversations/spamScore"; import { useCurrentAccount } from "@data/store/accountsStore"; @@ -44,17 +45,21 @@ export const useV3RequestItems = () => { } catch { content = lastMessage?.fallback ?? ""; } - const contentType = getMessageContentType( lastMessage?.contentTypeId! ); - - const spamScore = contentType - ? await getV3SpamScore({ + let spamScore = 0; + try { + if (contentType) { + spamScore = await getV3SpamScore({ message: content, contentType, - }) - : 0; // TODO: Handle this, maybe not 0 if we can't find content type? + }); + } + } catch (error) { + logger.error("Couldn't get spam score", error); + } + if (spamScore > 1) { likelySpam.push(conversation); } else { diff --git a/queries/useV3ConversationListQuery.ts b/queries/useV3ConversationListQuery.ts index 295fa9146..edad31362 100644 --- a/queries/useV3ConversationListQuery.ts +++ b/queries/useV3ConversationListQuery.ts @@ -167,6 +167,7 @@ export const updateConversationDataToConversationListQuery = ( conversation: Partial ) => { const previousConversationsData = getConversationListQueryData(account); + if (!previousConversationsData) return; const newConversations: V3ConversationListType = previousConversationsData.map((c) => { diff --git a/utils/xmtpRN/contentTypes/index.ts b/utils/xmtpRN/contentTypes/index.ts index 869027c3f..636c2a841 100644 --- a/utils/xmtpRN/contentTypes/index.ts +++ b/utils/xmtpRN/contentTypes/index.ts @@ -26,7 +26,10 @@ export function isContentType(args: { return contentType.startsWith(prefix); } -export function getMessageContentType(contentType: string) { +export function getMessageContentType(contentType: string | undefined) { + if (!contentType) { + return undefined; + } return ObjectTyped.keys(contentTypesPrefixes).find((key) => contentType.startsWith(contentTypesPrefixes[key]) ); diff --git a/utils/xmtpRN/conversations.ts b/utils/xmtpRN/conversations.ts index 931b07d72..b079c7c38 100644 --- a/utils/xmtpRN/conversations.ts +++ b/utils/xmtpRN/conversations.ts @@ -14,13 +14,15 @@ import { DmWithCodecsType, } from "./client"; import { getXmtpClient } from "./sync"; +import { addConversationToConversationListQuery } from "@/queries/useV3ConversationListQuery"; export const streamConversations = async (account: string) => { await stopStreamingConversations(account); const client = (await getXmtpClient(account)) as ConverseXmtpClientType; await client.conversations.stream(async (conversation) => { logger.info("[XMTPRN Conversations] GOT A NEW CONVO"); - // handleNewConversation(client, conversation); + + addConversationToConversationListQuery(account, conversation); }); logger.info("STREAMING CONVOS"); };