Mattermost, Inc.

Selectively delete chat

Hi everyone,

Is there any way to delete log chats between users, possibly only messages sent between selected dates? I have some users who have exchanged critical / confidential information at some point in past and would like it to be removed.

Hello, @Throin

The easiest way is to do it from the database in which you will have to narrow down the ChannelId and the CreateAt column. For example, ensure that the posts are the right ones that you want to delete by running a SELECT statement first on the Posts table WHERE the ChannelId:

SELECT * FROM Posts WHERE ChannelId = "<channel_id>" AND UserId = "<user_id>" AND CreateAt BETWEEN <time_1> AND <time_2>\G

Once confirmed, you can run the DELETE statement based on the criteria above:

DELETE FROM Posts WHERE ChannelId = "<channel_id>" AND UserId = "<user_id>" AND CreateAt BETWEEN <time_1> AND <time_2>\G

However, you will need to identify ChannelId and the UserId that you want to delete, which can be tricky. So, make sure you test it out on a staging instance if possible first before completely deleting it from the system.