Skip to content

fix: remove default: () => new Date() from lastMessageAt in conversationModel to prevent empty conversations surfacing in list #49

Description

@coderabbitai

Summary

In backend/src/models/conversationModel.ts, the lastMessageAt field has a Mongoose default:

lastMessageAt: {
  type: Date,
  default: () => new Date()  // ← fires on every insert, including upserts in getMessages
}

When getMessages upserts a new conversation (e.g. a user opens a chat before any message is sent), Mongoose applies this default on insert, so the empty conversation immediately appears at the top of the conversation list with a fresh timestamp.

Expected fix

Remove the default so lastMessageAt is only set when a message is actually sent:

lastMessageAt: {
  type: Date
  // no default
}

References

Alpha milestone

Required before alpha — empty conversations polluting the list is a visible UX bug.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions