RocketChat / RocketChat/Rocket.Chat

Android app shows ghost lastMessage after user deletion (room.lastMessage not cleaned up)

Open
#36,885 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
46.1k
Forks
13.9k
Avg merge
3d 3h
Merged PRs (30d)
130

Description

Description:

When a user is deleted from Rocket.Chat, all of their messages are removed from the rocketchat_message collection. However, if one of these messages was the last message in a room, the lastMessage field in the corresponding rocketchat_room document is not cleaned up.

This results in a ghost message that is only visible on the Android mobile client. The web and desktop clients ignore the dangling lastMessage pointer.


Steps to reproduce:
  1. Create a room (e.g., #general).
  2. Post a message in the room as User A.
  3. Delete User A from the system.
    • The message disappears from the rocketchat_message collection.
    • But the room document (rocketchat_room) still has the message stored in its lastMessage field.
  4. Open the room on the Android mobile app → the ghost message is shown.
  5. Open the same room in the browser or desktop client → no ghost message is shown.

Expected behavior:
  • When a user (and their messages) are deleted, the lastMessage field in rocketchat_room should be cleared or updated to point to the latest valid message.
  • No ghost messages should appear in any client.

Actual behavior:
  • Ghost message still appears in Android mobile client.
  • The message is not in rocketchat_message anymore.
  • The room’s lastMessage field still references it.
  • Web and desktop clients do not display it, but Android does.

Server Setup Information:
  • Version of Rocket.Chat Server: 7.10.0
  • License Type: Community
  • Number of Users: 20
  • Operating System: Ubuntu 24.04 LTS
  • Deployment Method: Docker
  • Number of Running Instances: 1
  • DB Replicaset Oplog: Disabled
  • NodeJS Version: 22.16.0
  • MongoDB Version: 6.0.13

Client Setup Information
  • Desktop App or Browser Version: 4.9.0 / Firefox 142.0.1

  • Operating System: Linux, macOS, Windows

  • Mobile App: Android Rocket.Chat app (latest release from Play Store): 4.63.0.96963


Additional context
  • The issue only affects mobile clients (tested on multiple Android devices).
  • It seems the Android app uses the lastMessage field in rocketchat_room to render channel previews, while web/desktop clients query rocketchat_message directly.
  • Manual workaround:
    db.rocketchat_room.updateOne(
      { _id: "GENERAL" },
      { $unset: { lastMessage: "" } }
    )
    

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace the user-deletion flow that removes messages from the rocketchat_message collection and inspect how the related rocketchat_room document's lastMessage field is handled. Reproduce the deletion with a room's final message, then verify that the field is cleared or points to a valid remaining message and that the Android client no longer shows a ghost message.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, mongodb, typescript
Domain
backend, databases, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.