Mattermost, Inc.

[Solved] Retrieving old headers in a channel

Hi there :slightly_smiling_face:,
I would like to know if it is possible to retrieve the old headers from a specific channel.
I need to make an history of these.
I don’t even know if the changes of the header are recorded somewhere.
May I can use some sql request in the database, parse the logs, or even better use the api then ?

Some search option could help to retrieve the past headers.
However System is not a valid user for search with “from:”.
Does someone have another idea to help me ?

I don’t believe that we archive old channel headers. They are stored in the Header column of the Channels table in the database, and there’s no mechanism (that I’m aware of) for storing past values. The act of modifying a channel header should be recorded in the Audits table, but I don’t believe that the old value of the header is stored there.

Thanks for the answer.
The only thing I know is that I can scroll back in the channel and see when the header was changed, the old value and the new one. The “user” who changed it is “System”.
I can read that for every change :
System 23:59
User1 updated the channel header from: hello to: Hello there

So, it is recorded somewhere and I don’t know were. I use some trick now, the one who changes the header says it has, and we can do a search with his username. But it is painfull and not automatic.

Right, the system sends messages with type system_header_change whenever a user changes the header. These messages are recorded in the Posts table, so you could do something like this (in MySQL) to query the history of the header:

SELECT
  CreateAt,
  JSON_UNQUOTE(JSON_EXTRACT(CAST(Props AS JSON), '$.username')) AS Username,
  JSON_UNQUOTE(JSON_EXTRACT(CAST(Props AS JSON), '$.old_header')) AS OldHeader,
  JSON_UNQUOTE(JSON_EXTRACT(CAST(Props AS JSON), '$.new_header')) AS NewHeader
FROM Posts
WHERE Type = 'system_header_change'
ORDER BY CreateAt;

I’ll leave it as an exercise to the reader to figure out how to do this in PostgreSQL (it isn’t difficult), and warn you that if the Posts table grows too large, this query could get slow.

This is exactly what I needed, thank you very much MusikPolice !
You couldn’t make a better answer. :smiley:

1 Like