From e6f36f064959261f588c11f91aeb2fcb8164d70b Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sat, 16 Oct 2021 09:09:22 +0530 Subject: [PATCH] Pre-fill CreateAt to let link previews work. (#18698) * Pre-fill CreateAt to let link previews work. Because of the fact that getEmbedsAndImages has been now refactored to work _before_ a post is saved. So the CreateAt field of a post was absent. This led to link previews being failed to save in the DB because the timestamp wasn't there. So we just pre-fill the field for it to work. At the store layer, if the timestamp is present, it will just reuse that. https://community-daily.mattermost.com/boards/workspace/zyoahc9uapdn3xdptac6jb69ic/285b80a3-257d-41f6-8cf4-ed80ca9d92e5/495cdb4d-c13a-4992-8eb9-80cfee2819a4?c=305651ab-a96f-40d3-8bcf-8391c0d3e306 ```release-note NONE ``` * Do not override existing time ```release-note NONE ``` --- app/post.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/post.go b/app/post.go index c45c5fd8d7..7be53bc516 100644 --- a/app/post.go +++ b/app/post.go @@ -266,6 +266,11 @@ func (a *App) CreatePost(c *request.Context, post *model.Post, channel *model.Ch } } + // Pre-fill the CreateAt field for link previews to get the correct timestamp. + if post.CreateAt == 0 { + post.CreateAt = model.GetMillis() + } + post = a.getEmbedsAndImages(post, true) previewPost := post.GetPreviewPost() if previewPost != nil {