Files
2bb8d01100 Mattermost Blocks (#36338)
* Mattermost Blocks

* Rethink some block props and styles

* Remove obsolete comment

* Style fixes and add examples

* Add mention, search, and image metadata support

* Several UI improvements

* Validate blocks by translating them

* Add initial e2e tests

* Fix lint

* Fix tests and lint

* Fix lint

* Improve e2e and simplify doPostAction

* server side cleanup

* Fix typo

* Fix style

* Fix some tests

* Fix more tests

* Fix cypress tests

* Fix playwhright tests

* Fix flaky system console test

* Frontend cleanup

* Add blocks editor

* Fix CI

* Limit all blocks width

* Fix test

* Enable webhook service on playwhright CI

* fix flaky test

* Fix style

* Cleanups

* Address coderabbit comments

* Address coderabbit comments

* Address CI errors

* Fix tests

* Address changes in valid actions

* UX fixes

* Fix test

* Fix danger buttons and add allow emojis in buttons

* style tweaks

use semantic color tokens for buttons and accents, update max-heights for scollables,  adjustments to containers, removed btn-sm (using default button size for mm blocks with height and padding adjustments for use within blocks. removed hover selector from utils to prevent hover state issue with primary button, refined semantic-color-warning.

* Address feedback

* Add interactive content to post previews

* Add collapse transitions

* Address autocomplete position

* Handle columns within column sets

* Fix css lint

* Fix tests

* Use feature flag

* Address feedback

* Fix lint and add missing tests

* Fix e2e tests

* Fix e2e test

* Allow interactive posts without a message

* Fix lint

* Address feedback

* Fix ci

* Fix lint

* Add limits to block translations

* Fix lint

* Address feedback

* Address feedback

* Update snapshot

* Fix collapsible not defaulting to the right value

* Add total text limit

* Sync translations with mobile

* Fix snapshot

---------

Co-authored-by: Matthew Birtch <[email protected]>
Co-authored-by: Mattermost Build <[email protected]>
2026-06-29 20:33:46 +02:00

137 lines
4.8 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package model
import (
"encoding/json"
"maps"
)
type PostMetadata struct {
// 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"`
// Emojis holds all custom emojis used in the post, reactions, message attachments, and
// interactive payloads (mm_blocks, Block Kit blocks, Adaptive Cards) where applicable.
Emojis []*Emoji `json:"emojis,omitempty"`
// Files holds information about the file attachments on the post.
Files []*FileInfo `json:"files,omitempty"`
// RedactedFileCount is set when file attachments are stripped by an ABAC permission policy.
// Clients use this to render a placeholder instead of the file.
RedactedFileCount int `json:"redacted_file_count,omitempty"`
// Images holds the dimensions of all external images in the post as a map of the image URL to its dimensions.
// 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"`
// Reactions holds reactions made to the post.
Reactions []*Reaction `json:"reactions,omitempty"`
// Priority holds info about priority settings for the post.
Priority *PostPriority `json:"priority,omitempty"`
// Acknowledgements holds acknowledgements made by users to the post
Acknowledgements []*PostAcknowledgement `json:"acknowledgements,omitempty"`
// Translations holds translation data for configured target languages, keyed by language code
Translations map[string]*PostTranslation `json:"translations,omitempty"`
ExpireAt int64 `json:"expire_at,omitempty"`
Recipients []string `json:"recipients,omitempty"`
}
// PostTranslation represents a translation of a post in a specific language
type PostTranslation struct {
Text string `json:"text,omitempty"` // Used when Type is "string"
Object json.RawMessage `json:"object,omitempty"` // Used when Type is "object"
Type string `json:"type"`
State string `json:"state"`
SourceLang string `json:"source_lang,omitempty"` // Original language of the post
}
func (p *PostMetadata) Auditable() map[string]any {
embeds := make([]map[string]any, 0, len(p.Embeds))
for _, pe := range p.Embeds {
embeds = append(embeds, pe.Auditable())
}
if len(embeds) == 0 {
embeds = nil
}
return map[string]any{
"embeds": embeds,
"emojis": p.Emojis,
"files": p.Files,
"images": p.Images,
"reactions": p.Reactions,
"priority": p.Priority,
"acknowledgements": p.Acknowledgements,
"translations": p.Translations,
"redacted_file_count": p.RedactedFileCount,
}
}
type PostImage struct {
Width int `json:"width"`
Height int `json:"height"`
// Format is the name of the image format as used by image/go such as "png", "gif", or "jpeg".
Format string `json:"format"`
// FrameCount stores the number of frames in this image, if it is an animated gif. It will be 0 for other formats.
FrameCount int `json:"frame_count"`
}
// Copy does a deep copy
func (p *PostMetadata) Copy() *PostMetadata {
embedsCopy := make([]*PostEmbed, len(p.Embeds))
copy(embedsCopy, p.Embeds)
emojisCopy := make([]*Emoji, len(p.Emojis))
copy(emojisCopy, p.Emojis)
filesCopy := make([]*FileInfo, len(p.Files))
copy(filesCopy, p.Files)
imagesCopy := map[string]*PostImage{}
maps.Copy(imagesCopy, p.Images)
reactionsCopy := make([]*Reaction, len(p.Reactions))
copy(reactionsCopy, p.Reactions)
acknowledgementsCopy := make([]*PostAcknowledgement, len(p.Acknowledgements))
copy(acknowledgementsCopy, p.Acknowledgements)
translationsCopy := map[string]*PostTranslation{}
maps.Copy(translationsCopy, p.Translations)
var postPriorityCopy *PostPriority
if p.Priority != nil {
postPriorityCopy = &PostPriority{
Priority: p.Priority.Priority,
RequestedAck: p.Priority.RequestedAck,
PersistentNotifications: p.Priority.PersistentNotifications,
PostId: p.Priority.PostId,
ChannelId: p.Priority.ChannelId,
}
}
return &PostMetadata{
Embeds: embedsCopy,
Emojis: emojisCopy,
Files: filesCopy,
Images: imagesCopy,
Reactions: reactionsCopy,
Priority: postPriorityCopy,
Acknowledgements: acknowledgementsCopy,
Translations: translationsCopy,
RedactedFileCount: p.RedactedFileCount,
}
}