Skip to content

fix: delete orphaned message notifications on conversation hard-delete#756

Open
ionfwsrijan wants to merge 2 commits into
Shivayan09:mainfrom
ionfwsrijan:fix/issue-753-message-notification-cleanup
Open

fix: delete orphaned message notifications on conversation hard-delete#756
ionfwsrijan wants to merge 2 commits into
Shivayan09:mainfrom
ionfwsrijan:fix/issue-753-message-notification-cleanup

Conversation

@ionfwsrijan
Copy link
Copy Markdown
Contributor

Description

When a conversation is hard-deleted (all participants have soft-deleted it), deleteConversation cleans up messages and the conversation document itself — but orphaned Notification documents of type: "message" are left behind referencing the now-deleted conversation.

Changes

server/src/controllers/conversation.controller.js — Added Notification.deleteMany({ conversation: convo._id, type: "message" }) in the allDeleted branch, before the conversation document is removed. This ensures orphaned notifications are cleaned up atomically with the conversation deletion.

Impact

  • Prevents broken UX where users see "User messaged you" notifications for deleted conversations
  • Eliminates database bloat from orphaned notification documents
  • Prevents .populate("conversation") from returning null references for deleted conversations

Fixes #753

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 1, 2026

@ionfwsrijan is attempting to deploy a commit to the Shivayan's projects Team on Vercel.

A member of the Team first needs to authorize it.

@ionfwsrijan
Copy link
Copy Markdown
Contributor Author

@Shivayan09 You may review and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Orphaned Message Notifications on Conversation Deletion Lead to Broken UX and Database Bloat

1 participant