From 2190c37359413ebf02b1f27b0fe122b1f413de88 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Fri, 26 Oct 2018 11:26:24 -0400 Subject: [PATCH] MM-12036 Add image dimensions for other fields in message attachments (#9748) --- app/post_metadata.go | 16 ++++++++++++ app/post_metadata_test.go | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/app/post_metadata.go b/app/post_metadata.go index bd34624d70..9cc18d618b 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -248,6 +248,22 @@ func getImagesInMessageAttachments(post *model.Post) []string { images = append(images, imagesInFieldValue...) } } + + if attachment.AuthorIcon != "" { + images = append(images, attachment.AuthorIcon) + } + + if attachment.ImageURL != "" { + images = append(images, attachment.ImageURL) + } + + if attachment.ThumbURL != "" { + images = append(images, attachment.ThumbURL) + } + + if attachment.FooterIcon != "" { + images = append(images, attachment.FooterIcon) + } } return images diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index e21f8bdbda..deb08930c8 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -692,6 +692,58 @@ func TestGetImagesInMessageAttachments(t *testing.T) { }, Expected: []string{"https://example.com/logo2", "https://example.com/icon2"}, }, + { + Name: "image in author_icon", + Post: &model.Post{ + Props: map[string]interface{}{ + "attachments": []*model.SlackAttachment{ + { + AuthorIcon: "https://example.com/icon2", + }, + }, + }, + }, + Expected: []string{"https://example.com/icon2"}, + }, + { + Name: "image in image_url", + Post: &model.Post{ + Props: map[string]interface{}{ + "attachments": []*model.SlackAttachment{ + { + ImageURL: "https://example.com/image", + }, + }, + }, + }, + Expected: []string{"https://example.com/image"}, + }, + { + Name: "image in thumb_url", + Post: &model.Post{ + Props: map[string]interface{}{ + "attachments": []*model.SlackAttachment{ + { + ThumbURL: "https://example.com/image", + }, + }, + }, + }, + Expected: []string{"https://example.com/image"}, + }, + { + Name: "image in footer_icon", + Post: &model.Post{ + Props: map[string]interface{}{ + "attachments": []*model.SlackAttachment{ + { + FooterIcon: "https://example.com/image", + }, + }, + }, + }, + Expected: []string{"https://example.com/image"}, + }, { Name: "images in multiple fields", Post: &model.Post{