How to delete old messages automatically in a channel?

Hello,

we are using Mattermost teams via GitHub on a Firefox browser at work for our team. Currently there are all old messages to see if you scroll to the top, which we don’t need and don’t want.

Is there an option to hide or delete all old messages automatically, so only the messages from TODAY are shown in the channel chat?

Thanks in advance.

You can configure a data retention policy to delete messages older than a day: Data retention policy — Mattermost documentation.

Hi @MMJJ882 and welcome to the Mattermost forums!

Data retention policies are a great way to do that, but they’re not available in the teams edition unfortunately.
You can do that directly in the database, if you like, so if it’s only the last 24hrs worth of messages you want to keep, you could run the following query in regular intervals on your database (this is MySQL syntax, not sure what you’re using):

update Posts set DeleteAt=unix_timestamp()*1000 where createat < (unix_timestamp()-86400)*1000 AND DeleteAt != 0;

The mattermost clients will not recognize the change here immediately, though, since this change has been carried out directly in the database and that is basically unsupported, but if you also restart the server after the cleanup, they might catch up automatically; otherwise a reload (F5, CTRL-r) in the application helps to get rid of the old posts in the currently open channel.

Another option would be to iterate over all channels in your installation and use the GetPostsForChannel API Call to delete them; this should also automatically refresh the clients.

If you only want the messages from today and the system should wipe all posts at midnight, it’s even easier, because then you can just have a cronjob running at 23:59 which sets all available posts to deleted:

update Posts set DeleteAt=unix_timestamp()*1000 WHERE DeleteAt=0;

Not sure if that would help or work for you, let me know, if you need additional help.

Please tell me how can I delete all messages in the channels by cleaning the database with the sql command. For example, all messages for the last 3 months?

Hi @Ityumenev and welcome to the Mattermost forums!

Deleting posts from the database is a bit more complicated, because there are a lot of cross references which are handled in the application, so there is no officially supported way to do that, but you might have luck with scripts like this one:

1 Like

Thanks a lot!
As for the data folder, where the files are stored, as I understand it, everything can be deleted there except for the users folder? User avatars are stored in the users folder, as I understand it.

If you want to remove all the attachments from the filesystem, then you can delete all the folders with dates in their names, so f.ex. the folder 20220704 will contain all attachments for all teams on your server for all channels.
The other folders there are:

  • brand
    that’s for your custom portal branding if you have one
  • plugins
    that’s plugin data, you should leave that alone, if you want to remove plugins, then uninstall them using the system console
  • emoji
    custom emojis
  • users
    profile pictures
1 Like

Thank you for your help. Is there any way to disable boards or jitsi meet on a specific channel? For example, you can turn off calls in the channel settings menu, but the rest is strange that there is none.

No, boards is enabled system wise, as well as jitsi meets. Calls has been created with this feature in mind, not sure if jitsi will adapt to that change (boards will not, because boards are not necessarily tied to a channel anymore).

Why can’t you delete accounts? Written that only deactivate. For example, a person retired. Or you need to change the current account just to another person (password, mail, login.)

You can, but only using mmctl user delete oder the DeleteUser API call.

Please create a new topic for your next questions, this topic is already solved and we try to stick to a “one issue, one topic” policy. Thanks!

I loved this content. Thanks for creating it. I’m a big supporter of your stuff.

where to turn if the plugin store stops working?

@Ityumenev please do not hijack other people’s threads with unrelated issues. If you need help with your plugin store, please create a new topic and we’ll have a look. thanks!