* Allow Embeds editing without editing

* Add focalboard to embed after it being in props

* Fix tests

* change to boards

* remove extra gunk

* Fix tests

* Add Feature Flag

* update boardsunfurl

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Hossein
2021-10-13 10:51:27 -04:00
коммит произвёл GitHub
родитель be203d9bf3
Коммит 6521b0dfe3
4 изменённых файлов: 30 добавлений и 12 удалений

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

@@ -108,6 +108,7 @@ func (a *App) PreparePostForClient(originalPost *model.Post, isNewPost, isEditPo
if post.DeleteAt > 0 {
// For deleted posts we don't fill out metadata nor do we return the post content
post.Message = ""
post.Metadata = &model.PostMetadata{}
return post
}
@@ -142,6 +143,11 @@ func (a *App) getEmbedsAndImages(post *model.Post, isNewPost bool) *model.Post {
// Embeds and image dimensions
firstLink, images := a.getFirstLinkAndImages(post.Message)
if post.Metadata.Embeds == nil {
post.Metadata.Embeds = []*model.PostEmbed{}
}
if embed, err := a.getEmbedForPost(post, firstLink, isNewPost); err != nil {
appErr, ok := err.(*model.AppError)
isNotFound := ok && appErr.StatusCode == http.StatusNotFound
@@ -149,12 +155,9 @@ func (a *App) getEmbedsAndImages(post *model.Post, isNewPost bool) *model.Post {
if !isNotFound {
mlog.Debug("Failed to get embedded content for a post", mlog.String("post_id", post.Id), mlog.Err(err))
}
} else if embed == nil {
post.Metadata.Embeds = []*model.PostEmbed{}
} else {
post.Metadata.Embeds = []*model.PostEmbed{embed}
} else if embed != nil {
post.Metadata.Embeds = append(post.Metadata.Embeds, embed)
}
post.Metadata.Images = a.getImagesForPost(post, images, isNewPost)
return post
}
@@ -227,6 +230,13 @@ func (a *App) getEmbedForPost(post *model.Post, firstLink string, isNewPost bool
}, nil
}
if _, ok := post.GetProps()["boards"]; ok && a.Config().FeatureFlags.BoardsUnfurl {
return &model.PostEmbed{
Type: model.PostEmbedBoards,
Data: post.GetProps()["boards"],
}, nil
}
if firstLink == "" {
return nil, nil
}

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

@@ -420,8 +420,8 @@ func TestPreparePostForClient(t *testing.T) {
And this is our icon: ` + server.URL + `/test-image1.png`,
}, th.BasicChannel, false, true)
require.Nil(t, err)
clientPost := th.App.PreparePostForClient(post, false, false)
post.Metadata.Embeds = nil
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(post, false, false)
// Reminder that only the first link gets an embed and dimensions
@@ -498,8 +498,8 @@ func TestPreparePostForClient(t *testing.T) {
},
}, th.BasicChannel, false, true)
require.Nil(t, err)
clientPost := th.App.PreparePostForClient(post, false, false)
post.Metadata.Embeds = nil
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(post, false, false)
t.Run("populates embeds", func(t *testing.T) {
assert.ElementsMatch(t, []*model.PostEmbed{
@@ -534,6 +534,7 @@ func TestPreparePostForClient(t *testing.T) {
ChannelId: th.BasicChannel.Id,
}, th.BasicChannel, false, true)
require.Nil(t, err)
post.Metadata.Embeds = nil
th.AddReactionToPost(post, th.BasicUser, "taco")
@@ -567,6 +568,7 @@ func TestPreparePostForClient(t *testing.T) {
Message: "hello world",
}, th.BasicChannel, false, true)
require.Nil(t, err)
referencedPost.Metadata.Embeds = nil
link := fmt.Sprintf("%s/%s/pl/%s", *th.App.Config().ServiceSettings.SiteURL, th.BasicTeam.Name, referencedPost.Id)
@@ -576,8 +578,8 @@ func TestPreparePostForClient(t *testing.T) {
Message: link,
}, th.BasicChannel, false, true)
require.Nil(t, err)
clientPost := th.App.PreparePostForClient(previewPost, false, false)
previewPost.Metadata.Embeds = nil
clientPost := th.App.PreparePostForClientWithEmbedsAndImages(previewPost, false, false)
firstEmbed := clientPost.Metadata.Embeds[0]
preview := firstEmbed.Data.(*model.PreviewPost)
require.Equal(t, referencedPost.Id, preview.PostID)
@@ -723,7 +725,8 @@ func testProxyOpenGraphImage(t *testing.T, th *TestHelper, shouldProxy bool) {
}, th.BasicChannel, false, true)
require.Nil(t, err)
embeds := th.App.PreparePostForClient(post, false, false).Metadata.Embeds
post.Metadata.Embeds = nil
embeds := th.App.PreparePostForClientWithEmbedsAndImages(post, false, false).Metadata.Embeds
require.Len(t, embeds, 1, "should have one embed")
embed := embeds[0]

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

@@ -49,6 +49,9 @@ type FeatureFlags struct {
// Enable different treatments for first time users, possible values = ("none", "tips_and_next_steps")
DownloadAppsCTA string
// Enable Boards Unfurl Preview
BoardsUnfurl bool
}
func (f *FeatureFlags) SetDefaults() {
@@ -66,6 +69,7 @@ func (f *FeatureFlags) SetDefaults() {
f.AddChannelButton = "by_team_name"
f.PrewrittenMessages = "none"
f.DownloadAppsCTA = "none"
f.BoardsUnfurl = true
}
func (f *FeatureFlags) Plugins() map[string]string {

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

@@ -9,6 +9,7 @@ const (
PostEmbedOpengraph PostEmbedType = "opengraph"
PostEmbedLink PostEmbedType = "link"
PostEmbedPermalink PostEmbedType = "permalink"
PostEmbedBoards PostEmbedType = "boards"
)
type PostEmbedType string