RocketChat / RocketChat/Rocket.Chat
Entering a tmid of null causes issues in message processing
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 using the api/v1/chat.sendMessage endpoint, if you send a "tmid":null, then the message never will show up in the UI. The endpoint api/v1/method.call/loadHistory will not show the message, but the api/v1/channels.messages API will show it.
Steps to reproduce:
- Stand up a new server, and get a user token.
curl -H "X-Auth-Token: $token" \ -H "X-User-Id: $userid" \ -H "Content-type:application/json" \ http://localhost:3000/api/v1/chat.sendMessage \ -d '{"message": { "rid": "GENERAL", "msg": "This is a message test!","tmid":null }}'- Go to the general channel, the message is not there.
curl -H "X-Auth-Token: $token" \ -H "X-User-Id: $userid" \ -H "Content-type:application/json" \ http://localhost:3000/api/v1/chat.sendMessage \ -d '{"message": { "rid": "GENERAL", "msg": "This is a message test2!" }}'- The message is there.
Expected behavior:
With different languages JSON serializers handling null fields differently, the null should be processed like it's not there, instead of relying on languages serializer to be set to not process nulls.
Actual behavior:
It doesn't show in the UI since that uses loadHistory, but will show in channels.messages.
Server Setup Information:
- Version of Rocket.Chat Server: 4.6.3, 4.8.1, 5.0.0-dev
- Operating System: Mac and Linux
- Deployment Method: docker then git pull and build
- Number of Running Instances: N/A
- DB Replicaset Oplog: N/A
- NodeJS Version: Whatever docker has, and 14.19.3
- MongoDB Version: 4.0 and 4.4
Client Setup Information
- Desktop App or Browser Version: Latest Chrome, Edge, and Firefox tested
- Operating System: Windows and Mac
Additional context
We had an old 1.1 server, and this issue isn't in that server. Sending a message with a tmid of null still shows the message.
I added
if (message.tmid === null) {
delete message.tmid;
}
Under line 19 of sendMessage.js and that fixed the issue. Happy to PR that and be a contributor or happy if you have a different fix. :)
It also seems that this was sort of mentioned before as an issue under the React client, and closed.
Relevant logs:
4.6.3 posted in trace that this line was causing a processing issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with apps/meteor/app/lib/server/methods/sendMessage.js, especially the referenced lines 19 and 67, and reproduce the behavior using the provided chat.sendMessage and loadHistory curl requests. Done means a message sent with "tmid": null appears in the UI and loadHistory consistently treats it like a message without that field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100