Skip to content

Commit

Permalink
fix: Update Conversation List when new conversation is streamed (#1333)
Browse files Browse the repository at this point in the history
Add new conversation to list when streamed
Fix content type errors
  • Loading branch information
alexrisch authored Dec 10, 2024
1 parent 1c8eb9e commit c48a7c1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
17 changes: 11 additions & 6 deletions features/conversation-requests-list/useV3RequestItems.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions queries/useV3ConversationListQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export const updateConversationDataToConversationListQuery = (
conversation: Partial<ConversationWithCodecsType>
) => {
const previousConversationsData = getConversationListQueryData(account);

if (!previousConversationsData) return;
const newConversations: V3ConversationListType =
previousConversationsData.map((c) => {
Expand Down
5 changes: 4 additions & 1 deletion utils/xmtpRN/contentTypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
);
Expand Down
4 changes: 3 additions & 1 deletion utils/xmtpRN/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
Expand Down

0 comments on commit c48a7c1

Please sign in to comment.