RocketChat / Rocket.Chat

The communications platform that puts data protection first.
https://rocket.chat/
Other
40.53k stars 10.56k forks source link

limit does not work in api function rooms.cleanHistory #12885

Open 2minwia opened 5 years ago

2minwia commented 5 years ago

Im trying to create a "remove latest messages" function for a bot, which uses rooms.cleanHistory in conjunction with the limit argument to only remove the latest x messages.
However, limit is seemingly not working properly.
Having it set to a string throws {"success":false,"error":"Match error: Failed Match.OneOf, Match.Maybe or Match.Optional validation"}, which is probably intended, but trying to use a number just deletes all messages in the time period set, instead of just the latest x posts. (or the last x posts. i don't really know what its supposed to do, since it doesn't work :^) )

Steps to reproduce:
Run something along the lines of

curl -H "X-Auth-Token: token"
-H "X-User-Id: rocket.cat"
-H "Content-type: application/json"
https://example.org/api/v1/rooms.cleanHistory
-d '{ "roomId": "YGQmgs6zbfa4ZYvNa", "latest": "2026-12-09T13:42:25.304Z", "oldest": "2016-08-30T13:42:25.304Z", "limit": 3 }'

on a terminal with relevant auth-token, user-id, etc.

Expected behavior:
It removes the last three messages sent (or first three messages sent. I'm not really sure. psst: if it does the first three, this is also a feature request for a switch to have it do the last three sent.)

Actual behavior:
It removes all messages within the time period. That's bad. It shouldn't do that.

vynmera commented 5 years ago

The limit field is only to be used by clients that wish to break the deletion down into multiple requests. (The web client does this as well, it sets a limit of 2500 so you can track progress on large channels) - sorry this was not yet obvious (frankly, it's a bug).

On my defense, I wrote the documentation for limit while it was still in development (and the limit field would work as you described, removing latest messages first until the limit is reached). After some changes by @ggazzo this is no longer the case and limit cannot ensure integrity.

A flag to bring back this old functionality may be nice, however. (along with other things that used to work, e.g. retention policies in slow channels not waiting for new messages, and also the fact someone deleted the svg icons I added) Be sure to keep this issue open if this is something you are interested in (you can also join open.rocket.chat, join #dev and complain ask there), or if you know some JS, make a PR (and turn off "Let maintainers edit your code" :wink: )