From 5f65356a3fb8ae5142ac28fc7b81e0c70dbcfabd Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 22 Nov 2018 13:10:36 -0500 Subject: [PATCH] Address issues --- app/post_metadata.go | 40 +++++++++++++++++++++------------------- model/post.go | 2 +- model/post_metadata.go | 16 +++++++++------- store/sqlstore/utils.go | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/app/post_metadata.go b/app/post_metadata.go index 6b0058c9139..0b4de04cd63 100644 --- a/app/post_metadata.go +++ b/app/post_metadata.go @@ -131,27 +131,29 @@ func (a *App) getEmbedForPost(post *model.Post, firstLink string) (*model.PostEm }, nil } - if firstLink != "" { - og, image, err := a.getLinkMetadata(firstLink, true) - if err != nil { - return nil, err - } + if firstLink == "" { + return nil, nil + } - if og != nil { - return &model.PostEmbed{ - Type: model.POST_EMBED_OPENGRAPH, - URL: firstLink, - Data: og, - }, nil - } + og, image, err := a.getLinkMetadata(firstLink, true) + if err != nil { + return nil, err + } - if image != nil { - // Note that we're not passing the image info here since they'll be part of the PostMetadata.Images field - return &model.PostEmbed{ - Type: model.POST_EMBED_IMAGE, - URL: firstLink, - }, nil - } + if og != nil { + return &model.PostEmbed{ + Type: model.POST_EMBED_OPENGRAPH, + URL: firstLink, + Data: og, + }, nil + } + + if image != nil { + // Note that we're not passing the image info here since they'll be part of the PostMetadata.Images field + return &model.PostEmbed{ + Type: model.POST_EMBED_IMAGE, + URL: firstLink, + }, nil } return nil, nil diff --git a/model/post.go b/model/post.go index 0e5769778c9..c252976d284 100644 --- a/model/post.go +++ b/model/post.go @@ -133,7 +133,7 @@ type PostForIndexing struct { ParentCreateAt *int64 `json:"parent_create_at"` } -// Shallowly clone the a post +// Clone shallowly copies the post. func (o *Post) Clone() *Post { copy := *o return © diff --git a/model/post_metadata.go b/model/post_metadata.go index bc4da5843b4..a337b2f8bfd 100644 --- a/model/post_metadata.go +++ b/model/post_metadata.go @@ -4,21 +4,23 @@ package model type PostMetadata struct { - // An array of the information required to render additional details about the contents of this post. + // Embeds holds information required to render content embedded in the post. This includes the OpenGraph metadata + // for links in the post. Embeds []*PostEmbed `json:"embeds,omitempty"` - // An arrayof the custom emojis used in the post or in reactions to the post. + // Emojis holds all custom emojis used in the post or used in reaction to the post. Emojis []*Emoji `json:"emojis,omitempty"` - // An array of information about the file attachments on the post. + // Files holds information about the file attachments on the post. Files []*FileInfo `json:"files,omitempty"` - // A map of image URL to information about all external images in the post. This includes image embeds, - // inline Markdown images, OpenGraph images, and message attachment images, but it does not contain the dimensions - // of file attachments which are contained in PostMetadata.FileInfos. + // Images holds the dimensions of all external images in the post as a map of the image URL to its diemsnions. + // This includes image embeds (when the message contains a plaintext link to an image), Markdown images, images + // contained in the OpenGraph metadata, and images contained in message attachments. It does not contain + // the dimensions of any file attachments as those are stored in FileInfos. Images map[string]*PostImage `json:"images,omitempty"` - // A list of reactions made to the post + // Reactions holds reactions made to the post. Reactions []*Reaction `json:"reactions,omitempty"` } diff --git a/store/sqlstore/utils.go b/store/sqlstore/utils.go index 61eac9758ba..d5139da5894 100644 --- a/store/sqlstore/utils.go +++ b/store/sqlstore/utils.go @@ -13,7 +13,7 @@ import ( // be used as part of a SQL query. func MapStringsToQueryParams(list []string, paramPrefix string) (string, map[string]interface{}) { keys := bytes.Buffer{} - params := make(map[string]interface{}) + params := make(map[string]interface{}, len(list)) for i, entry := range list { if keys.Len() > 0 { keys.WriteString(",")