MM-11868/MM-12010/MM-12011/MM-12036 Improve post metadata structure (#9693)

* MM-11868/MM-12010/MM-12011/MM-12036 Include dimensions for opengraph and message attachment images in post metadata

* Remove duplicate check from getFirstLinkAndImages

* Add tests for getImagesInMessageAttachments

* Rename PostMetadata.FileInfos to PostMetadata.Files

* Rename Metadata.ImageDimensions to Metadata.Images
Этот коммит содержится в:
Harrison Healey
2018-10-24 04:49:55 -04:00
родитель 3929cb0141
Коммит 18684dd6de
5 изменённых файлов: 516 добавлений и 196 удалений

Просмотреть файл

@@ -11,7 +11,6 @@ import (
"strings"
"unicode/utf8"
"github.com/dyatlov/go-opengraph/opengraph"
"github.com/mattermost/mattermost-server/utils/markdown"
)
@@ -83,18 +82,8 @@ type Post struct {
PendingPostId string `json:"pending_post_id" db:"-"`
HasReactions bool `json:"has_reactions,omitempty"` // Deprecated, do not use this field any more
// Transient fields populated before sending posts to the client
ReactionCounts ReactionCounts `json:"reaction_counts" db:"-"`
FileInfos []*FileInfo `json:"file_infos" db:"-"`
ImageDimensions []*PostImageDimensions `json:"image_dimensions" db:"-"`
OpenGraphData []*opengraph.OpenGraph `json:"opengraph_data" db:"-"`
Emojis []*Emoji `json:"emojis" db:"-"`
}
type PostImageDimensions struct {
URL string `json:"url"`
Width int `json:"width"`
Height int `json:"height"`
// Transient data populated before sending a post to the client
Metadata *PostMetadata `json:"metadata" db:"-"`
}
type PostEphemeral struct {

22
model/post_embed.go Обычный файл
Просмотреть файл

@@ -0,0 +1,22 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
const (
POST_EMBED_IMAGE PostEmbedType = "image"
POST_EMBED_MESSAGE_ATTACHMENT PostEmbedType = "message_attachment"
POST_EMBED_OPENGRAPH PostEmbedType = "opengraph"
)
type PostEmbedType string
type PostEmbed struct {
Type PostEmbedType `json:"type"`
// The URL of the embedded content. Used for image and OpenGraph embeds.
URL string `json:"url,omitempty"`
// Any additional data for the embedded content. Only used for OpenGraph embeds.
Data interface{} `json:"data,omitempty"`
}

28
model/post_metadata.go Обычный файл
Просмотреть файл

@@ -0,0 +1,28 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
type PostMetadata struct {
// An array of the information required to render additional details about the contents of this post.
Embeds []*PostEmbed `json:"embeds,omitempty"`
// An arrayof the custom emojis used in the post or in reactions to the post.
Emojis []*Emoji `json:"emojis,omitempty"`
// An array of 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 map[string]*PostImage `json:"images,omitempty"`
// A map of emoji names to a count of users that reacted with the given emoji.
ReactionCounts ReactionCounts `json:"reaction_counts,omitempty"`
}
type PostImage struct {
Width int `json:"width"`
Height int `json:"height"`
}