diff --git a/app/post_metadata.go b/app/post_metadata.go index 9eb9e987f4..f5d751bbf5 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -176,7 +176,10 @@ func (a *App) getEmbedForPost(post *model.Post, firstLink string, isNewPost bool }, nil } - return nil, nil + return &model.PostEmbed{ + Type: model.POST_EMBED_LINK, + URL: firstLink, + }, nil } func (a *App) getImagesForPost(post *model.Post, imageURLs []string, isNewPost bool) map[string]*model.PostImage { diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index e03ac54c46..d9dbe85f3a 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -536,6 +536,13 @@ func TestGetEmbedForPost(t *testing.T) { w.Header().Set("Content-Type", "image/png") w.Write(file) + } else if r.URL.Path == "/other" { + w.Header().Set("Content-Type", "text/html") + w.Write([]byte(` + + + + `)) } else { t.Fatal("Invalid path", r.URL.Path) } @@ -544,6 +551,7 @@ func TestGetEmbedForPost(t *testing.T) { ogURL := server.URL + "/index.html" imageURL := server.URL + "/image.png" + otherURL := server.URL + "/other" t.Run("with link previews enabled", func(t *testing.T) { th := Setup(t) @@ -593,6 +601,16 @@ func TestGetEmbedForPost(t *testing.T) { }, embed) assert.Nil(t, err) }) + + t.Run("should return a link embed", func(t *testing.T) { + embed, err := th.App.getEmbedForPost(&model.Post{}, otherURL, false) + + assert.Equal(t, &model.PostEmbed{ + Type: model.POST_EMBED_LINK, + URL: otherURL, + }, embed) + assert.Nil(t, err) + }) }) t.Run("with link previews disabled", func(t *testing.T) { @@ -634,6 +652,13 @@ func TestGetEmbedForPost(t *testing.T) { assert.Nil(t, embed) assert.Nil(t, err) }) + + t.Run("should not return a link embed", func(t *testing.T) { + embed, err := th.App.getEmbedForPost(&model.Post{}, otherURL, false) + + assert.Nil(t, embed) + assert.Nil(t, err) + }) }) } diff --git a/model/post_embed.go b/model/post_embed.go index 6e8e33cadb..15d061fc79 100644 --- a/model/post_embed.go +++ b/model/post_embed.go @@ -7,6 +7,7 @@ const ( POST_EMBED_IMAGE PostEmbedType = "image" POST_EMBED_MESSAGE_ATTACHMENT PostEmbedType = "message_attachment" POST_EMBED_OPENGRAPH PostEmbedType = "opengraph" + POST_EMBED_LINK PostEmbedType = "link" ) type PostEmbedType string