Skip to content

Fix avatar initials in realtime messages - #2

Draft
sgzsh269 wants to merge 1 commit into
mainfrom
codex/diagnose-avatar-icon-bug
Draft

sgzsh269 wants to merge 1 commit into
mainfrom
codex/diagnose-avatar-icon-bug

Conversation

@sgzsh269

Copy link
Copy Markdown
Owner

Summary

  • include sender first and last names when broadcasting messages
  • expose optional sender info in PartySocket message type
  • include message id and createdAt fields for real-time updates
  • fix lint warnings in new route and socket hook

Testing

  • node_modules/.bin/biome check packages/webapp/src/app/api/chatrooms/[id]/messages/new/route.ts packages/webapp/src/lib/usePartySocket.ts (fails: Found 3 errors)
  • bun run --filter webapp build (fails: failed to fetch Inter font)

https://chatgpt.com/codex/tasks/task_e_686f64c188448320bb44d1d00b11afbe

@sgzsh269
sgzsh269 marked this pull request as draft July 10, 2025 08:42
@sgzsh269
sgzsh269 requested a review from Copilot July 10, 2025 08:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enriches real-time chat events with full sender details and message metadata, and addresses lint issues in the socket hook and API route.

  • Extend PartyMessage to include id, content, createdAt, and a detailed sender object
  • Broadcast id, content, createdAt, and sender in the new message route
  • Suppress a lint rule on useEffect and adjust the host fallback in the socket hook

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
packages/webapp/src/lib/usePartySocket.ts Added new message fields in the interface, fixed lint, and updated host fallback
packages/webapp/src/app/api/chatrooms/[id]/messages/new/route.ts Typed newMessage, included extra fields in broadcast, and removed unused var
Comments suppressed due to low confidence (1)

packages/webapp/src/app/api/chatrooms/[id]/messages/new/route.ts:83

  • New real-time fields (id, content, createdAt, sender) have been added—consider adding unit or integration tests to ensure these are present in socket events.
            content: content,

}, [onMessagesClear]);

// Clear messages when chatroom changes to prevent cross-chatroom message leakage
// biome-ignore lint/correctness/useExhaustiveDependencies: run on chatroom change only

Copilot AI Jul 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The effect’s dependency array uses onMessagesClear instead of chatroomId, so it won’t clear messages when the chatroom actually changes. Consider replacing the dependency with chatroomId (and removing the lint ignore) to match the comment.

Suggested change
// biome-ignore lint/correctness/useExhaustiveDependencies: run on chatroom change only

Copilot uses AI. Check for mistakes.
Comment on lines 152 to +153
conn = new PartySocket({
host: process.env.NEXT_PUBLIC_PARTYKIT_HOST!,
host: process.env.NEXT_PUBLIC_PARTYKIT_HOST ?? "",

Copilot AI Jul 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Falling back to an empty string may hide a missing or misconfigured NEXT_PUBLIC_PARTYKIT_HOST. It’s better to throw an error or explicitly log a warning if the env var is undefined.

Copilot uses AI. Check for mistakes.

export interface PartyMessage {
id?: string;
content?: string;

Copilot AI Jul 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Both content and text exist on PartyMessage, which could lead to confusion. Consider unifying on one property name for the message body.

Copilot uses AI. Check for mistakes.
}
// Save complete AI response to database
const aiMessage = await db
await db

Copilot AI Jul 10, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By removing the assignment to aiMessage, you lose the inserted record’s id and createdAt. If you need those for real-time updates, re-capture the result of the insert.

Suggested change
await db
const [aiMessage] = await db

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants