Address issues

This commit is contained in:
Harrison Healey
2018-11-22 13:10:36 -05:00
parent 5388afd37e
commit 5f65356a3f
4 changed files with 32 additions and 28 deletions

View File

@@ -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

View File

@@ -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 &copy

View File

@@ -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"`
}

View File

@@ -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(",")