-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Update Conversation List when new conversation is streamed #1333
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
Comment on lines
+30
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should put | undefined here 🤔 And instead handle the undefined before calling the function. Curious on your thoughts. It's just that I feel it's counterintuitive to call this function with a contentType that is undefined haha. Love the |
||
return ObjectTyped.keys(contentTypesPrefixes).find((key) => | ||
contentType.startsWith(contentTypesPrefixes[key]) | ||
); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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); | ||||||||||||||||||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error handling for the query update The conversation list update should be wrapped in a try-catch block to handle potential failures gracefully. Also, consider removing the empty line for better readability. logger.info("[XMTPRN Conversations] GOT A NEW CONVO");
-
- addConversationToConversationListQuery(account, conversation);
+ try {
+ await addConversationToConversationListQuery(account, conversation);
+ } catch (error) {
+ logger.error("[XMTPRN Conversations] Failed to update conversation list", error);
+ } 📝 Committable suggestion
Suggested change
|
||||||||||||||||||
}); | ||||||||||||||||||
logger.info("STREAMING CONVOS"); | ||||||||||||||||||
}; | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider initializing empty conversation list instead of early return
The early return when no previous conversations exist could lead to missed updates. Consider initializing with an empty array instead.
This ensures that updates are not lost when the conversation list is initially empty.
📝 Committable suggestion